swagger-api / swagger-samples

Samples for the various Swagger projects under swagger-api
http://swagger.io
Apache License 2.0
538 stars 883 forks source link

Simple Ask | Can we bundle common responses about error ? #207

Closed mztnnrt closed 3 years ago

mztnnrt commented 3 years ago

Thank you very much for your implement, can i ask about api responses ?


Is there the way that bundle common response about error ? For example, status 400, 401, 404, 500 is common each API. (except for 200)

paths:
  /memos:
    get:
      tags: [Memo]
      x-exegesis-controller: memo
      operationId: memo#all
      parameters:
        - name: tag
          in: query
          schema:
            type: string
      responses:
        200:
          $ref: '#/components/responses/memos'
        400:
          $ref: '#/components/responses/400'
        401:
          $ref: '#/components/responses/401'
        404:
          $ref: '#/components/responses/404'
        500:
          $ref: '#/components/responses/500'
components:
  responses:
      201:
        description: Created.
      400:
        description: Bad request.
      401:
        description: Unauthorized request.
      404:
        description: Not found.
      500:
        description: Internal server error.
      memos:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/memoResponse'

In summary, I want to know that can we bundle response as like below. (part of "✅") (In a word , "response common components")

paths:
  /memos:
    get:
      tags: [Memo]
      x-exegesis-controller: memo
      operationId: memo#all
      parameters:
        - name: tag
          in: query
          schema:
            type: string
      responses:
        200:
          $ref: '#/components/responses/memos'
        errors: # ✅
           #... contain 400, 401, 404, 500.

If exists, please share info for developer, If exists, our yaml become more simple and readable, i think 🧑🏼‍💻

webron commented 3 years ago

You can use the default keyword. That said please use our forums for general questions.