debian-mirror-gitlab/app/assets/javascripts/blob/openapi/index.js

28 lines
1 KiB
JavaScript
Raw Normal View History

2020-01-01 13:55:28 +05:30
import { SwaggerUIBundle } from 'swagger-ui-dist';
2021-09-30 23:02:18 +05:30
import createFlash from '~/flash';
2021-12-07 22:27:20 +05:30
import { removeParams, updateHistory } from '~/lib/utils/url_utility';
2020-01-01 13:55:28 +05:30
import { __ } from '~/locale';
export default () => {
const el = document.getElementById('js-openapi-viewer');
Promise.all([import(/* webpackChunkName: 'openapi' */ 'swagger-ui-dist/swagger-ui.css')])
.then(() => {
2021-12-07 22:27:20 +05:30
// Temporary fix to prevent an XSS attack due to "useUnsafeMarkdown"
// Once we upgrade Swagger to "4.0.0", we can safely remove this as it will be deprecated
// Follow-up issue: https://gitlab.com/gitlab-org/gitlab/-/issues/339696
updateHistory({ url: removeParams(['useUnsafeMarkdown']), replace: true });
2020-01-01 13:55:28 +05:30
SwaggerUIBundle({
url: el.dataset.endpoint,
dom_id: '#js-openapi-viewer',
2021-12-07 22:27:20 +05:30
useUnsafeMarkdown: false,
2020-01-01 13:55:28 +05:30
});
})
2021-03-08 18:12:59 +05:30
.catch((error) => {
2021-09-30 23:02:18 +05:30
createFlash({
message: __('Something went wrong while initializing the OpenAPI viewer'),
});
2020-01-01 13:55:28 +05:30
throw error;
});
};