与draft-07
相比,它定义:
{
"type": ["object", "boolean"],
"properties": {
...
"$ref": {
"type": "string",
"format": "uri-reference"
},
}
...
}
目前我正在尝试为openapi
编写验证器。但验证失败是因为openapi
schema(是的,它是来自Google API的模式)并未将$ref
定义为schema
的允许属性。
$ref
属性的建议是什么?
答案 0 :(得分:2)
$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
某些内容或reference
(example):
"schemaOrReference": {
"oneOf": [
{
"$ref": "#/definitions/schema"
},
{
"$ref": "#/definitions/reference"
}
]
},
顺便说一下,官方OpenAPI规范库中目前有两个不同的OAS3 JSON Schema草案。请随意尝试,并在相应的讨论中提供反馈。