JSON schema for dynamic properties

后端 未结 1 400
余生分开走
余生分开走 2020-12-17 16:53

i have an object in which the \"key\" of the property will be set dynamically... what is the right way of defining this in a JSON Schema?

This is what my object look

相关标签:
1条回答
  • 2020-12-17 17:56

    I think what you are looking for is the patternProperties field, rather than the properties one. Should look something like this, assuming you just want a match all pattern:

    {
        "$schema": "http://json-schema.org/draft-04/schema",
        "title": "SomeSchema",
        "description": "SomeDescription",
        "type": "object",
        "properties": {
            "column_definitions": {
                "type": [
                    "array",
                    "null"
                ],
                "items": {
                    "$ref": "#/definitions/columnDef"
                },
                "readOnly": true
            },
            "row_values": {
                "type": [
                    "array",
                    "null"
                ],
                "items": {
                    "type": "object"
                },
                "readOnly": true
            }
        },
        "definitions": {
            "columnDef": {
                "type": "object",
                "patternProperties": {
                    ".*": {
                        "type": "object",
                        "properties": {
                            "type": {
                                "type": [
                                    "string",
                                    "null"
                                ],
                                "enum": [
                                    "Text",
                                    "Boolean",
                                    "Numeric",
                                    "DateTime"
                                ],
                                "readOnly": true
                            },
                            "isNullable": {
                                "type": [
                                    "boolean",
                                    "null"
                                ],
                                "readOnly": true
                            }
                        }
                    }
                }
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题