gpt4 book ai didi

jsonschema - 覆盖继承的 json 模式

转载 作者:行者123 更新时间:2023-12-03 16:52:03 45 4
gpt4 key购买 nike

如何覆盖由“allOf”关键字继承的 json 模式中定义的验证规则?
例子:

{
"$schema": "http://json-schema.org/draft-06/schema",
"title": "My JSON Schema",
"description": "",
"definitions": {
"a": {
"type": "object",
"properties": {
"b": {
"type": "object",
"properties": {
"c": {
"type": "string",
"minLength": 1,
"maxLength": 100
}
},
"required": [
"c"
]
}
},
"required": [
"b"
]
}
},
"properties": {
"main": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/a"
}
]
},
"sub": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/a"
}
]
}
}
}
json 模式定义了两个对象:

  • 两个对象都从定义的对象“a”继承了它们的属性
    但是对象“sub”应该有属性 b.c 的其他验证规则(当前它是 minLength 1 和 maxLength 100)。
    所以当然下面的 json 是无效的:
    {
    "main" :{
    "b": {
    "c": "This property has a min length"
    }
    },"sub" : {
    "b": {
    "c": ""
    }
    }
    }
    如何覆盖属性 b.c 的验证规则?

    最佳答案

    目前没有办法按照 JSON Schema 规范的规定执行此操作。

    关于jsonschema - 覆盖继承的 json 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51280697/

    45 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com