allOf required property not composing properly
See original GitHub issueFrom @baynezy on July 3, 2017 13:46
If you take the following swagger definition:-
{
"swagger": "2.0",
"info": {
"title": "An API Definition",
"version": "0.1"
},
"paths": {
"/users": {
"post": {
"operationId": "getUser",
"produces": [
"application/json"
],
"parameters": [{
"name": "newUser",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/newUser"
}
}],
"responses": {
"201": {
"description": "Details of the user"
}
}
}
}
},
"definitions": {
"user": {
"type": "object",
"required": ["username", "firstName", "lastName"],
"properties": {
"username": {
"type": "string"
},
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
}
}
},
"newUser": {
"allOf": [{
"$ref": "#/definitions/user"
},
{
"type": "object",
"required": ["email", "roles"],
"properties": {
"email": {
"type": "string"
},
"roles": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
]
}
}
}
Then newUser is a composite of user and the additional properties defined on newUser. In the Swagger Editor the UI shows this correctly.

However, it should also compose the required property which it is failing to do. user states that username, firstName, and lastName are required, and newUser states that email, and roles are required. However, it is only marking those on newUser as required.

This should be a super-set of these.
6.26. allOf
This keyword’s value MUST be a non-empty array. Each item of the array MUST be a valid JSON Schema.
An instance validates successfully against this keyword if it validates successfully against all schemas defined by this keyword’s value.
Copied from original issue: swagger-api/swagger-editor#1390
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (6 by maintainers)

Top Related StackOverflow Question
@webron - that works as I had hoped. Thank you very much.
Thanks for verifying! Closing.