【问题标题】:Required parameters in query are not marked in UI查询中的必需参数未在 UI 中标记
【发布时间】:2019-09-26 05:00:13
【问题描述】:

我已经在我的 yaml 文件参数中做了标记:

     parameters:
     - name: someID
       in: query
       description: The some ID
       required: true
       schema:
        type: uuid

在生成的 java 类字段中标记为必需,这很好,但不幸的是在 Swagger UI 上不是。这是有问题的,因为我想在请求失败之前通知用户这个文件是必需的。

【问题讨论】:

  • 1) 这是openapi: 3.0.0 还是swagger: "2.0"? 2) OpenAPI/Swagger 中没有type: uuid,你的意思是type: string + format: uuid? 3) Which version 的 Swagger UI 你使用的是 2.x 还是 3.x?我相信两者都通过使用* 来指示所需的参数。
  • swagger: 2.0 在哪里添加 * ?在名字的末尾?架构:类型:字符串格式:uuid

标签: java swagger swagger-ui


【解决方案1】:

在 OpenAPI 2.0 (swagger: '2.0') 中,查询参数不使用schema,而是直接使用type 关键字。注意there's no type: uuid,而不是你需要type: string + format: uuid

parameters:
  - name: someID
    in: query
    description: The some ID
    required: true
    type: string
    format: uuid

Swagger UI 通过在参数名称旁边显示红色* required 注释来指示所需参数:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多