openapi-spec-validator icon indicating copy to clipboard operation
openapi-spec-validator copied to clipboard

Only top-level objects are validated

Open am-on opened this issue 6 years ago • 0 comments

Validation should fail when an object has an item in the required list that isn't defined in properties.

Validation fails as expected when an object is defined on the top level:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /my-pet:
    get:
      summary: A pet
      operationId: getPet
      tags:
        - pets
      responses:
        '200':
          description: A pet
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pet"
components:
  schemas:
    Pet:
      type: object
      required:
        - name
        - undefinedRequiredItem # This item is not defined in properties, FAIL validation
      properties:
        name:
          type: string
> Required list has not defined properties: ['undefinedRequiredItem']

BUG: Validation passes for an invalid object used as an array item:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      responses:
        '200':
          description: Array of pets
          content:
            application/json:    
              schema:
                $ref: "#/components/schemas/Pets"
components:
  schemas:
    Pets:
      type: array
      items:
        type: object
        required:
          - name
          - undefinedRequiredItem # This item is not defined in properties, but validation passes
        properties:
          name:
            type: string
> OK

BUG: Validation passes for an invalid nested object:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /my-pet:
    get:
      summary: A pet
      operationId: getPet
      tags:
        - pets
      responses:
        '200':
          description: A pet
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pet"
components:
  schemas:
    Pet:
      type: object
      properties:
        pet:
          type: object
          required:
            - name
            - undefinedRequiredItem # This item is not defined in properties, but validation passes
          properties:
            name:
              type: string
> OK

am-on avatar May 28 '19 11:05 am-on