Swagger/OpenAPI 3.0 issue with example on responses

时光总嘲笑我的痴心妄想 提交于 2020-01-02 07:15:09

问题


This is a simplified version of my OpenAPI 3.0 definition I'm viewing on the Swagger Editor online. I am trying to have the two responses for error codes 401 and 403, that share the same schema, show different examples - this doesn't seem to work and I still see the referenced type as example.

Can you help me figuring out what's wrong with the definitions?

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

回答1:


Your definition is correct, and the response example show up in Swagger Editor 3.6.5+ and Swagger UI 3.17.4+. Also, multiple examples are supported in Swagger UI 3.23.0+ and Editor 3.6.31+.



来源:https://stackoverflow.com/questions/48551855/swagger-openapi-3-0-issue-with-example-on-responses

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