使用枚举时看不到滚动菜单

Cant see scroll menu when working with enum

我想在 openAPI 中定义枚举。

我看了这个post:

How to define an enum in OpenAPI (Swagger)?

我希望能够看到这样的枚举:

我正在使用 components 并将其定义为:

components:
  
  schemas:
  
    FilterImg:
      type: object
      properties:
          name:
            type: string
            enum: ["img_1", "img_2"]
          value:
            type: string

我正在使用它:

post:
      summary: Add new img
      tags:
        - img
      description: Lets a user post a new img
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FilterImg'
      responses:
        '200':
          description: Successfully
    

但是我看不到枚举作为枚举滚动菜单(在网络浏览器中),正如我们在示例中看到的那样。

我错过了什么?

您正在传递 application/json 内容类型并且您想要 enum dropdown 这怎么可能?

您需要从本文档中了解更多关于 swagger 的知识 Swagger Docs and Openapi Specification,

无论如何我有了一个想法,你需要在正文中使用这个下拉菜单所以我在这里添加了 application/x-www-form-urlencoded 内容类型:

post:
  summary: Add new img
  tags:
    - img
  description: Lets a user post a new img
  requestBody:
    required: true
    content:
      application/x-www-form-urlencoded:
        schema:
          $ref: '#/components/schemas/FilterImg'
  responses:
    '200':
      description: Successfully

其余内容相同。

它看起来像:

希望对您有所帮助。

对于 JSON/XML 请求和响应主体,各个主体字段的枚举值显示在架构文档中,即 Schema 选项卡(或模型 选项卡(如果是 OpenAPI 2.0)。