首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >需要帮助添加if- help,然后在比较外部和内部模式中的对象时,使用networknt使用json模式验证器。

需要帮助添加if- help,然后在比较外部和内部模式中的对象时,使用networknt使用json模式验证器。
EN

Stack Overflow用户
提问于 2022-10-24 14:42:21
回答 1查看 17关注 0票数 0

例如,只有在declinfo是强制性的情况下,date才是强制性的。类似地,我必须在其他内部对象中添加验证。

当前模式:

代码语言:javascript
复制
{
  "$schema":"http://json-schema.org/draft/2019-09/schema#",
  "type":"object",
  "description":"test",
  "title":"test",
  "properties":{
    "date":{
      "type":[
        "string",
        "null",
        "integer"
      ],
      "description":"Date",
      "format":"^[0-9]*$",
      "minLength":1,
      "maxLength":8
    },
    "declInfo":{
      "type":"array",
      "items":{
        "type":"object",
        "properties":{
          "number":{
            "type":"string",
            "format":"^[a-zA-Z0-9._\\- ]*$",
            "minLength":1,
            "maxLength":19
          }
        }
      }
    }
  }
}
EN

回答 1

Stack Overflow用户

发布于 2022-11-16 05:29:05

您可以使用dependentRequired to conditionally require certain properties。如果您想有条件地应用架构there is also dependentSchema

例如,您可以添加

代码语言:javascript
复制
{
  "$schema":"http://json-schema.org/draft/2019-09/schema#",
  "type":"object",
  "description":"test",
  "title":"test",
  "properties":{
    "date":{
        ...
    },
    "declInfo":{
        ...
    }
  },
  "dependentRequired": {
    "date": ["declInfo"]
  }
}

使用示例的完整模式:https://www.jsonschemavalidator.net/s/3G68BVHh

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74182861

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档