Skip to content

Commit d866b87

Browse files
committed
make it work for yaml specs as well
1 parent 897be68 commit d866b87

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"fast-glob": "3.3.1",
2828
"jquery": "3.7.0",
2929
"jquery.are-you-sure": "1.9.0",
30+
"js-yaml": "4.1.0",
3031
"katex": "0.16.8",
3132
"license-checker-webpack-plugin": "0.2.1",
3233
"lightningcss-loader": "2.1.0",

web_src/js/standalone/swagger.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import SwaggerUI from 'swagger-ui-dist/swagger-ui-es-bundle.js';
22
import 'swagger-ui-dist/swagger-ui.css';
3+
import {parseUrl} from '../utils.js';
4+
import {load} from "js-yaml";
35

46
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();
7+
const url = parseUrl(document.getElementById('swagger-ui').getAttribute('data-source'));
8+
const res = await fetch(url.toString());
9+
const text = await res.text();
10+
const spec = /\.ya?ml$/i.test(url.pathname) ? load(text) : JSON.parse(text);
811

912
// This code is shared for our own spec as well as user-defined specs, this
1013
// section is for our own spec
11-
if (url.endsWith('/swagger.v1.json')) {
14+
if (url.pathname.endsWith('/swagger.v1.json')) {
1215
// Make the page's protocol be at the top of the schemes list
1316
const proto = window.location.protocol.slice(0, -1);
1417
spec.schemes.sort((a, b) => {

0 commit comments

Comments
 (0)