-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
Schema composition doesn't appear to work with additionalProperties: false.
openapi.yaml
openapi: 3.0.1
components:
schemas:
Pet:
type: object
properties:
name:
type: string
age:
type: integer
required:
- name
- age
additionalProperties: false
Dog:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
properties:
bark:
type: boolean
required:
- bark
additionalProperties: false
paths:
/simple:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
responses:
'200':
content:
application/json:
schema:
type: object
/complex:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Dog'
responses:
'200':
content:
application/json:
schema:
type: object
Simple schema
- Hitting
/simplewith the following works as expected.
{
"name": "hunter",
"age": 12,
}
- Including an extra property
fooin the request...
{
"name": "hunter",
"age": 12,
"foo": true
}
...returns an error as expected because additionalProperties: false is set on the Pet schema.
{
"error": {
"name": "ValidationError",
"message": "Error while validating request: request.body should NOT have additional properties",
"data": [
{
"keyword": "additionalProperties",
"dataPath": ".body",
"schemaPath": "#/properties/body/additionalProperties",
"params": {
"additionalProperty": "foo"
},
"message": "should NOT have additional properties"
}
]
}
}
Complex schema with composition
On the other hand, hitting /complex with the following...
{
"name": "hunter",
"age": 12,
"bark": true
}
...returns an unexpected error.
{
"error": {
"name": "ValidationError",
"message": "Error while validating request: request.body should NOT have additional properties",
"data": [
{
"keyword": "additionalProperties",
"dataPath": ".body",
"schemaPath": "#/properties/body/additionalProperties",
"params": {
"additionalProperty": "name"
},
"message": "should NOT have additional properties"
}
]
}
}
Metadata
Metadata
Assignees
Labels
No labels