Skip to content

Commit 26d5305

Browse files
committed
fetch spec from url provided in query parameter
1 parent 5c77857 commit 26d5305

File tree

6 files changed

+30
-24
lines changed

6 files changed

+30
-24
lines changed

dist/swagger-ui.js

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

dist/swagger-ui.js.map

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

src/core/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import System from "core/system"
44
import ApisPreset from "core/presets/apis"
55
import * as AllPlugins from "core/plugins/all"
66
import { filterConfigs } from "plugins/configs"
7+
import { parseSeach } from "core/utils"
78

89
module.exports = function SwaggerUI(opts) {
910

@@ -73,9 +74,13 @@ module.exports = function SwaggerUI(opts) {
7374

7475
let localConfig = system.specSelectors.getLocalConfig ? system.specSelectors.getLocalConfig() : {}
7576
let mergedConfig = deepExtend({}, config, configs, localConfig)
77+
let search = parseSeach()
78+
if (search.url) {
79+
mergedConfig.url = search.url
80+
}
7681
store.setConfigs(filterConfigs(mergedConfig))
7782

78-
if(typeof mergedConfig.spec === "object" && Object.keys(mergedConfig.spec).length) {
83+
if(!search.url && typeof mergedConfig.spec === "object" && Object.keys(mergedConfig.spec).length) {
7984
system.specActions.updateUrl("")
8085
system.specActions.updateLoadingStatus("success");
8186
system.specActions.updateSpec(JSON.stringify(mergedConfig.spec))

src/core/plugins/download-url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function downloadUrlPlugin (toolbox) {
3030
},
3131

3232
updateLoadingStatus: (status) => {
33-
let enums = [null, "loading", "failed", "success"]
33+
let enums = [null, "loading", "failed", "success", "failedConfig"]
3434
if(enums.indexOf(status) === -1) {
3535
console.error(`Error: ${status} is not one of ${JSON.stringify(enums)}`)
3636
}

src/core/utils.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,3 +549,19 @@ export const getSampleSchema = (schema, contentType="", config={}) => {
549549

550550
return JSON.stringify(memoizedSampleFromSchema(schema, config), null, 2)
551551
}
552+
553+
export const parseSeach = () => {
554+
let map = {}
555+
let search = window.location.search
556+
557+
if ( search != "" ) {
558+
let params = search.substr(1).split("&");
559+
560+
for (let i in params) {
561+
i = params[i].split("=");
562+
map[decodeURIComponent(i[0])] = decodeURIComponent(i[1]);
563+
}
564+
}
565+
566+
return map;
567+
}

src/plugins/configs/index.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import YAML from "js-yaml"
2+
import { parseSeach } from "core/utils"
23
import yamlConfig from "../../../swagger-config.yaml"
34

45
const CONFIGS = [ "url", "spec", "validatorUrl", "onComplete", "onFailure", "authorizations", "docExpansion",
@@ -16,22 +17,6 @@ const parseYamlConfig = (yaml, system) => {
1617
}
1718
}
1819

19-
const parseSeach = () => {
20-
let map = {}
21-
let search = window.location.search
22-
23-
if ( search != "" ) {
24-
let params = search.substr(1).split("&");
25-
26-
for (let i in params) {
27-
i = params[i].split("=");
28-
map[decodeURIComponent(i[0])] = decodeURIComponent(i[1]);
29-
}
30-
}
31-
32-
return map;
33-
}
34-
3520

3621
export default function configPlugin (toolbox) {
3722
let { fn } = toolbox

0 commit comments

Comments
 (0)