kin-openapi icon indicating copy to clipboard operation
kin-openapi copied to clipboard

Improper validation when additionalProperties are set to false

Open shubhamkr-cohesity opened this issue 8 months ago • 0 comments

I have been doing some tests with this library and came across a situation where the library is unable to validate the request payload properly if some extra fields are present.

Expectation: This should pass. { "category": "test" }

Result: request body has an error: doesn't match schema #/components/schemas/PetWithCategory: property "category" is unsupported

openapi: 3.0.0
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
  "/pets":
    post:
      summary: Create a pet
      operationId: createPets
      tags:
      - pets
      requestBody:
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/PetWithCategory"
        required: true
      responses:
        '201':
          description: Null response
components:
  schemas:
    PetCategory:
      type: object
      properties:
        category:
          type: string
    PetWithCategory:
      allOf:
      - "$ref": "#/components/schemas/PetCategory"
      - type: object
        properties:
          pet:
            "$ref": "#/components/schemas/Pet"
      additionalProperties: false
    Pet:
      type: object
      required:
      - id
      - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string

shubhamkr-cohesity avatar Jun 03 '24 11:06 shubhamkr-cohesity