swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

Old PR comes back to haunt me: validating required properties actually exist

Open marcelstoer opened this issue 5 years ago • 1 comments

Years ago I contributed two PRs #83 and #84 which added validation to ensure properties declared as required actually exist.

The test case I contributed uses a definition like so:

https://github.com/APIDevTools/swagger-parser/blob/c47b3f5cc849b09d7b0bc11a14e4a44d5caee1df/test/specs/validate-spec/valid/inherited-required-properties.yaml#L48-L54

Today I learned folks might actually put this into their API specs like so instead:

 OfferingRequired:
  allOf:
    - $ref: '#/definitions/Offering'
    - type: object
      required:
        - contentId                        # <-- all required properties are "inherited" through the composition of Offering 
        - start
        - end

@JamesMessinger in your experience is this a common enough variant that I should adjust the code through a PR accordingly?

marcelstoer avatar Nov 25 '20 21:11 marcelstoer

According to https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#composition-and-inheritance-polymorphism it is expected(?) that you use allOf to compose something out of a $ref object and an "anonymous" local object.

marcelstoer avatar Feb 10 '21 13:02 marcelstoer