【问题标题】:JSON Schema Custom DefinitionJSON 模式自定义定义
【发布时间】:2018-06-07 19:07:16
【问题描述】:

我可以使用自定义说明符/属性,如“必需”关键字来用自定义说明装饰我的 Json 架构字段。

例如:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Product",
    "description": "A product from Acme's catalog",
    "type": "object",
    "properties": {
        "id": {
            "description": "The unique identifier for a product",
            "type": "integer"
        },
        "name": {
            "description": "Name of the product",
            "type": "string"
        },
        "price": {
            "type": "number",
            "minimum": 0,
            "exclusiveMinimum": true
        },
       "**credit-card**": {
            "**type**": "**number**",
        },
        "tags": {
            "type": "array",
            "items": {
                "type": "string"
            },
            "minItems": 1,
            "uniqueItems": true
        }
    },
    "required": ["id", "name", "price"],
    "**confidential**" : ["**credit-card**"]
}

我可以使用一个名为“机密”的特殊关键字来确保“信用卡”不应该被泄露和/或掩盖吗?架构标准是否允许此类自定义元数据关键字?

【问题讨论】:

    标签: json schema metadata


    【解决方案1】:

    这取决于您将用于执行验证的库。我用过AJV,它允许你定义自定义关键字,你可以找到更多关于它的信息here

    【讨论】:

      猜你喜欢
      • 2014-01-12
      • 2023-01-20
      • 1970-01-01
      • 1970-01-01
      • 2015-06-07
      • 1970-01-01
      • 2013-04-22
      • 1970-01-01
      • 2016-08-01
      相关资源
      最近更新 更多