OpenAPI-Specification icon indicating copy to clipboard operation
OpenAPI-Specification copied to clipboard

Configuring global request parameters

Open hjpbarcelos opened this issue 12 years ago • 15 comments

Could we have a way for declaring global request parameters?

I'm working on an aggregation API that has its own authentication method. What I do is just to forward an Authentication header to these APIs that will handle the authentication.

Currently, I have to set:

    parameters:
        - name: authorization
        in: header
        description: The user access token
        required: true

in every request.

Is there an easy way to include a option that allows us to configure global request parameters? I'm pretty sure I'm not the only one with this need. Some coleagues of mine have worked with swagger some time ago and they told me they had faced the same issue.

Suggestions I have for this:

  1. Having an wildcard entry on paths:

    *:
        post:
            parameters:
                - name: authorization
                  in: header
                  description: The user access token
                  required: true
        get:  
            parameters:
                - name: authorization
                  in: header
                  description: The user access token
                  required: true
    

    It could be very repetitive if we needed to set the parameters for every request method.

  2. Having an wildcard entry on paths that allows global path and global method configuration:

    *:
        *:
            parameters:
                - name: authorization
                  in: header
                  description: The user access token
                  required: true
        post:
            parameters:
                - name: another_one
                  in: body
                  description: Something
                  required: true
    

    This way, we could set global parameters for every method and refining if needed.

There should also be a way to ignore these global configurations, such as:

/signin:
    post:
        parameters:
            - name: username
            # ...
        use_global_parameters: false

Also, there should be possible to overwrite the global configurations, like:

*:
    *:
        parameters:
            - name: something
                in: query
                description: something
                required: true
    post:
        parameters:
            - name: something
                in: body
                description: Something
                required: true

hjpbarcelos avatar Oct 13 '14 21:10 hjpbarcelos

I don't believe we're going to support global parameters so quickly. That's the bad news. The good news is that authorization gets special treatment anyways and there's a way to declare security schemes globally. I just updated the security sections in the spec yesterday/today (depending on your TZ) which allows you to declare a security header or query parameter that needs to be sent with the request.

https://github.com/wordnik/swagger-spec/blob/master/versions/2.0.md#swaggerSecurityDefinitions https://github.com/wordnik/swagger-spec/blob/master/versions/2.0.md#swaggerSecurity

By the way, this is not new to 2.0 and could have been done in previous versions as well.

webron avatar Oct 14 '14 03:10 webron

So, as far as I understood, the security scheme type I should use to solve my problem (just to pass the Authentication header around) is apiKey. Am I right?

hjpbarcelos avatar Oct 14 '14 16:10 hjpbarcelos

That is correct.

webron avatar Oct 14 '14 17:10 webron

Ok, I'll look into it. Thank you =].

hjpbarcelos avatar Oct 14 '14 17:10 hjpbarcelos

Hi @webron

I have this defined in the global swagger-spec:

securityDefinitions:
  forwarded:
    name: authorization
    type: apiKey
    in: header
  /profiles/me:
    x-swagger-router-controller: profile
    get:
      security:
        - passaporte:
          - forwarded
      description: Gets the information about the current user
      operationId: me

How can I obtain the security params?

Thank you,

hjpbarcelos avatar Nov 20 '14 17:11 hjpbarcelos

I'm not sure what you mean by that question...

webron avatar Nov 20 '14 18:11 webron

I am sorry. Let me try to put this another way.

My problem is the the same of the first post in this thread: I need to forward an authorization header to another API.

This is repeated across almost every API entry, but the authentication and refresh authentication ones.

Right now, I'm doing it in an operation-base:

    parameters:
        - name: authorization
          in: header
          description: The user access token
          required: true

Now I'm trying to remove this and use the security object, but I need access to the security parameters in order to forward them, but I couldn't find a way of doing so.

hjpbarcelos avatar Nov 20 '14 18:11 hjpbarcelos

What do you mean access and forward them? Swagger is for documentation, there's no 'action' behind it.

webron avatar Nov 20 '14 18:11 webron

When I'm passing a header as a parameter, I'm able to access it like:

function someExpressRouteCallback(req, res) {
    var authorization = req.params.swagger.authorization.value;
}

What I'm asking is if there's a way of obtaining the value of this authorization header when I configure it as a security definition.

hjpbarcelos avatar Nov 20 '14 18:11 hjpbarcelos

This is using which library?

webron avatar Nov 20 '14 18:11 webron

Oh, I see now. This is not defined here. Sorry about that. I'm using apigee-127, maybe I should ask them how to do this. Sorry to bother you.

hjpbarcelos avatar Nov 20 '14 19:11 hjpbarcelos

Hehe, yeah. They may have not had the chance to implement it yet, but you should bring it up with them.

webron avatar Nov 20 '14 19:11 webron

@webron can you please help me how to access apiKey at url after setting it. https://stackoverflow.com/questions/49050969/setting-swagger-apikey-in-version-3-0

shatestest avatar Mar 05 '18 12:03 shatestest

Is it possible to set a default apikey value like the one below.

securityDefinitions:
  forwarded:
    name: authorization
    type: apiKey
    in: header
    default: myapikey

I tried this, but it doesn't work.

deepan-itela avatar Jul 31 '18 22:07 deepan-itela

I've got a few headers that are always sent back, and every request path has got multiple possible status codes, especially because >= 400 ranges are documented too.

I've got a few hundred of these repeating:

local checkbuster ninja_8444_api-docs_

Can this issue be re-opened?

StephanBijzitter avatar Jul 25 '21 01:07 StephanBijzitter