question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

allOf required property not composing properly

See original GitHub issue

From @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.

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.

Copied from original issue: swagger-api/swagger-editor#1390

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
baynezycommented, Jul 18, 2017

@webron - that works as I had hoped. Thank you very much.

0reactions
webroncommented, Jul 19, 2017

Thanks for verifying! Closing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

allOf required property not composing properly #1390 - GitHub
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...
Read more >
All Of is not working properly in Open API Swagger 3.0
In my project I am using Open API 3.0 to for generating mmodel classes. My requirement is to I have to reuse the...
Read more >
Testbed-12 Javascript-JSON-JSON-LD Engineering Report
THE INTELLECTUAL PROPERTY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ......
Read more >
JSchema.AllOf Property - Json.NET
Gets the AllOf schemas.
Read more >
Validation of required read-only field fails when request body ...
Schema using allOf composition with required readOnly properties are not validated properly. PUT /test {“notReadOnly”: “abc”, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found