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
487 stars 39 forks source link

schemaTypeCheck ignores properties under allOf when checking for existence of required fields #510

Open LittleGreenYoda42 opened 1 week ago

LittleGreenYoda42 commented 1 week ago

Hey there, when the schemaTypeCheck checks for the existence of properties which are required, it does not take into account the information in an allOf section. (see example below)

The schema is actually valid but the result show the error message: object contains required fields but no properties

And as a small side note: The schemaTypeCheck page references the wrong Function source (duplicated_enum_entry instead of schema_type)

openapi: 3.0.1
info:
  title: Minimal OpenAPI Example
  version: 1.0.0
paths:
  /:
    get:
      responses:
        '200':
          description: A simple get endpoint

components:
  schemas:
    BaseSchema:
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 1
        name:
          type: string
          example: "Base Name"

    Example:
      type: object
      required:
        - extraField
        - id
      allOf:
        - $ref: '#/components/schemas/BaseSchema'
        - type: object
          properties:
            extraField:
              type: string
              example: "Additional Data"
LasneF commented 1 week ago

@daveshanley should be similar to https://github.com/daveshanley/vacuum/issues/505

and so as you mentionned near https://github.com/daveshanley/vacuum/blob/main/functions/openapi/schema_type.go#L261 that need to leverage an "expanded" version

daveshanley commented 1 week ago

will address soon.