kin-openapi
kin-openapi copied to clipboard
Improper validation when additionalProperties are set to false
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