Skip to content

Commit b41c92f

Browse files
committed
Merge branch 'url-from-query' of https://github.com/bodnia/swagger-ui into bodnia-url-from-query
2 parents ce6ce9a + 0b56640 commit b41c92f

File tree

10 files changed

+73
-76
lines changed

10 files changed

+73
-76
lines changed

dist/swagger-ui-bundle.js

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

dist/swagger-ui-bundle.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.

dist/swagger-ui-standalone-preset.js

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

dist/swagger-ui-standalone-preset.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.

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: 10 additions & 19 deletions
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

@@ -65,49 +66,39 @@ module.exports = function SwaggerUI(opts) {
6566
store.register([config.plugins, inlinePlugin])
6667

6768
var system = store.getSystem()
69+
let queryConfig = parseSeach()
6870

6971
const downloadSpec = (configs) => {
7072
if(typeof config !== "object") {
7173
return system
7274
}
7375

7476
let localConfig = system.specSelectors.getLocalConfig ? system.specSelectors.getLocalConfig() : {}
75-
let mergedConfig = deepExtend({}, config, configs, localConfig)
77+
let mergedConfig = deepExtend({}, config, localConfig, configs, queryConfig)
7678
store.setConfigs(filterConfigs(mergedConfig))
7779

78-
if(typeof mergedConfig.spec === "object" && Object.keys(mergedConfig.spec).length) {
80+
if(!queryConfig.url && typeof mergedConfig.spec === "object" && Object.keys(mergedConfig.spec).length) {
7981
system.specActions.updateUrl("")
8082
system.specActions.updateLoadingStatus("success");
8183
system.specActions.updateSpec(JSON.stringify(mergedConfig.spec))
82-
} else if(mergedConfig.url) {
84+
} else if(system.specActions.download && mergedConfig.url) {
8385
system.specActions.updateUrl(mergedConfig.url)
8486
system.specActions.download(mergedConfig.url)
8587
}
8688

87-
if(mergedConfig.dom_id)
89+
if(mergedConfig.dom_id) {
8890
system.render(mergedConfig.dom_id, "App")
91+
} else {
92+
console.error("Skipped rendering: no `dom_id` was specified")
93+
}
8994

9095
return system
9196
}
9297

93-
if (system.specActions.getConfigByUrl && !system.specActions.getConfigByUrl(downloadSpec)) {
98+
if (!system.specActions.getConfigByUrl || system.specActions.getConfigByUrl && !system.specActions.getConfigByUrl(downloadSpec)) {
9499
return downloadSpec(config)
95100
}
96101

97-
if (system.specActions.download && config.url) {
98-
system.specActions.download(config.url)
99-
}
100-
101-
if(config.spec && typeof config.spec === "string")
102-
system.specActions.updateSpec(config.spec)
103-
104-
if(config.dom_id) {
105-
system.render(config.dom_id, "App")
106-
} else {
107-
console.error("Skipped rendering: no `dom_id` was specified")
108-
}
109-
110-
return system
111102
}
112103

113104
// Add presets

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)