2

I have a set of Swagger file that defines the parameters in the usual manner. For instance:

parameters:
      - $ref: '#/parameters/authorization'
...  
parameters:  
  authorization:
    name: Authorization
    description: ''
    required: true
    type: string
    in: header

Upon importing these file into Postman, the Postman collection is correctly created, however I'd like the Postman variable for the "Authorization" parameter to be "AUTH_TOKEN" instead of "Authorization" (for instance).

Effectively, I want to declare a field (ideally in the swagger file?) that says "when exported to Postman, used the value AUTH_TOKEN as the variable name, instead of the default 'name' of "Authorization").

It seemed like x-postman-meta in the swagger might help with, but didn't find any info on this property outside of the GH issue on here saying it might help.

Anyhow - how can I achieve this?

empire29
  • 3,729
  • 6
  • 45
  • 71

1 Answers1

1

I've found a way to do this, although it doesn't feel good from a OpenAPI/Swagger perspective. What I found is you can add a "default" property with your variable name e.g.

    {
      "in": "header",
      "name": "Authorization",
      "description": "The bearer token in the format: Bearer {token}",
      "required": true,
      "type": "string",
      "default": "Bearer {{token}}"
    }

This feels bad because what the default property actually is for:

Use the default keyword in the parameter schema to specify the default value for an optional parameter. The default value is the one that the server uses if the client does not supply the parameter value in the request. The value type must be the same as the parameter’s data type.

So this wouldn't work if you had a integer type that you wanted to fill with a variable. Additionally, from a documentation standpoint it's plain wrong, the server requires this parameter to be provided by the client, it can't also have a default value, that's contradictory. Would be interested in a more "feel-good" solution.

Reference: https://swagger.io/docs/specification/describing-parameters/

voidmane
  • 48
  • 4