将一个Json模式的属性合并到另一个Json模式中
我有一个模式,其属性必须合并到另一个模式中。假设以下是必须包含其属性的架构:将一个Json模式的属性合并到另一个Json模式中,json,jsonschema,Json,Jsonschema,我有一个模式,其属性必须合并到另一个模式中。假设以下是必须包含其属性的架构: {"$schema": "http://json-schema.org/schema#", "title": "native", "type": "object", "required": ["executable"], "properties": { "job_name": { "type":"string", "dname": "job name" }, "executable":
{"$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
要求文档根据两个架构进行验证。它与merge不同,但它适用于您介绍的案例
{
"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" } }}