Swagger/OpenAPI 3.0在响应中的示例问题

6
这是我在Swagger Editor在线查看的OpenAPI 3.0定义的简化版本。我试图让两个错误代码401和403的响应,它们共享相同的模式,显示不同的示例 - 但这似乎行不通,我仍然看到引用类型作为示例。
你能帮我找出定义中的问题吗?
openapi: 3.0.0
info:
  version: '1.0'
  title: A service
paths:
  /doSomething:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: string
              example: A string
      responses:
        401:
          $ref: '#/components/responses/Unauthorized'
        403:
          $ref: '#/components/responses/Denied'
components:
  responses:
    Unauthorized:
      description: The endpoint cannot be reached because the request is not authorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: unauthorized
    Denied:
      description: The request's authorizations don't match the required ones needed to access the resource
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: permissions denied
  schemas:
    Error:
      type: object
      properties:
        error:
          type: string

您的示例现在可以在Swagger Editor 3.6.5+和Swagger UI 3.17.4+中正常工作。 - Helen
2个回答

2
您的定义是正确的,响应example在Swagger Editor 3.6.5+和Swagger UI 3.17.4+中显示。此外,Swagger UI 3.23.0+和Editor 3.6.31+支持多个examples

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接