code.gitea.io/gitea@v1.21.7/web_src/js/standalone/swagger.js (about)

     1  import SwaggerUI from 'swagger-ui-dist/swagger-ui-es-bundle.js';
     2  import 'swagger-ui-dist/swagger-ui.css';
     3  
     4  window.addEventListener('load', async () => {
     5    const url = document.getElementById('swagger-ui').getAttribute('data-source');
     6    const res = await fetch(url);
     7    const spec = await res.json();
     8  
     9    // Make the page's protocol be at the top of the schemes list
    10    const proto = window.location.protocol.slice(0, -1);
    11    spec.schemes.sort((a, b) => {
    12      if (a === proto) return -1;
    13      if (b === proto) return 1;
    14      return 0;
    15    });
    16  
    17    const ui = SwaggerUI({
    18      spec,
    19      dom_id: '#swagger-ui',
    20      deepLinking: true,
    21      docExpansion: 'none',
    22      defaultModelRendering: 'model', // don't show examples by default, because they may be incomplete
    23      presets: [
    24        SwaggerUI.presets.apis
    25      ],
    26      plugins: [
    27        SwaggerUI.plugins.DownloadUrl
    28      ]
    29    });
    30  
    31    window.ui = ui;
    32  });