How to represent sum/union types in in json schema

后端 未结 1 1356
借酒劲吻你
借酒劲吻你 2021-02-07 03:26

I am trying to document an existing use of JSON using json-schema. The system permits the following two possabilities for one of the object attributes.

Either



        
相关标签:
1条回答
  • 2021-02-07 04:21

    Use anyOf to assert that the property must conform to one or another schema.

    {
        "type": "object",
        "properties": {
            "tracking_number": {
                "anyOf": [
                    { "$ref": "#/definitions/tracking_number" },
                    { "type": "array", "items": { "$ref": "#/definitions/tracking_number" }
                ]
        },
        "definitions": {
            "tracking_number": { "type": "integer" }
        }
    }
    
    0 讨论(0)
提交回复
热议问题