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

Modeling inheritance does not work in validation

Open danielwinkler opened this issue 2 years ago • 1 comments
trafficstars

We are trying to model inheritance according to

https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/

To test the problem, please use the petstore example of your tests:

  • Import test/data/valid_openapi/petstore-detailed.yaml in the API explorer.
  • Use the request Add a new pet to the store.
  • We are trying to create a cat and have the cat specific properties validated (huntingSkill)
  • Send the following payload
{
  "name": "<string>",
  "photoUrls": [
    "<string>",
    "<string>"
  ],
  "id": "<long>",
  "category": {
    "id": "<long>",
    "name": "<string>",
    "sub": {
      "prop1": "<string>"
    }
  },
  "friend": {
    "value": "<Circular reference to #/components/schemas/Pet detected>"
  },
  "tags": [
    {
      "id": "<long>",
      "name": "<string>"
    }
  ],
  "status": "available",
  "petType": "cat",
  "huntingSkill": 3
}

Everything is fine, although huntingSkill should be a string (enum)

But when you change a property that is defined in the base component, e.g.

  "status": 3,

you'll get two errors, that status should be string, and that it should be one of the 3 enum values.

This issue becomes even worse, when additionalProperties is set to false in the openAPI specification of the base component. The huntingSkill would not even be allowed, although it is a property of the derived Cat component.

danielwinkler avatar May 08 '23 10:05 danielwinkler

@danielwinkler thanks for raising the issue, we are looking into it.

shashankawasthi88 avatar May 08 '23 17:05 shashankawasthi88