summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/blob/openapi/index.js
blob: 12cc2be824642612d77388d7dc0756b159c945da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { SwaggerUIBundle } from 'swagger-ui-dist';
import { deprecatedCreateFlash as flash } from '~/flash';
import { __ } from '~/locale';

export default () => {
  const el = document.getElementById('js-openapi-viewer');

  Promise.all([import(/* webpackChunkName: 'openapi' */ 'swagger-ui-dist/swagger-ui.css')])
    .then(() => {
      SwaggerUIBundle({
        url: el.dataset.endpoint,
        dom_id: '#js-openapi-viewer',
      });
    })
    .catch(error => {
      flash(__('Something went wrong while initializing the OpenAPI viewer'));
      throw error;
    });
};