Skip to content

allOf required property not composing properly #1390

@baynezy

Description

@baynezy

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.

image

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.

image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions