Swagger 模式属性被忽略 - 为什么?

问题描述

我正在尝试构建一个简单的 Swagger 模型:

PlayerConfig:
  type: object
  required:
    - kind
    - player_id
  properties:
    kind:
      type: string
      example: PlayerConfig
    player_id:
      type: string
      example: "foo"
      description: "bar"

sports_config:
  oneOf:
    - $ref: '#/components/schemas/PlayerConfig'
  discriminator:
    propertyName: kind

由于某种原因,生成的 HTML 没有显示 player_idexample 字段。这让我觉得我做的不对。s

所以问题是,是否可以像我尝试的那样使用模型作为类型。如果 example 字段的父字段是 parameters: 而不是 properties:,则它会被渲染。

更新:我阅读了 https://swagger.io/docs/specification/adding-examples/ 上的 Object and Property Examples 部分,看起来我的代码片段应该可以正常工作。

更新 #2:我实际上下载了 redoc-cli(这是 OpenAPI 的 CLI 工具 -> html 包)并从 Swagger 编辑器中获取一个示例规范,该规范在 example 下具有 properties 字段这模仿了我的问题,看起来像是预期的(见我附上的截图):

enter image description here

解决方法

如果字符串值包含空格(或其他一些特殊字符),则应将其括在引号中。所以这行应该是

  example: "LeBron James"