将一个 Json 模式的属性合并到另一个 Json 模式中
Merge properties of one Json schema in another Json schema
我有一个架构,我必须将其属性合并到另一个架构中。假设以下是必须包含其属性的架构:
{"$schema": "http://json-schema.org/schema#",
"title": "native",
"type": "object",
"required": ["executable"],
"properties":
{
"job_name":
{
"type":"string",
"dname": "job name"
},
"executable":
{
"type":"string",
"dname":"server",
"description": "server name"
}
}}
包含上述模式的模式的形式为:
{"$schema": "http://json-schema.org/schema#",
"title": "application",
"type": "object",
"required": ["app_name"],
"properties":
{
"app_name":
{
"type":"string",
"dname": "app name"
}
}}
我想将第一个架构的属性合并到第二个架构中,使第二个架构看起来像:
{"$schema": "http://json-schema.org/schema#",
"title": "native",
"type": "object",
"required": ["executable","app_name"],
"properties":
{
"job_name":
{
"type":"string",
"dname": "job name"
},
"executable":
{
"type":"string",
"dname":"server",
"description": "server name"
}
"app_name":
{
"type":"string",
"dname": "app name"
}
}}
另外,"required" 字段被添加到第二个架构中。
有办法吗?
您不能合并架构,但您可以使用 allOf
来要求文档针对两个架构进行验证。它与合并不同,但它适用于您提供的案例。
{
"allOf": [
{ ... schema1 ... },
{ ... schema2 ... }
]
}
我可以使用 'extends' 关键字在另一个模式中扩展一个模式,如下所示:
在定义中的同一个文件中定义第一个模式(我希望它也可以是另一个json模式文件)并在另一个模式中扩展它。
"definitions" : {
"argumentBaseType":{
"required": ["executable"],
"properties":
{
"job_name":
{
"type":"string",
"dname": "job name"
},
"executable":
{
"type":"string",
"dname":"server",
"description": "server name"
}
}
}
"properties":
{
{
Argument1 : {
"extends" : {
"$ref" : "#/definitions/argumentBaseType"
},
"app_name":
{
"type":"string",
"dname": "app name"
}
}}
我有一个架构,我必须将其属性合并到另一个架构中。假设以下是必须包含其属性的架构:
{"$schema": "http://json-schema.org/schema#",
"title": "native",
"type": "object",
"required": ["executable"],
"properties":
{
"job_name":
{
"type":"string",
"dname": "job name"
},
"executable":
{
"type":"string",
"dname":"server",
"description": "server name"
}
}}
包含上述模式的模式的形式为:
{"$schema": "http://json-schema.org/schema#",
"title": "application",
"type": "object",
"required": ["app_name"],
"properties":
{
"app_name":
{
"type":"string",
"dname": "app name"
}
}}
我想将第一个架构的属性合并到第二个架构中,使第二个架构看起来像:
{"$schema": "http://json-schema.org/schema#",
"title": "native",
"type": "object",
"required": ["executable","app_name"],
"properties":
{
"job_name":
{
"type":"string",
"dname": "job name"
},
"executable":
{
"type":"string",
"dname":"server",
"description": "server name"
}
"app_name":
{
"type":"string",
"dname": "app name"
}
}}
另外,"required" 字段被添加到第二个架构中。 有办法吗?
您不能合并架构,但您可以使用 allOf
来要求文档针对两个架构进行验证。它与合并不同,但它适用于您提供的案例。
{
"allOf": [
{ ... schema1 ... },
{ ... schema2 ... }
]
}
我可以使用 'extends' 关键字在另一个模式中扩展一个模式,如下所示:
在定义中的同一个文件中定义第一个模式(我希望它也可以是另一个json模式文件)并在另一个模式中扩展它。
"definitions" : { "argumentBaseType":{ "required": ["executable"], "properties": { "job_name": { "type":"string", "dname": "job name" }, "executable": { "type":"string", "dname":"server", "description": "server name" } } } "properties": { { Argument1 : { "extends" : { "$ref" : "#/definitions/argumentBaseType" }, "app_name": { "type":"string", "dname": "app name" } }}