【发布时间】:2021-07-30 00:06:59
【问题描述】:
给定以下 json 文档:
{
"property-1": {
"server": "string-value",
"environment": "string-value",
"cluster": "string-value"
},
"property-2": {
"server": "string-value",
"environment": "string-value",
"cluster": "string-value"
}
}
我正忙着为这种类型的 json 文档创建一个 json 模式,其中property-1 可以是任何字符串,但在其中,我们将拥有一个包含许多必需的集合结构。我正在努力的是如何定义架构,以便用户能够为property-1 | property-2 设置任何字符串。
我认为我必须使用一种模式,但我尝试过的方法并没有那么好。
{
"$schema": "http://json-schema.org/draft/2020-12/schema",
"type": "object",
"definitions": {
"role": {
"$id": "#svcrole",
"description": "Application name for which role is required.",
"type": "object",
"pattern": "^[a-zA-Z\\-]+$",
"properties": {
"server": {
"type": "string"
},
"environment": {
"type": "string"
},
"cluster": {
"type": "string"
}
},
"required": [
"server",
"environment",
"cluster"
]
}
},
"properties": {
"$schema": {
"type": "string"
},
"$name": {
"$ref": "#/definitions/role"
}
}
}
【问题讨论】:
标签: json validation schema