APIDevTools / swagger-parser

Swagger 2.0 and OpenAPI 3.0 parser/validator
https://apitools.dev/swagger-parser
MIT License
1.09k stars 154 forks source link

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

Open marcelstoer opened 3 years ago

marcelstoer commented 3 years ago

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 commented 3 years ago

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.