Reputation: 331
How to pass base url in the form http://localhost:3000/resources/api/?key=aslkdajd1323121lklakskdl
to swagger ui ?
I was able 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 through apiKeyauthorization in index.html did not help, but when I type in the key in UI, it worked. Unable to understand the reason for this. Hope someone can help me make sense out of it.
Upvotes: 5
Views: 8726
Reputation: 1682
You just need get the parameter from the url with javscript. In the file "index.html", under 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 my GIST.
Upvotes: 0
Reputation: 198
I was able to solve this by adding
window.authorizations.add("key", new ApiKeyAuthorization("key", yourKeyValue, "query"));
in the SwaggerUI constructor function
window.swaggerUi = new SwaggerUi({ . . .
right before the statement
window.swaggerUi.load()
Upvotes: 0
Reputation: 5441
Try this swagger 2.0 file (use http://studio.restlet.com to downgrade 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"
}
}
}
}
}
}
Upvotes: 2