Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way to define additionalProperties? or Free-Form Object #132

Closed
AlexeyMatskevich opened this issue Aug 18, 2023 · 5 comments
Closed
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@AlexeyMatskevich
Copy link
Contributor

Hi, I have some rspec test with data:

    let(:data) {
      {
        description: {},
        type: "closed", 
        max_rating: 1,
        answer_options: [
          {id: first_answer_option.id, description: "description", correct: false},
          {id: second_answer_option.id, description: "NOT description", correct: true},
          {description: "New answer", correct: false}
        ]
      }
    }

When generating the documentation, I have this description for the descriopion field

            description:
              type: object
              properties: {}

The description field in my business is a field within which I pass data from the wysiwyg editor, and get an arbitrary object.
I'm trying to define it as a Free Form Object, according to this documentation: https://swagger.io/docs/specification/data-models/data-types/#object
I add this key additionalProperties: {} and remove this key properties: {}

When I run the generation, I get again properties: {} key.

Is there any way to deal with this?

I can try to make a contribution if required.

@exoego
Copy link
Owner

exoego commented Aug 18, 2023

Right now, this is not doable.
rspec-openapi preserves most of manually added fields (additionalProperties for this case) but resurrect properties.

We may omit properties if there is already additionalProperties manually added.

@exoego exoego added enhancement New feature or request good first issue Good for newcomers labels Aug 18, 2023
@AlexeyMatskevich
Copy link
Contributor Author

I guess my example is one of the extreme cases. However, there is another extreme case that may arise for other users.

Instead of a Free object, someone may want to describe a predefined list of fields, but leave the ability to add any set of additional fields.

But in the openapi documentation I couldn't find any direct indication that this is possible, so I don't know if such a complex case actually exists.

@AlexeyMatskevich
Copy link
Contributor Author

Personally, your solution works for me. Just concerned about more general cases.

@exoego
Copy link
Owner

exoego commented Mar 1, 2024

Implemented in #178

@exoego exoego closed this as completed Mar 1, 2024
@exoego
Copy link
Owner

exoego commented Mar 2, 2024

This was released in v0.13.0

@exoego exoego added this to the v0.13.0 milestone Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants