0

在 OpenApi 3 中,我可以为同一状态代码指定多个返回模式。

例如:给定端点/something,它可以返回一个ApiResultOkApiResultError

(示例来自https://stackoverflow.com/a/47453822/3430316

openapi: 3.0.0
paths:
  /something:
    get:
      responses:
        '200':
          description: Result
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ApiResultOk'
                  - $ref: '#/components/schemas/ApiResultError'
components:
  schemas:
    ApiResultOk:
      type: object
      properties:
        result:
          type: boolean
          enum: [true]
        token:
          type: string
      required:
        - result
        - token
    ApiResultError:
      type: object
      properties:
        result:
          type: boolean
          enum: [false]
        errorCode:
          type: string
        errorMsg:
          type: string

是否可以为相关架构指定不同的标头?

(作为一种解决方法,标题在提供时可以是可选的描述。)

4

0 回答 0