rspec-openapi
rspec-openapi copied to clipboard
Is there any way to define additionalProperties? or Free-Form Object
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.
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.
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.
Personally, your solution works for me. Just concerned about more general cases.
Implemented in https://github.com/exoego/rspec-openapi/pull/178
This was released in v0.13.0