Skip to content

bundle() creates a invalid $ref #338

Open
@shonigbaum

Description

@shonigbaum

We are using the json-schema-ref-parser library to flatten / dereference our schemas. As we need to return them over an API, we use bundle() as sometimes circular references can occur in the given JSON schemas.

One user just discovered that his schema got invalid after using bundle() as four refs got replaced with a non-valid ref, pointing to a non-existing path. These schemas are quite complicated with many allOfs. I reproduced the broken schema and removed everything so just the invalid ref and needed surroundings are given:

{
    "type": "object",
    "allOf": [
        {
            "description": "REMOVED for better readbility"
        },
        {
            "type": "object",
            "properties": {
                "payload": {
                    "type": "array",
                    "items": {
                        "allOf": [
                            {
                                "description": "REMOVED for better readbility"
                            },
                            {
                                "type": "object",
                                "properties": {
                                    "reservationActionMetaData": {
                                        "allOf": [
                                            {
                                                "allOf": [
                                                    {
                                                        "type": "object",
                                                        "properties": {
                                                            "supplierPriceElements": {
                                                                "allOf": [
                                                                    {
                                                                        "description": "REMOVED for better readbility"
                                                                    },
                                                                    {
                                                                        "type": "object",
                                                                        "properties": {
                                                                            "purchaseRate": {
                                                                                "allOf": [
                                                                                    {
                                                                                        "type": "object",
                                                                                        "required": [
                                                                                            "amount"
                                                                                        ],
                                                                                        "properties": {
                                                                                            "amount": {
                                                                                                "type": "number"
                                                                                            }
                                                                                        }
                                                                                    },
                                                                                    {
                                                                                        "type": "object",
                                                                                        "properties": {
                                                                                            "inDetail": {
                                                                                                "type": "object",
                                                                                                "properties": {
                                                                                                    "perDate": {
                                                                                                        "type": "array",
                                                                                                        "items": {
                                                                                                            "type": "object",
                                                                                                            "properties": {
                                                                                                                "amount": {
                                                                                                                    "$ref": "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/fee/properties/modificationFee/properties/amount"
                                                                                                                }
                                                                                                            }
                                                                                                        }
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                ]
                                                                            },
                                                                            "fee": {
                                                                                "type": "object",
                                                                                "properties": {
                                                                                    "modificationFee": {
                                                                                        "$ref": "#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/purchaseRate/allOf/0"
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                ]
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "description": "REMOVED for better readbility"
                                                    }
                                                ]
                                            },
                                            {
                                                "description": "REMOVED for better readbility"
                                            }
                                        ]
                                    }
                                }
                            }
                        ]
                    }
                }
            }
        }
    ]
}

One ref (amount) points to a path (modificationFee) which contains another ref - and this contains the needed data. But the compiler cannot compile this (e.g. https://www.jsonschemavalidator.net/).

Error message:

Could not resolve schema reference '#/allOf/1/properties/payload/items/allOf/1/properties/reservationActionMetaData/allOf/0/allOf/0/properties/supplierPriceElements/allOf/1/properties/fee/properties/modificationFee/properties/amount'. Path 'allOf[1].properties.payload.items.allOf[1].properties.reservationActionMetaData.allOf[0].allOf[0].properties.supplierPriceElements.allOf[1].properties.purchaseRate.allOf[1].properties.inDetail.properties.perDate.items.properties.amount', line 59, position 123.

I can try to provide some stripped down schemas, but this could take some time. We have three schemas which reference themselves like A -(one ref)-> B -(multiple refs)-> C.

Maybe you have already an idea how this could happen?

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