Skip to content

Commit 00d23fb

Browse files
committed
Merge branch 'bodnia-url-from-query'
2 parents ce6ce9a + c522215 commit 00d23fb

File tree

10 files changed

+85
-88
lines changed

10 files changed

+85
-88
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: 22 additions & 31 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

@@ -35,79 +36,69 @@ module.exports = function SwaggerUI(opts) {
3536
store: { },
3637
}
3738

38-
const config = deepExtend({}, defaults, opts)
39+
const constructorConfig = deepExtend({}, defaults, opts)
3940

40-
const storeConfigs = deepExtend({}, config.store, {
41+
const storeConfigs = deepExtend({}, constructorConfig.store, {
4142
system: {
42-
configs: config.configs
43+
configs: constructorConfig.configs
4344
},
44-
plugins: config.presets,
45+
plugins: constructorConfig.presets,
4546
state: {
4647
layout: {
47-
layout: config.layout
48+
layout: constructorConfig.layout
4849
},
4950
spec: {
5051
spec: "",
51-
url: config.url
52+
url: constructorConfig.url
5253
}
5354
}
5455
})
5556

5657
let inlinePlugin = ()=> {
5758
return {
58-
fn: config.fn,
59-
components: config.components,
60-
state: config.state,
59+
fn: constructorConfig.fn,
60+
components: constructorConfig.components,
61+
state: constructorConfig.state,
6162
}
6263
}
6364

6465
var store = new System(storeConfigs)
65-
store.register([config.plugins, inlinePlugin])
66+
store.register([constructorConfig.plugins, inlinePlugin])
6667

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

6971
const downloadSpec = (configs) => {
70-
if(typeof config !== "object") {
72+
if(typeof constructorConfig !== "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({}, constructorConfig, localConfig, 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)) {
94-
return downloadSpec(config)
95-
}
96-
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")
98+
if (!system.specActions.getConfigByUrl || (system.specActions.getConfigByUrl && !system.specActions.getConfigByUrl(downloadSpec))) {
99+
return downloadSpec(constructorConfig)
108100
}
109101

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)