首页 > 解决方案 > 未应用 Swagger OAS 3.0 中的独有最小值

问题描述

Swagger Editor 给了我这个示例响应:

[
  {
    "simulation_run_id": 0
  }
]

定义:

  /v1/simulation-run-submissions:
    post:
      summary: 'Post a simulation run creation TODO: Will need to update API with parameters weather file, glmfile, name, start,end,interval, etc.. check wireframe.  Submit model file and get back validation and ID.  We will use the same API above and just return validation error.'
      #description:
      responses:
        '201':
          description: The metadata for a simulation run
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/SimulationRunSubmissionResponse'
...
components:
  schemas:
    SimulationRunId:
      type : integer
      format: int64
      minimum: 1
      exclusiveMinimum: true

exclusiveMinimum选项似乎不适用于架构,因为示例显示为 0。

标签: swaggeropenapiswagger-editor

解决方案


目前 Swagger UI 和 Swagger Editor在生成请求和响应示例时不使用minimum和值。exclusiveMinimum随时提交增强请求

最简单的解决方案是example手动指定:

components:
  schemas:
    SimulationRunId:
      type : integer
      format: int64
      minimum: 1
      exclusiveMinimum: true
      example: 2  # <-------

推荐阅读