JSON模式自定义

时间:2017-05-05 17:20:02

标签: json schema metadata

我是否可以使用自定义说明符/属性(如“required”关键字)来装饰具有自定义规范的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**"]
}

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

1 个答案:

答案 0 :(得分:0)

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