【发布时间】:2021-10-15 14:13:19
【问题描述】:
我遇到了自我referencing jsonSchema 的问题。
这个很好用:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"allOf": [
{
"$ref": "#/definitions/myData"
},
{
"$ref": "#/definitions/foo"
}
],
"definitions": {
"foo": {
"properties": {
"bar": {
"properties": {
"bang": {
"additionalProperties": {
"anyOf": [
{
"$ref": "#/definitions/foo"
},
{
"items": {
"$ref": "#/definitions/foo"
},
"type": "array"
}
]
},
"type": "object"
}
},
"type": "object"
}
},
"type": "object"
},
"myData": {
"properties": {
"list": {
"additionalProperties": {
"anyOf": [
{
"$ref": "#/definitions/myData"
},
{
"items": {
"$ref": "#/definitions/myData"
},
"type": "array"
}
]
},
"type": "object"
}
},
"type": "object"
}
},
"type": "object"
}
第二个失败了:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"allOf": [
{
"$ref": "#/definitions/myData"
},
{
"$ref": "#/definitions/foo"
}
],
"definitions": {
"foo": {
"properties": {
"bar": {
"properties": {
"bang": {
"items": {
"$ref": "#/definitions/foo"
},
"type": "array"
}
},
"type": "object"
}
},
"type": "object"
},
"myData": {
"properties": {
"list": {
"additionalProperties": {
"anyOf": [
{
"$ref": "#/definitions/myData"
},
{
"items": {
"$ref": "#/definitions/myData"
},
"type": "array"
}
]
},
"type": "object"
}
},
"type": "object"
}
},
"type": "object"
}
我们确实需要 bang 属性用它自己的定义定义一个元素数组。
这个 jsonSchema 在抛出这个错误时被 fastify 读取。
FastifyError [FST_ERR_SCH_SERIALIZATION_BUILD]:构建 GET 的序列化架构失败:xxx,由于错误,超出了最大调用堆栈大小
从 jsonSchema 验证器看来,这两个模式都是有效的。
【问题讨论】:
-
您的架构没有问题。您正在使用的某个库中一定存在错误。
-
Maximum call stack size exceeded-- 您的实现是否允许提高最大调用堆栈大小?对于您在此处使用的递归量,它可能设置得稍微太低,并且它会触发认为它处于无限循环中。 -
有一个未解决的问题(自 2019 年以来):github.com/fastify/fast-json-stringify/issues/181 维护者表示他们没有时间修复它,因为它需要进行重大重构。欢迎公关。
标签: json jsonschema fastify