You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

swagger.js 715B

123456789101112131415161718192021222324252627282930
  1. import SwaggerUI from 'swagger-ui';
  2. import 'swagger-ui/dist/swagger-ui.css';
  3. window.addEventListener('load', async () => {
  4. const url = document.getElementById('swagger-ui').dataset.source;
  5. const res = await fetch(url);
  6. const spec = await res.json();
  7. // Make the page's protocol be at the top of the schemes list
  8. const proto = window.location.protocol.slice(0, -1);
  9. spec.schemes.sort((a, b) => {
  10. if (a === proto) return -1;
  11. if (b === proto) return 1;
  12. return 0;
  13. });
  14. const ui = SwaggerUI({
  15. spec,
  16. dom_id: '#swagger-ui',
  17. deepLinking: true,
  18. presets: [
  19. SwaggerUI.presets.apis
  20. ],
  21. plugins: [
  22. SwaggerUI.plugins.DownloadUrl
  23. ]
  24. });
  25. window.ui = ui;
  26. });