Swagger: Reusing an enum definition as query parameter

我是研究僧i 提交于 2019-11-27 23:41:20

This is possible in OpenAPI 3.0. All parameters now use a schema, and, by extension, can $ref the schemas.

openapi: 3.0.0
...
paths:
  /something:
    get:
      parameters:
        - in: query
          name: action
          schema:
            $ref: '#/components/schemas/OperationType'
      ...

components:
  schemas:
    OperationType:
      type: string
      enum:
        - registration
        - renewal

For Swagger 2.0, we've limited the ability to use model definitions for anything but body parameters. The definitions section is used to define schema, which can also be used to define non-objects. However, those definitions can only be accessed where the schema keyword is used. As initially stated, schema not accessible for non-body parameters, and as such, cannot be used by query or path parameters, thus limiting the ability to reuse those definitions.

There's an open feature request asking for it to be handled in a future version of the spec.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!