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

Unable to include json schema in swagger document

习惯使用 RAML 来定义 API 定义,我的工作正在研究切换到使用 Swagger v3,因为它现在支持 YAML 样式语法。

我希望将带有 json 架构和示例的非常小的 RAML 文档迁移到 swagger 3,并且我正在努力将 json 架构迁移到 swagger

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

这是我正在使用并试图大摇大摆的 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.swaggerhub.com 编辑器,但出现错误

"should NOT have additional properties additionalProperty: analytics " 在有效响应行突出显示

如果我删除了 additionalProperties 行,那么我仍然收到错误

我的 swagger 文档中没有其他提及 additionalProperty

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

改变

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
          ...