APIDevTools / json-schema-ref-parser

Parse, Resolve, and Dereference JSON Schema $ref pointers in Node and browsers
https://apitools.dev/json-schema-ref-parser
MIT License
952 stars 227 forks source link

Failed to dereference following schema #259

Closed ExcitedSpider closed 2 years ago

ExcitedSpider commented 2 years ago
{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "$ref": "#/definitions/Example",
    "definitions": {
        "Example": {
            "properties": {
                "id": {
                    "type": "integer"
                },
                "price": {
                    "type": "number"
                },
                "byte": {
                    "type": "string",
                    "format": "binary",
                    "binaryEncoding": "base64"
                },
                "name": {
                    "type": "string"
                },
                "map_int32_string": {
                    "additionalProperties": {
                        "type": "string"
                    },
                    "type": "object"
                },
                "map_string_int32": {
                    "additionalProperties": {
                        "type": "integer"
                    },
                    "type": "object"
                },
                "action": {
                    "enum": [
                        "ONLINE",
                        0,
                        "OFFLINE",
                        1
                    ],
                    "oneOf": [
                        {
                            "type": "string"
                        },
                        {
                            "type": "integer"
                        }
                    ]
                },
                "item": {
                    "$ref": "#/definitions/example.Item",
                    "additionalProperties": true
                },
                "items": {
                    "items": {
                        "$ref": "#/definitions/example.Item"
                    },
                    "type": "array"
                },
                "nonexistent": {
                    "type": "string"
                },
                "sourceType": {
                    "enum": [
                        "Producer",
                        0,
                        "Consumer",
                        1
                    ],
                    "oneOf": [
                        {
                            "type": "string"
                        },
                        {
                            "type": "integer"
                        }
                    ]
                },
                "mq_config": {
                    "$ref": "#/definitions/example.MqConfig",
                    "additionalProperties": true
                },
                "enable": {
                    "type": "boolean"
                }
            },
            "additionalProperties": true,
            "type": "object"
        },
        "example.Item": {
            "properties": {
                "id": {
                    "type": "integer"
                },
                "price": {
                    "type": "number"
                },
                "name": {
                    "type": "string",
                    "description": "bytes byte = 3;"
                },
                "map_int32_string": {
                    "additionalProperties": {
                        "type": "string"
                    },
                    "type": "object"
                },
                "map_string_int32": {
                    "additionalProperties": {
                        "type": "integer"
                    },
                    "type": "object"
                },
                "action": {
                    "enum": [
                        "ONLINE",
                        0,
                        "OFFLINE",
                        1
                    ],
                    "oneOf": [
                        {
                            "type": "string"
                        },
                        {
                            "type": "integer"
                        }
                    ]
                },
                "snippets": {
                    "items": {
                        "type": "string"
                    },
                    "type": "array"
                }
            },
            "additionalProperties": true,
            "type": "object"
        },
        "example.KafkaCfg": {
            "properties": {
                "name": {
                    "type": "string"
                }
            },
            "additionalProperties": true,
            "type": "object"
        },
        "example.MqConfig": {
            "properties": {
                "rmq_config": {
                    "$ref": "#/definitions/example.RMQCfg",
                    "additionalProperties": true
                },
                "nsq_config": {
                    "$ref": "#/definitions/example.NSQCfg",
                    "additionalProperties": true
                },
                "kafka_config": {
                    "$ref": "#/definitions/example.KafkaCfg",
                    "additionalProperties": true
                }
            },
            "additionalProperties": true,
            "type": "object"
        },
        "example.NSQCfg": {
            "properties": {
                "name": {
                    "type": "string"
                }
            },
            "additionalProperties": true,
            "type": "object"
        },
        "example.RMQCfg": {
            "properties": {
                "name": {
                    "type": "string"
                }
            },
            "additionalProperties": true,
            "type": "object"
        }
    }
}
ExcitedSpider commented 2 years ago

I saw that there is a similar issue relating to the top-level $ref, so I am going to close this one. https://github.com/APIDevTools/json-schema-ref-parser/issues/48

For those who have same problems, you can try to remove the top-level $ref.