[英]How to combine Json schemas
我有一个 C# 应用程序,其中包含多个类,其属性对应于 Json 文件中的条目。 我想根据 Json 模式验证 Json 文件,我将使用 NewtonSoft 的模式生成器为类型创建,例如JSchema schema = generator.Generate(typeof(ClassName))
。 我的问题是,这将为每个 class 生成一个 Json 模式,我想针对所有这些模式验证 Json 文件。 如何将 Json 模式组合成一个大型超级模式?
生成模式后,如果您希望模式创建一个,则可以使用此oneOf
和$ref
方法。
{
"oneOf": [
{"$ref": "your path here"}, // the root schema, defining the object
{
"type": "array", // the schema.
"items": {"$ref": "your path here"}
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.