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

30 lines
852 B
JavaScript
Raw Normal View History

2022-11-25 23:54:43 +05:30
import { setAttributes } from '~/lib/utils/dom_utils';
import axios from '~/lib/utils/axios_utils';
2020-01-01 13:55:28 +05:30
2022-11-25 23:54:43 +05:30
const createSandbox = () => {
const iframeEl = document.createElement('iframe');
setAttributes(iframeEl, {
src: '/-/sandbox/swagger',
2023-03-04 22:38:38 +05:30
sandbox: 'allow-scripts allow-popups allow-forms',
2022-11-25 23:54:43 +05:30
frameBorder: 0,
width: '100%',
// The height will be adjusted dynamically.
// Follow-up issue: https://gitlab.com/gitlab-org/gitlab/-/issues/377969
height: '1000',
});
return iframeEl;
};
export default async () => {
const wrapperEl = document.getElementById('js-openapi-viewer');
const sandboxEl = createSandbox();
const { data } = await axios.get(wrapperEl.dataset.endpoint);
wrapperEl.appendChild(sandboxEl);
2020-01-01 13:55:28 +05:30
2022-11-25 23:54:43 +05:30
sandboxEl.addEventListener('load', () => {
sandboxEl.contentWindow.postMessage(data, '*');
});
2020-01-01 13:55:28 +05:30
};