I'm using Swagger to produce the documentation of my REST API. According to 
what is written around, the Swagger UI does not offer support for basic 
authentication (differently from the online editor 
<http://editor.swagger.io/>). My problem is that one of my APIs is a POST 
that require digest (not even basic) authentication.


A possible solution I found around is to add a fixed user:pass 
authentication header in the request via javascript code. This should be 
easily done according to the Swagger UI documentation 
<https://github.com/swagger-api/swagger-ui> (see Custom Header Parameters 
<https://github.com/swagger-api/swagger-ui#custom-header-parameters---for-basic-auth-etc>).
 
I report the incriminated code line:


swaggerUi.api.clientAuthorizations.add("key", new 
SwaggerClient.ApiKeyAuthorization("Authorization", "XXXX", "header"));


Unfortunately it doesn't work. The swaggerUi.api field results 
uninitialised (null) after I initialise the SwaggerUi object, and as a 
consequence swaggerUi.api.clientAuthorizationsis undefined. I tried 
initialising such fields in different way, failing every time. I tried also 
similar calls to the API I found in threads discussing this topic, but none 
of them has worked. Does anyone have an idea about that? The documentation 
is not particularly clear about that.

For completeness, I report the js snippet where I initialise the SwaggerUI 
object


  var urlPush = "./doc_push.yaml";
  window.swaggerUiPush = new SwaggerUi({
        url: urlPush,
        dom_id: "swagger-ui-container-push",
        supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
        onFailure: function(data) {
          log("Unable to Load SwaggerUI");
        },
        docExpansion: "list",
        jsonEditor: false,
        defaultModelRendering: 'model',
        showRequestHeaders: false,
   });

-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to