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 885B

1234567891011121314151617181920212223242526272829303132
  1. import SwaggerUI from 'swagger-ui-dist/swagger-ui-es-bundle.js';
  2. import 'swagger-ui-dist/swagger-ui.css';
  3. window.addEventListener('load', async () => {
  4. const url = document.getElementById('swagger-ui').getAttribute('data-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. docExpansion: 'none',
  19. defaultModelRendering: 'model', // don't show examples by default, because they may be incomplete
  20. presets: [
  21. SwaggerUI.presets.apis
  22. ],
  23. plugins: [
  24. SwaggerUI.plugins.DownloadUrl
  25. ]
  26. });
  27. window.ui = ui;
  28. });