8000 Only top-level objects are validated · Issue #77 · python-openapi/openapi-spec-validator · GitHub
[go: up one dir, main page]

Skip to content
Only top-level objects are validated #77
Open
@am-on

Description

@am-on

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0