我有一个如下jsonschema
定义definition-1.json
。我有一个名为inputs
type的属性,array
它指的anyOf
definitions
是
"inputs": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/definitions/stringParameter"
},
{
"$ref": "#/definitions/numberParameter"
},
{
"$ref": "#/definitions/booleanParameter"
},
{
"$ref": "#/definitions/jsonParameter"
},
{
"$ref": "#/definitions/fileParameter"
}
]
}
}
然后definitions
像下面一样定义的参数jsonschema
definition-1.json
"definitions": {
"stringParameter": {
"type": "object",
"required": [
"name",
"description",
"datatype"
]
}
...
}
现在我想definitions
在我的其他模式中引用这个参数,dummy-1.json
如下所示
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "dummy-1.json",
"allOf": [
{
"type": "object",
"required": [
"definition_data"
],
"properties": {
"definition_data": {
"type": "object",
"required": [
"inputs"
],
"properties": {
"type": "array",
"inputs": {
"items": {
"allOf": [
{
"prop1": {
"$ref": "#/definitions/stringParameter"
}
},
{
"prop2": {
"$ref": "#/definitions/numberParameter"
}
}
]
}
}
}
}
}
},
{
"type": "object",
"properties": {
"definition_data": {
"$ref": "definition-1.json"
}
}
}
]
}
这看起来不像工作。prop1
也将成功验证其他参数定义的任何属性部分,即使在dummy-1.json
我明确提到#/definitions/stringParameter
。我可以理解inputs
接受所有参数。但是想知道如何实现 1:1 的参数定义映射。definition-1.json
anyOf
definitions
dummy-1.json