Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
response => {
console.info(response);
let url = response.url;
const swaggerUI = SwaggerUI({
dom_id: "#ui",
url: response.url,
requestInterceptor: (req) => {
// Only set Authorization header if the request matches the spec URL
if (req.url === url) {
req.headers.Authorization = "Bearer " + AuthManager.getUser().getPartialToken();
}
return req;
},
presets: [
SwaggerUI.presets.apis,
disableAuthorizeAndInfoPlugin
],
plugins: [
SwaggerUI.plugins.DownloadUrl
]
})
}
).catch(
.then((responses) => {
const swagger = responses[0];
const url = swagger.url;
this.setState({ setSwagger: true });
const swaggerUI = SwaggerUI({
dom_id: '#ui',
url: swagger.url,
requestInterceptor: (req) => {
// Only set Authorization header if the request matches the spec URL
if (req.url === url) {
req.headers.Authorization = 'Bearer ' + AuthManager.getUser().getPartialToken();
}
return req;
},
presets: [SwaggerUI.presets.apis, disableAuthorizeAndInfoPlugin],
plugins: [SwaggerUI.plugins.DownloadUrl],
});
})
.catch((error) => {
EditorAutosuggestSnippetsPlugin,
EditorAutosuggestKeywordsPlugin,
EditorAutosuggestRefsPlugin,
EditorAutosuggestOAS3KeywordsPlugin,
PerformancePlugin,
JumpToPathPlugin,
SplitPaneModePlugin,
ASTPlugin,
}
const defaults = {
// we have the `dom_id` prop for legacy reasons
dom_id: "#swagger-editor", // eslint-disable-line camelcase
layout: "EditorLayout",
presets: [
SwaggerUI.presets.apis
],
plugins: Object.values(plugins),
components: {
EditorLayout
},
showExtensions: true,
swagger2GeneratorUrl: "https://generator.swagger.io/api/swagger.json",
oas3GeneratorUrl: "https://generator3.swagger.io/openapi.json",
swagger2ConverterUrl: "https://converter.swagger.io/api/convert",
}
export default function SwaggerEditor(options) {
let mergedOptions = deepMerge(defaults, options)
mergedOptions.presets = defaults.presets.concat(options.presets || [])
mergedOptions.plugins = defaults.plugins.concat(options.plugins || [])
// We actually can't prevent SwaggerUI from overwriting the set URL with one in the query string.
// https://github.com/swagger-api/swagger-ui/issues/4332
if (window.location.search) {
window.location.search = "";
}
window.ui = SwaggerUI({
deepLinking: true,
dom_id: "#swagger-ui",
layout: "DashboardLayout",
plugins: [
SwaggerUI.plugins.DownloadUrl,
vanillaForums
],
presets: [
SwaggerUI.presets.apis
],
requestInterceptor: function (request) {
request.headers["x-transient-key"] = gdn.getMeta("TransientKey");
return request;
},
url: gdn.url("/api/v2/open-api/v2"),
validatorUrl: null
});
});
let swagger = responses[0];
let url = swagger.url;
this.setState({setSwagger: true});
const swaggerUI = SwaggerUI({
dom_id: "#ui",
url: swagger.url,
requestInterceptor: (req) => {
// Only set Authorization header if the request matches the spec URL
if (req.url === url) {
req.headers.Authorization = "Bearer " + AuthManager.getUser().getPartialToken();
}
return req;
},
presets: [
SwaggerUI.presets.apis,
disableAuthorizeAndInfoPlugin
],
plugins: [
SwaggerUI.plugins.DownloadUrl
]
})
}).catch(
error => {
* application/json:
* schema:
* type: string
*/
function getHello(name) {
// TODO: Replace the code with a REST API call when it's implemented on the backend
return { message: 'Hello ' + name + '!' };
}
var helloDiv = document.getElementById('hello');
helloDiv.innerHTML = getHello('World').message;
swaggerUi({
spec: swaggerJson, dom_id: '#apiDocs',
presets: [
swaggerUi.presets.apis,
swaggerUi.SwaggerUIStandalonePreset
]
});
setTimeout(() => {
this.richPreview = new SwaggerUIBundle({
spec: this.getFormData(),
dom_id: '#rich-preview',
// Disable Swagger.io online validation (AKA spyware)
validatorUrl: null,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: 'StandaloneLayout'
});
}, 0);
}
return this.$userStore.dispatch('refreshToken')
.then(() => {
response.text = '{"internal": "KVDI: Your access token has been refreshed, please try again"}'
response.ok = true
return response
})
.catch((err) => {
console.error(err)
response.text = `{"internal": "KVDI: Failure while trying to refresh access token: ${err}"}`
return response
})
}
return response
},
presets: [
SwaggerUIBundle.presets.apis
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
]
})
if (this.$userStore.getters.isLoggedIn) {
this.ui.authActions.authorize({
api_key: {
name: 'api_key',
schema: {
type: 'apiKey',
in: 'header',
name: 'X-Session-Token',
description: ''
},
value: this.$userStore.getters.token
ngAfterViewInit() {
const ui = SwaggerUI({
url: 'http://localhost:8084/number-api/swagger.json',
domNode: this.el.nativeElement.querySelector('.swagger-container'),
deepLinking: true,
presets: [
SwaggerUI.presets.apis
],
});
}
.subscribe(json => {
json['host'] = window.location.host;
const protocal = window.location.protocol;
json['schemes'] = [protocal.replace(":", "")];
let ui = SwaggerUI({
spec: json,
domNode: this.el.nativeElement.querySelector('.swagger-container'),
deepLinking: true,
presets: [
SwaggerUI.presets.apis
],
requestInterceptor: interceptor.requestInterceptor,
authorizations: {
csrf: function () {
this.headers['X-Xsrftoken'] = csrfCookie;
return true;
}
}
});
});
}