Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cfg["filter"] =
_.isNil(this.page.configuration.enableFiltering)
? false : this.page.configuration.enableFiltering === "true";
cfg["showExtensions"] =
_.isNil(this.page.configuration.showExtensions)
? false : this.page.configuration.showExtensions === "true";
cfg["showCommonExtensions"] =
_.isNil(this.page.configuration.showCommonExtensions)
? false : this.page.configuration.showCommonExtensions === "true";
cfg["oauth2RedirectUrl"] = window.location.origin + '/swagger-oauth2-redirect.html';
cfg["maxDisplayedTags"] =
_.isNaN(Number(this.page.configuration.maxDisplayedTags)) || this.page.configuration.maxDisplayedTags === "-1"
? undefined : Number(this.page.configuration.maxDisplayedTags);
}
const ui = SwaggerUIBundle(
_.merge(cfg, {
onComplete: () => {
// May be used in a short future, so keeping this part of the code to not forget about it.
ui.initOAuth({
clientId: "",
// appName: "Swagger UI",
scopeSeparator: " ",
// additionalQueryStringParams: {some_parm: "val"}
});
// ui.preauthorizeApiKey('api_key', 'my_api_key')
}
}));
};
export function mountSwagger() {
SwaggerUIBundle({
deepLinking: true,
dom_id: "#swagger-ui",
// layout: "DashboardLayout",
plugins: [SwaggerUIBundle.plugins.DownloadUrl],
presets: [SwaggerUIBundle.presets.apis],
requestInterceptor: (request: Request) => {
request.headers["x-transient-key"] = getMeta("TransientKey");
return request;
},
url: formatUrl("/api/v2/open-api/v3" + window.location.search),
validatorUrl: null,
});
}
public updateSwagger(resource: any): void {
const authToken = this.auth.getToken();
new SwaggerUIBundle({
dom_id: '#swaggerHolder',
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
url: window.location.protocol + '//' + window.location.host + resource,
docExpansion: 'none',
apisSorter: 'alpha',
showRequestHeaders: false,
validatorUrl: null,
configs: {
preFetch: (req) => {
if (authToken) {
req.headers['Authorization'] = 'Bearer ' + authToken;
}
return req;
},
},
});