Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle produces invalid output when there are additional properties on $ref object pointing to a recursive schema #73

Closed
mickdekkers opened this issue Feb 9, 2018 · 2 comments
Labels

Comments

@mickdekkers
Copy link

Repro here: https://github.com/mickdekkers/json-schema-ref-parser-extra-ref-props-issue

Issue description

json-schema-ref-parser's .bundle() method seems to have trouble with additional properties on $ref objects in certain cases where recursive schemas are used.
For example with a linked list schema, which references itself on the next property.

a graph of the references of a potentially failing schema

This is a schema for a linked list node:

{
    "$id": "Node.schema.json",
    "definitions": {
        "node": {
            "type": "object",
            "properties": {
                "data": {
                    "description": "Some data",
                    "type": "integer"
                },
                "next": {
                    "$ref": "#/definitions/node"
                }
            }
        }
    }
}

If that schema is then referenced through a $ref object happens to contain an additional property, in this case title:

{
    "$id": "LinkedList.schema.json",
    "definitions": {
        "linkedList": {
            "$ref": "Node.schema.json#/definitions/node",
            "title": "linkedList"
        }
    }
}

The resulting bundle that json-schema-ref-parser produces looks like this:

{
    "$id": "LinkedList.schema.json",
    "definitions": {
        "linkedList": {
            "$ref": "#/definitions/linkedList/properties/next",
            "title": "linkedList"
        }
    }
}

Note how the definition for the node schema isn't included in the bundle, and the $ref object references itself.

Caveats

Interestingly enough, the issue does not occur when the node schema's next $ref object also contains an additional property. It also does not occur when only the node schema's next $ref object contains an additional property.

Here's a table of when the issue occurs:

Folder Setup Issue occurs?
LinkedList Basic linked list schema No
LinkedListRootRefTitle Linked list with additional property on root $ref object (LinkedList.schema.json) Yes
LinkedListNextRefTitle Linked list with additional property on next $ref object (Node.schema.json) No
LinkedListBothRefsTitle Linked list with additional property on both $ref objects No
@JamesMessinger
Copy link
Member

awesome! Thank you for the detailed bug report and repro. 👍 🥇

@philsturgeon
Copy link
Member

@mnaumanali94 can we investigate to make sure this isn't still happening? As OpenAPI v3.1 supports $ref siblings we'll see more people using them soon.

@jonluca jonluca closed this as completed Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants