adding headers in swagger YAML for dev portal API documentation

Not applicable
I am creating this YAML on http://playground.apistudio.io/b0ac1d44-630e-4ec5-827b-21930590a985/#/ But the try operation bit is not working .part of the reason is that my API is secured via an APpkey.How can I set a header and give it a predefined value ..i want to add this headers: Apikey: "55JIO0chabcdffGGCCK0fCYQ5phBAVd" Please suggest how to do this or an example will help

Additional Information

Solved Solved
0 4 36.2K
1 ACCEPTED SOLUTION

Not applicable

Hi @shweta agarwal

You can use parameters object with default for the parameter as below.

parameters:
        - name: Apikey
          in: header
          description: API key
          required: false
          type: string
          format: string
          default: xxxx

Please find the updated swagger yaml attached with the answer.

wiley.txt

View solution in original post

4 REPLIES 4

Not applicable

Hi @shweta agarwal

You can use parameters object with default for the parameter as below.

parameters:
        - name: Apikey
          in: header
          description: API key
          required: false
          type: string
          format: string
          default: xxxx

Please find the updated swagger yaml attached with the answer.

wiley.txt

@shweta agarwal , You can find details regarding swagger spec 2.0 here.

@Anil Sagar tahts exactly what I was looking for.

Thanks

Not applicable

Header parameter

Let’s say we want our API consumer’s to provide some informations about themselves by using the good old User-Agent HTTP header (for tracking, debugging, or whatever you want).

We define the parameter just like any other one, we just need to set the headervalue in in:

  userAgent:
    name: User-Agent
    type: string
    in: header
    required: true

And we use it (on every path) just like any other parameter:

paths:
  /persons:
    parameters:
      - $ref: '#/parameters/userAgent'

There’s absolutely no way of telling once and for all that all operations needs this header parameter (for now).

nb: This works also with custom HTTP header.