Re: How to set the 401 "Unauthorized" response globally?

21 views
Skip to first unread message

Ron Ratovsky

unread,
Jul 19, 2017, 6:52:32 PM7/19/17
to swagger-sw...@googlegroups.com

You can’t – the spec doesn’t support global responses.

You can define a reusable response, but would still have to reference it from the different operations.

 

 

 

From: <swagger-sw...@googlegroups.com> on behalf of "sa...@fastdone.com.br" <sa...@fastdone.com.br>
Reply-To: "swagger-sw...@googlegroups.com" <swagger-sw...@googlegroups.com>
Date: Tuesday, 18 July 2017 at 20:11
To: Swagger <swagger-sw...@googlegroups.com>
Subject: How to set the 401 "Unauthorized" response globally?

 

Hi All,

 

I am new to swagger & am trying out the features ; thus please excuse my question if it's already a documented one. I tried looking for information but could not find any...

How to set the 401 "Unauthorized" response globally? That is, without having to refer in several operations?

 

swagger: '2.0'

info:

  title: xxxxxxx

  description: >-

    xxxxxxxx

  version: 1.0.0

  contact:

    name:  xxxx

    email: xxxx

  license:

    name: Apache 2.0

schemes:

  - https

basePath: /api/v1

produces:

  - application/json

#Algumas APIs usam mais de uma chave de segurança, digamos, API Key e ID da API. Para especificar que as chaves são usadas em conjunto (como em AND lógico), liste-as no mesmo item na matriz de segurança:

securityDefinitions:

  apiKey: #Para definir a segurança baseada na chave da API:

    type: apiKey

    in: header

    name: X-API-KEY

  basicAuth: #Para aplicar a autenticação básica para toda a API:

    type: basic

  appId:

    type: apiKey

    in: header

    name: X-APP-ID

 

security:

  - apiKey: []

    appId: []

 

paths:

  /products:

    post:

      tags:

        - Products

      summary: Armazena um recurso recém-criado

      description: Cria um  produto e o armazena no sistema (ProductsController)

      operationId: ProductsController@store

      produces:

        - application/json

      responses:

        '200':

          description: Ok

          schema:

            $ref: '#/definitions/Product'

    get:

      tags:

        - Products

      summary: Lista todas os produtos cadastrados no sistema.

      operationId: ProductsController@index

      description: 

        Retorna uma lista com todas os produtos de disponibilidade

        HORIZONTAL, VERTICAL e UAU cadastrados no sistema (ProductsController).

      responses:

        '200':

          description: Ok

          schema:

            type: array

            items:

              $ref: '#/definitions/Product'

        default:

          description: 

            Ops! Ocorreu um erro na sua solicitação. Desculpe-nos o transtorno.

            Iremos corrigir para que isto não volte a acontecer e você tenha a

            melhor experiência com o Go Score!

          schema:

            $ref: '#/definitions/Error'

    Error:

    type: object

    properties:

      code:

        type: integer

        format: int32

      message:

        type: string

      fields:

        type: string

  

 

 

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages