rspec-openapi icon indicating copy to clipboard operation
rspec-openapi copied to clipboard

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

Open AlexeyMatskevich opened this issue 2 years ago • 3 comments
trafficstars

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.

AlexeyMatskevich avatar Aug 18 '23 13:08 AlexeyMatskevich

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 avatar Aug 18 '23 14:08 exoego

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 avatar Aug 18 '23 15:08 AlexeyMatskevich

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

AlexeyMatskevich avatar Aug 18 '23 15:08 AlexeyMatskevich

Implemented in https://github.com/exoego/rspec-openapi/pull/178

exoego avatar Mar 01 '24 10:03 exoego

This was released in v0.13.0

exoego avatar Mar 02 '24 11:03 exoego