-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swagger UI (dev2.0) fails to render page when 401 response is returned. Screenshots attached #259
Comments
Hi, I just saw your other issue. It sounds like there's a bootstrapping problem, where you're not able to set the headers until after the UI loads, but it can't load because the authorization scheme isn't set. |
You should be able to do the following: <script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
url: "http://petstore.swagger.wordnik.com/api/api-docs",
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
onComplete: function(swaggerApi, swaggerUi){
if(console) {
console.log("Loaded SwaggerUI")
}
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
},
onFailure: function(data) {
if(console) {
console.log("Unable to Load SwaggerUI");
console.log(data);
}
},
docExpansion: "none"
});
$('#input_apiKey').change(function() {
var key = $('#input_apiKey')[0].value;
console.log("key: " + key);
if(key && key.trim() != "") {
console.log("added key " + key);
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "query"));
}
})
window.authorizations.add("key", new ApiKeyAuthorization("api_key", "YOUR_KEY_HERE", "query"));
window.swaggerUi.load();
});
</script> This sets the |
Thank you. That solved that issue. However, I found out that you are now missing the headers: [] property for 'obj'. Take a look at them around line 54 and 235. Cheers |
Hi,
I got dev2.0 branch and my headers wont get sent. I go: window.authorizations.add("key", new ApiKeyAuthorization("someKey", "someValue", "header"));
And because it doesnt get sent i get this:
Can you help me with this please?
Im using latest Chrome
This is some extra info:
Request URL:http://localhost:8080/PWAssessment/api/api-docs.json
Request Method:GET
Status Code:401 Unauthorized (from cache)
Request Headers
Accept:/
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Host:localhost:8080
Origin:null
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36
Response Headers
Access-Control-Allow-Headers:Content-Type, X-SCAPI-Authentication-Key
Access-Control-Allow-Methods:PUT, GET, POST, DELETE, OPTIONS
Access-Control-Allow-Origin:*
Content-Type:text/plain
Date:Mon, 15 Jul 2013 23:01:31 GMT
Server:Apache-Coyote/1.1
Transfer-Encoding:chunked
The text was updated successfully, but these errors were encountered: