无法在swagger文档中包含json架构



习惯于使用RAML定义API定义,我的工作是研究切换到使用Swagger v3,因为它现在支持YAML风格的语法。

我希望将一个非常小的带有json模式和示例的RAML文档迁移到swagger 3中,并且我正在努力将json模式迁移到swager 中

我一直在使用https://swagger.io/docs/并查看其他各种博客文章

这是我正在使用并试图进入swagger 的json模式

{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"analytics": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"date": {
"type": "string",
"format": "date"
},
"submission": {
"type": "string"
},
"source": {
"type": "string"
},
"model": {
"type": "string"
},
"count": {
"type": "integer"
}
},
"additionalProperties": false,
"required": [
"date",
"submission",
"source",
"model",
"count"
]
}
]
}
},
"additionalProperties": false,
"required": [
"analytics"
]
}

现在看看swagger文档和其他帖子,我应该使用components标记来定义模式,因为它可以被引用为$ref:'#/components/schemas/validresponse'

这是我使用swagger文档创建的

components:
schemas:
validresponse:
additionalProperties: true
analytics:
type: object
properties: 
analytics:
type: array
items:
type: object
properties :
date:
type: string
format: date
submission:
type: string
source:
type: string
model:
type: string
count:
type: integer
required: 
- date
- submission
- source
- model
- count

我正在使用app.swakerhub.com编辑器,并且我得到了一个错误

"不应具有其他属性additionalProperty:analytics"在有效响应行上突出显示

如果我删除了额外的Properties行,那么我仍然会得到错误

在我的招摇过市文件中,我没有其他提及额外财产的内容

我不知道为什么这不起作用。我希望这是简单的事情,我做错了

更改

components:
schemas:
validresponse:
additionalProperties: true
analytics:
type: object
properties: 
analytics:
type: array
...

进入

components:
schemas:
validresponse:
additionalProperties: true
# <--- no "analytics:" node here.
type: object   # <--- "type: object" must be indented same as additionalProperties above
properties: 
analytics:
type: array
...

最新更新