json-schema-codegen icon indicating copy to clipboard operation
json-schema-codegen copied to clipboard

KeyError: Property's type is not inferred when it references a definition

Open tokybe opened this issue 5 years ago • 0 comments

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "Table",
    "definitions": {
        "dataSource": {
            "properties": {
                "type": {
                    "type": "string",
                    "enum": [
                        "postgres",
                        "script"
                    ],
                    "default": "postgres"
                }
            },
            "type": "object"
        }
    },
    "properties": {
        "datasource": {
            "$ref": "#/definitions/dataSource"
        }
    }
}

fails with

Exception has occurred: KeyError 'type' File "*****/json_codegen/generators/python3.py", line 252, in get_partial_annotation_from_definition property_type = property_["type"]

It doesn't fail if we specify the type

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "Table",
    "definitions": {
        "dataSource": {...}
    },
    "properties": {
        "datasource": {
            "$ref": "#/definitions/dataSource",
            "type": "object"
        }
    }
}

tokybe avatar Apr 08 '19 13:04 tokybe