<!-- HTML for static distribution bundle build -->
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Swagger UI</title>
    <link
      rel="stylesheet"
      type="text/css"
      href="https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui.css"
      integrity="sha384-wxLW6kwyHktdDGr6Pv1zgm/VGJh99lfUbzSn6HNHBENZlCN7W602k9VkGdxuFvPn"
      crossorigin="anonymous"
      referrerpolicy="no-referrer"
    />
    <link rel="icon" type="image/png" href="favicon-32x32.png" sizes="32x32" />
    <link rel="icon" type="image/png" href="favicon-16x16.png" sizes="16x16" />
    <style>
      html {
        box-sizing: border-box;
        overflow: -moz-scrollbars-vertical;
        overflow-y: scroll;
      }

      *,
      *:before,
      *:after {
        box-sizing: inherit;
      }

      body {
        margin: 0;
        background: #fafafa;
      }

      .swagger-ui .topbar a {
        content: url('public/img/grafana_icon.svg');
        height: 50px;
        flex: 0;
      }
    </style>
  </head>

  <body>
    <div id="swagger-ui"></div>

    <script
      nonce="[[.Nonce]]"
      src="https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui-bundle.js"
      charset="UTF-8"
      integrity="sha384-wmyclcVGX/WhUkdkATwhaK1X1JtiNrr2EoYJ+diV3vj4v6OC5yCeSu+yW13SYJep"
      crossorigin="anonymous"
      referrerpolicy="no-referrer"
    ></script>
    <script
      nonce="[[.Nonce]]"
      src="https://unpkg.com/swagger-ui-dist@5.17.14/swagger-ui-standalone-preset.js"
      charset="UTF-8"
      integrity="sha384-2YH8WDRaj7V2OqU/trsmzSagmk/E2SutiCsGkdgoQwC9pNUJV1u/141DHB6jgs8t"
      crossorigin="anonymous"
      referrerpolicy="no-referrer"
    ></script>
    <script nonce="[[.Nonce]]">
      window.onload = async function () {
        // the trailing slash breaks relative URL loading
        if (window.location.pathname.endsWith('/')) {
          const idx = window.location.href.lastIndexOf('/');
          window.location.href = window.location.href.substring(0, idx);
          return;
        }

        const urlParams = new URLSearchParams(window.location.search);
        const v2 = { name: 'Grafana API (OpenAPI v2)', url: 'public/api-merged.json' };
        const v3 = { name: 'Grafana API (OpenAPI v3)', url: 'public/openapi3.json' };
        const urls = urlParams.get('show') == 'v3' ? [v3, v2] : [v2, v3];
        try {
          const rsp = await fetch('openapi/v3');
          const apis = await rsp.json();
          for (const [key, value] of Object.entries(apis.paths)) {
            const parts = key.split('/');
            if (parts.length == 3) {
              urls.push({
                name: `${parts[1]}/${parts[2]}`,
                url: value.serverRelativeURL.substring(1), // remove initial slash
              });
            }
          }
          urls.push({ name: 'Grafana apps (OpenAPI v2)', url: 'openapi/v2' });
        } catch (err) {
          // console.warn('Error loading k8s apis', err);
        }

        // Begin Swagger UI call region
        const ui = SwaggerUIBundle({
          urls,
          dom_id: '#swagger-ui',
          deepLinking: true,
          presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],
          plugins: [SwaggerUIBundle.plugins.DownloadUrl],
          layout: 'StandaloneLayout',
          filter: true,
          tagsSorter: 'alpha',
          tryItOutEnabled: true,
          queryConfigEnabled: false,
        });

        window.ui = ui;
      };
    </script>
  </body>
</html>