Skip to content

Commit 0047ce9

Browse files
authored
fix: don't trigger url remote document load if urls is provided (via #5161)
* fix: don't trigger `url` remote document load if `urls` is provided * better test block title
1 parent b716ed2 commit 0047ce9

File tree

5 files changed

+464
-1
lines changed

5 files changed

+464
-1
lines changed

src/core/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ module.exports = function SwaggerUI(opts) {
148148
system.specActions.updateUrl("")
149149
system.specActions.updateLoadingStatus("success")
150150
system.specActions.updateSpec(JSON.stringify(mergedConfig.spec))
151-
} else if (system.specActions.download && mergedConfig.url) {
151+
} else if (system.specActions.download && mergedConfig.url && !mergedConfig.urls) {
152152
system.specActions.updateUrl(mergedConfig.url)
153153
system.specActions.download(mergedConfig.url)
154154
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
openapi: "3.0.0"
2+
info:
3+
title: Simple API overview
4+
version: 2.0.0
5+
paths:
6+
/:
7+
get:
8+
operationId: listVersionsv2
9+
summary: List API versions
10+
responses:
11+
'200':
12+
description: |-
13+
200 response
14+
content:
15+
application/json:
16+
examples:
17+
foo:
18+
value: {
19+
"versions": [
20+
{
21+
"status": "CURRENT",
22+
"updated": "2011-01-21T11:33:21Z",
23+
"id": "v2.0",
24+
"links": [
25+
{
26+
"href": "http://127.0.0.1:8774/v2/",
27+
"rel": "self"
28+
}
29+
]
30+
},
31+
{
32+
"status": "EXPERIMENTAL",
33+
"updated": "2013-07-23T11:33:21Z",
34+
"id": "v3.0",
35+
"links": [
36+
{
37+
"href": "http://127.0.0.1:8774/v3/",
38+
"rel": "self"
39+
}
40+
]
41+
}
42+
]
43+
}
44+
'300':
45+
description: |-
46+
300 response
47+
content:
48+
application/json:
49+
examples:
50+
foo:
51+
value: |
52+
{
53+
"versions": [
54+
{
55+
"status": "CURRENT",
56+
"updated": "2011-01-21T11:33:21Z",
57+
"id": "v2.0",
58+
"links": [
59+
{
60+
"href": "http://127.0.0.1:8774/v2/",
61+
"rel": "self"
62+
}
63+
]
64+
},
65+
{
66+
"status": "EXPERIMENTAL",
67+
"updated": "2013-07-23T11:33:21Z",
68+
"id": "v3.0",
69+
"links": [
70+
{
71+
"href": "http://127.0.0.1:8774/v3/",
72+
"rel": "self"
73+
}
74+
]
75+
}
76+
]
77+
}
78+
/v2:
79+
get:
80+
operationId: getVersionDetailsv2
81+
summary: Show API version details
82+
responses:
83+
'200':
84+
description: |-
85+
200 response
86+
content:
87+
application/json:
88+
examples:
89+
foo:
90+
value: {
91+
"version": {
92+
"status": "CURRENT",
93+
"updated": "2011-01-21T11:33:21Z",
94+
"media-types": [
95+
{
96+
"base": "application/xml",
97+
"type": "application/vnd.openstack.compute+xml;version=2"
98+
},
99+
{
100+
"base": "application/json",
101+
"type": "application/vnd.openstack.compute+json;version=2"
102+
}
103+
],
104+
"id": "v2.0",
105+
"links": [
106+
{
107+
"href": "http://127.0.0.1:8774/v2/",
108+
"rel": "self"
109+
},
110+
{
111+
"href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf",
112+
"type": "application/pdf",
113+
"rel": "describedby"
114+
},
115+
{
116+
"href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
117+
"type": "application/vnd.sun.wadl+xml",
118+
"rel": "describedby"
119+
},
120+
{
121+
"href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
122+
"type": "application/vnd.sun.wadl+xml",
123+
"rel": "describedby"
124+
}
125+
]
126+
}
127+
}
128+
'203':
129+
description: |-
130+
203 response
131+
content:
132+
application/json:
133+
examples:
134+
foo:
135+
value: {
136+
"version": {
137+
"status": "CURRENT",
138+
"updated": "2011-01-21T11:33:21Z",
139+
"media-types": [
140+
{
141+
"base": "application/xml",
142+
"type": "application/vnd.openstack.compute+xml;version=2"
143+
},
144+
{
145+
"base": "application/json",
146+
"type": "application/vnd.openstack.compute+json;version=2"
147+
}
148+
],
149+
"id": "v2.0",
150+
"links": [
151+
{
152+
"href": "http://23.253.228.211:8774/v2/",
153+
"rel": "self"
154+
},
155+
{
156+
"href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf",
157+
"type": "application/pdf",
158+
"rel": "describedby"
159+
},
160+
{
161+
"href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
162+
"type": "application/vnd.sun.wadl+xml",
163+
"rel": "describedby"
164+
}
165+
]
166+
}
167+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<!-- HTML for dev server -->
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
5+
<head>
6+
<meta charset="UTF-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
<title>Swagger UI</title>
9+
<link rel="stylesheet" type="text/css" href="/swagger-ui.css">
10+
<style>
11+
html {
12+
box-sizing: border-box;
13+
overflow: -moz-scrollbars-vertical;
14+
overflow-y: scroll;
15+
}
16+
17+
*,
18+
*:before,
19+
*:after {
20+
box-sizing: inherit;
21+
}
22+
23+
body {
24+
margin: 0;
25+
background: #fafafa;
26+
}
27+
</style>
28+
</head>
29+
30+
<body>
31+
32+
<div id="swagger-ui"></div>
33+
34+
<script src="/swagger-ui-bundle.js"> </script>
35+
<script src="/swagger-ui-standalone-preset.js"> </script>
36+
<script>
37+
window.onload = function () {
38+
window["SwaggerUIBundle"] = window["swagger-ui-bundle"]
39+
window["SwaggerUIStandalonePreset"] = window["swagger-ui-standalone-preset"]
40+
// Build a system
41+
const ui = SwaggerUIBundle({
42+
url: "https://petstore.swagger.io/v2/swagger.json",
43+
urls: [
44+
{
45+
name: "USPTO",
46+
url: "./uspto.yaml"
47+
},
48+
{
49+
name: "Examples",
50+
url: "./api-with-examples.yaml"
51+
},
52+
],
53+
dom_id: '#swagger-ui',
54+
presets: [
55+
SwaggerUIBundle.presets.apis,
56+
SwaggerUIStandalonePreset
57+
],
58+
plugins: [
59+
SwaggerUIBundle.plugins.DownloadUrl
60+
],
61+
layout: "StandaloneLayout",
62+
onComplete: () => {
63+
if (window.completeCount) {
64+
window.completeCount++
65+
} else {
66+
window.completeCount = 1
67+
}
68+
}
69+
})
70+
71+
window.ui = ui
72+
}
73+
</script>
74+
</body>
75+
76+
</html>

0 commit comments

Comments
 (0)