Swagger ui url with options

How to pass base url in the form http://localhost:3000/resources/api/?key=aslkdajd1323121lklakskdl to swagger ui?

I managed to access http://localhost:3000/resources/api , but when I add auth filter and pass key, it says: Unauthorized .

Using swagger 1.X

Pre-populating the parameter with apiKeyauthorization in index.html did not help, but when I entered the key in the user interface, it worked. It is impossible to understand the reason for this. Hope someone can help me figure this out.

+5
source share
3 answers

Try this swagger 2.0 file (use http://studio.restlet.com to upgrade to version 1.2):

 { "swagger": "2.0", "info": { "version": "0.0.1", "title": "Todo App" }, "host": "localhost:3000", "schemes": [ "http" ], "paths": { "/resources/api": { "post": { "parameters": [ { "name": "key", "in": "query", "description": "key", "required": true, "type": "string" } ], "responses": { "200": { "description": "Successful response" } } } } } } 
+2
source

I was able to solve this by adding window.authorizations.add("key", new ApiKeyAuthorization("key", yourKeyValue, "query"));

in the constructor function SwaggerUI window.swaggerUi = new SwaggerUi({ . . .

before the expression window.swaggerUi.load()

0
source

You just need to get the parameter from url using javscript. In the "index.html" file in the swagger-ui / dist folder, add something like this to get your key:

 var key = window.location.search.match(/key=([^&]+)/); 

You can see a simple example in GIST .

0
source

All Articles