为什么 OpenAPI 没有将 '$ref' 定义为允许 属性?
Why OpenAPI does not define '$ref' as allowed property?
与 draft-07
相比,它定义了:
{
"type": ["object", "boolean"],
"properties": {
...
"$ref": {
"type": "string",
"format": "uri-reference"
},
}
...
}
目前我正在尝试为 openapi
. But validation fails because openapi
schema 编写验证器(是的,它是来自 google api 的架构)没有定义 $ref
允许 属性 用于 schema
.
这是打字错误吗?关于如何检查$ref
属性有什么建议?
$ref
是 JSON 参考。它不是 schema
定义的一部分,而是 reference
定义的一部分:
"reference": {
"type": "object",
"description": "A simple object to allow referencing other components in the specification, internally and externally. The Reference Object is defined by JSON Reference and follows the same structure, behavior and rules. For this specification, reference resolution is accomplished as defined by the JSON Reference specification and not by the JSON Schema specification.",
"required": [
"$ref"
],
"additionalProperties": false,
"properties": {
"$ref": {
"type": "string"
}
}
},
然后其他允许 $ref
的定义使用 oneOf
something 或 reference
(example):
"schemaOrReference": {
"oneOf": [
{
"$ref": "#/definitions/schema"
},
{
"$ref": "#/definitions/reference"
}
]
},
顺便说一句,官方 OpenAPI 规范存储库中目前有两个不同的草案 OAS3 JSON 模式。请随意尝试,并在相应的讨论中提供您的反馈。
与 draft-07
相比,它定义了:
{
"type": ["object", "boolean"],
"properties": {
...
"$ref": {
"type": "string",
"format": "uri-reference"
},
}
...
}
目前我正在尝试为 openapi
. But validation fails because openapi
schema 编写验证器(是的,它是来自 google api 的架构)没有定义 $ref
允许 属性 用于 schema
.
这是打字错误吗?关于如何检查$ref
属性有什么建议?
$ref
是 JSON 参考。它不是 schema
定义的一部分,而是 reference
定义的一部分:
"reference": {
"type": "object",
"description": "A simple object to allow referencing other components in the specification, internally and externally. The Reference Object is defined by JSON Reference and follows the same structure, behavior and rules. For this specification, reference resolution is accomplished as defined by the JSON Reference specification and not by the JSON Schema specification.",
"required": [
"$ref"
],
"additionalProperties": false,
"properties": {
"$ref": {
"type": "string"
}
}
},
然后其他允许 $ref
的定义使用 oneOf
something 或 reference
(example):
"schemaOrReference": {
"oneOf": [
{
"$ref": "#/definitions/schema"
},
{
"$ref": "#/definitions/reference"
}
]
},
顺便说一句,官方 OpenAPI 规范存储库中目前有两个不同的草案 OAS3 JSON 模式。请随意尝试,并在相应的讨论中提供您的反馈。