blob: ed6461766046e52557419a6769b7f9629384928a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
import { SwaggerUIBundle } from 'swagger-ui-dist';
import { safeLoad } from 'js-yaml';
import { isObject } from '~/lib/utils/type_utility';
const renderSwaggerUI = (value) => {
/* SwaggerUIBundle accepts openapi definition
* in only JSON format, so we convert the YAML
* config to JSON if it's not JSON value
*/
let spec = value;
if (!isObject(spec)) {
spec = safeLoad(spec, { json: true });
}
Promise.all([import(/* webpackChunkName: 'openapi' */ 'swagger-ui-dist/swagger-ui.css')])
.then(() => {
SwaggerUIBundle({
spec,
dom_id: '#swagger-ui',
deepLinking: true,
displayOperationId: true,
});
})
.catch((error) => {
throw error;
});
};
const addInitHook = () => {
window.addEventListener(
'message',
(event) => {
if (event.origin !== window.location.origin) {
return;
}
renderSwaggerUI(event.data);
},
false,
);
};
addInitHook();
export default {};
|