【问题标题】:How can I validate that a JSON Schema is valid against the JSON Schema Standard) with JsonSchema.Net我如何使用 JsonSchema.Net 验证 JSON 模式对 JSON 模式标准有效)
【发布时间】:2023-02-17 23:22:54
【问题描述】:

我一直在努力尝试根据元模式验证 json 模式(检查 json 是否实际上遵循 JSON 模式标准)。 我试着按照文档linklink

我尝试了所有这些,但它们都返回相同的结果..有效..所以在我看来他们没有验证任何东西..

private void ValidateSchema(string schemaString)
{
    var element = JsonNode.Parse(schemaString);
    var metaSchema = Json.Schema.MetaSchemas.Metadata202012;
    var options = new ValidationOptions
    {
        OutputFormat = OutputFormat.Detailed,
        ValidateMetaSchema = false // tried also with true
    };
    var results = metaSchema.Validate(element, options);
}
private void ValidateSchema(string schemaString)
{
    var element = JsonNode.Parse(schemaString);
    var metaSchema = Json.Schema.MetaSchemas.Draft202012; 
    var options = new ValidationOptions
    {
        OutputFormat = OutputFormat.Detailed,
        ValidateMetaSchema = false // tried also with true
    };
    var results = metaSchema.Validate(element, options);
}

这些是我尝试过的输入。我预计有些人会返回无效。

@"{""f"":""a""}"
@"{}"
@"{""required"": [""prop1"", ""prop2"", ""prop3"", ""prop4"", ""prop5"", ""prop6""]}"
@"{
""$schema"": ""http://json-schema.org/draft-07/schema#"",
""type"": ""object"",
""required"": [""prop1"", ""prop2"", ""prop3"", ""prop4"", ""prop5"", ""prop6""]
}"

【问题讨论】:

    标签: c# jsonschema json-everything


    【解决方案1】:

    针对元模式的验证不涵盖您的示例。元模式使用开放模型,也没有语义检查。您需要一个 JSON 模式 linter,例如 JSONBuddy (https://www.json-buddy.com) 附带的那种,也可以在 json-schema-linter.com 上获得以进行快速测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-08
      • 2015-07-18
      • 1970-01-01
      相关资源
      最近更新 更多