2016-03-10 22 views
6

Chcę, aby prawie wszystkie moje ścieżki miały następujące 3 ogólne odpowiedzi na błędy. Jak opisać to w Swaggerze, nie kopiując wszędzie tych linii?Jak nie skopiować i wkleić 3 ogólnych odpowiedzi na błąd w prawie wszystkich ścieżkach?

401: 
     description: The requester is unauthorized. 
     schema: 
     $ref: '#/definitions/Error' 
    500: 
     description: "Something went wrong. It's server's fault." 
     schema: 
     $ref: '#/definitions/Error' 
    503: 
     description: Server is unavailable. Maybe there is maintenance? 
     schema: 
     $ref: '#/definitions/Error' 

Przykład jak użyć tego we wniosku:

paths: 
    /roles: 
     get: 
     summary: Roles 
     description: | 
      Returns all roles available for users. 
     responses: 
      200: 
      description: An array with all roles. 
      schema: 
       type: array 
       items: 
       $ref: '#/definitions/Role' 
      401: 
      description: The requester is unauthorized. 
      schema: 
       $ref: '#/definitions/Error' 
      500: 
      description: "Something went wrong. It's server's fault." 
      schema: 
       $ref: '#/definitions/Error' 
      503: 
      description: Server is unavailable. Maybe there is maintenance? 
      schema: 
       $ref: '#/definitions/Error' 

Odpowiedz

4

Wygląda mogę dodać następujący ogólnej definicji reakcji:

# An object to hold responses that can be used across operations. 
# This property does not define global responses for all operations. 
responses: 
    NotAuthorized: 
    description: The requester is unauthorized. 
    schema: 
     $ref: '#/definitions/Error' 

jednak będę nadal trzeba odwoływać w ścieżkach tak:

401: 
    $ref: "#/responses/NotAuthorized" 
+0

to nie działa z Swagger-Codegen. .. –

Powiązane problemy