【发布时间】:2021-10-20 14:14:29
【问题描述】:
我使用 Swagger 设计 API,并使用 Swagger UI 在我们的公司 API 设计网站上显示它们。我有一个 JSON 文件,其中包含一个 JSONSCHEMA,其中包含我想在多个 SWAGGER 文件中使用的每个变量。
例如,假设 foo.json 文件包含以下架构:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "fooooo",
"version": "2021_11",
"type": "object",
"definitions": {
"EligibilityNotification": {
"type":"object",
"properties": {
"code": {
"type": "string"
},
"label": {
"type": "string"
}
}
}
}
}
我有以下招摇文件:
components:
NotificationGroup:
type: object
properties:
eligibilityNotifications:
type: array
items:
$ref: '../JSONSchemas/foo.json#/definitions/EligibilityNotification'
相对路径是正确的,我在创建主题之前仔细检查了它。
当我通过“OpenAPI SwaggerUI preview”Visual Studio Code 的插件浏览 swagger 时,我在本地遇到以下问题:
“未知类型:object,null”
【问题讨论】:
-
foo.json 中的
EligibilityNotification模式是否指定"type":"object"或"type": ["object", "null"]?后一种语法仅在 OpenAPI 3.1 中受支持,但在 3.0 中不受支持。
标签: json swagger swagger-ui jsonschema