2016-03-10 13 views
6

Desidero che quasi tutti i miei percorsi abbiano le seguenti 3 risposte di errore generiche. Come posso descriverlo in Swagger senza copypasting di queste righe ovunque?Come non copiare e incollare 3 risposte di errore generiche in quasi tutti i percorsi?

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' 

Esempio di come io uso questo in una richiesta:

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' 

risposta

4

Sembra che posso aggiungere la seguente definizione di risposta globale:

# 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' 

Tuttavia mi sarà ancora necessario fare riferimento in percorsi come questo:

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

Questo non funziona con spavalderia-Codegen. .. –

Problemi correlati