Is there a "after JSON load()" callback for SwaggerUI ?

838 views
Skip to first unread message

Pierre Rioux

unread,
Oct 5, 2016, 5:05:16 PM10/5/16
to Swagger
I'm trying to create a SwaggerUI page in my dev environment, and I'm trying to override the HOST and SCHEME of the API described in my JSON spec.

The SwaggerUI init code is very simple, and I tried to crush the values in the onComplete() callback in this way:

var swaggerUi = new SwaggerUi({
  url
: './cbrain-4.5.0-swagger.json',
  dom_id
: 'swagger-ui-container',
  defaultModelRendering
: 'schema',
  onComplete
: function(swaggerApi, swaggerUi) {
   
// Overide the built-in CBRAIN service config to use the current page's.
   
var host   = window.location.host;                      // can include the port number
   
var scheme = window.location.protocol.replace(/:/,"");  // "http" or "https"
    swaggerApi
.scheme                = scheme;
    swaggerApi
.host                  = host;
    swaggerApi
.swaggerObject.schemes = [ scheme ];
    swaggerApi
.swaggerObject.host    = host;
 
}
});
swaggerUi
.load();


As you can see, I found 4 properties in both the swaggerAPI and internal swaggerObject where I can change the values; it works in that the values are changed, but it seems it makes no difference because the UI has already been built at this point and all the "Try it out!" dialogs are all configured to use the old HOST and SCHEME that were defined in the JSON.


My question is, how can I initialize a swaggerUI with a URL for a JSON spec, yet get the UI built with a different HOST and SCHEME ? Is there some kind of callback I can provide such that the values of the JSON object be updated BEFORE the UI is built?


Thanks.

tony tam

unread,
Oct 5, 2016, 5:22:30 PM10/5/16
to swagger-sw...@googlegroups.com
You need to run swaggerApi.setHost(“…”), etc. during the onComplete function

--
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 swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pierre Rioux

unread,
Oct 5, 2016, 5:27:24 PM10/5/16
to Swagger
Ah thanks! So where are these functions described? I'm having trouble finding the documentation in all the Swagger pages.

Pierre
Reply all
Reply to author
Forward
0 new messages