jensoleg / swagger-ui

Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
http://swagger.io
Other
1.14k stars 310 forks source link

developer_key is not adding into API header #33

Open vrarora1 opened 8 years ago

vrarora1 commented 8 years ago

Hi,

API testing is not working when I started using this UI. Earlier with the default swagger theme, the API's are wroking but when I used the same json into this theme, its not working. The problem that I found is, the developer_key is not adding into the headers of API(which adds up in default drop down swagger theme). Can some one suggest how can I add the developer_key into the header of the api using this UI?

Attached the screenshot of the UI using our json.

image

Default swagger UI: image

devconductor commented 8 years ago

I have the same problem... :(

chorsnell commented 7 years ago

@vrarora1 and @devconductor, it was a fairly simple fix. If you fork / clone it, and go to line 93 of the index.html, you need to change key to match the name property of your security definition.

So:

securityDefinitions:
  Authorization:
    type: apiKey
    description: HTTP Basic Authentication. Works over `HTTP` and `HTTPS`
    in: header
    name: Authorization

You'd need to change that line 93 to:

window.swaggerUi.api.clientAuthorizations.add("Authorization", apiKeyAuth);

...or I guess you could change the name of your security definition to key.. but bleh. Will update this if I find a more dynamic solution.

Interestingly this works on the latest 3.0 release, but it doesn't look as pretty as @jensoleg's fork :laughing: