daveshanley / vacuum

vacuum is the worlds fastest OpenAPI 3, OpenAPI 2 / Swagger linter and quality analysis tool. Built in go, it tears through API specs faster than you can think. vacuum is compatible with Spectral rulesets and generates compatible reports.
https://quobix.com/vacuum
MIT License
490 stars 39 forks source link

oas3-valid-schema-example Rule passes with invalid example object #392

Closed yashwason closed 6 months ago

yashwason commented 7 months ago

I have the oas3-valid-schema-example enabled on my Vacuum configuration. It rightly warns about a missing example on the below 'address' field if I delete examples. But if I modify the example e.g. I delete the required fields country and address1; the lint still passes.

ResponseAddressFields:
    type: object
    description: Address-related fields of response body
    properties:
        address:
            type: object
            description: Primary physical address of the organisation
            required:
                - address1
                - city
                - country
            examples: 
                - address1: J-234 Gandhi Nagar
                  address2: Street number 2, Block 2
                  city: Delhi
                  subDivision:
                    entity: countrySubDivision
                    name: Delhi
                    type: union territory
                    code: IN-DL
                  country:
                    entity: country
                    name: India
                    code: IN
                  postalCode: '110019'
            allOf:
                - $ref: '#/components/schemas/CommonAddressFields'
                - type: object
                  properties:
                      subDivision:
                          type: object
                          required: 
                            - entity
                            - name
                            - type
                            - code
                          properties:
                              entity:
                                  type: string
                              name:
                                  type: string
                              type:
                                  type: string
                              code:
                                  $ref: '#/components/schemas/SubDivisionCodeField'

                      country:
                          type: object
                          required: 
                            - entity
                            - name
                            - code
                          properties:
                              entity:
                                  type: string
                              name:
                                  type: string
                              code:
                                  $ref: '#/components/schemas/CountryCodeField'
daveshanley commented 7 months ago

Interesting, I will look into this when I can. The oas3-valid-schema-example is due for a rewrite, it is struggling a little.

https://quobix.com/vacuum/rules/examples/oas3-valid-schema-example/

daveshanley commented 6 months ago

This should be resolved in v0.7.0 can you try again?

yashwason commented 6 months ago

Resolved indeed. Vacuum now warns about missing properties in examples.