config passed with configUrl in constructor
This commit is contained in:
@@ -68,23 +68,25 @@ module.exports = function SwaggerUI(opts) {
|
|||||||
var system = store.getSystem()
|
var system = store.getSystem()
|
||||||
let queryConfig = parseSeach()
|
let queryConfig = parseSeach()
|
||||||
|
|
||||||
const downloadSpec = () => {
|
const downloadSpec = (fetchedConfig) => {
|
||||||
if(typeof constructorConfig !== "object") {
|
if(typeof constructorConfig !== "object") {
|
||||||
return system
|
return system
|
||||||
}
|
}
|
||||||
|
|
||||||
let localConfig = system.specSelectors.getLocalConfig ? system.specSelectors.getLocalConfig() : {}
|
let localConfig = system.specSelectors.getLocalConfig ? system.specSelectors.getLocalConfig() : {}
|
||||||
let mergedConfig = deepExtend({}, constructorConfig, localConfig, queryConfig)
|
let mergedConfig = deepExtend({}, constructorConfig, localConfig, fetchedConfig || {}, queryConfig)
|
||||||
store.setConfigs(filterConfigs(mergedConfig))
|
store.setConfigs(filterConfigs(mergedConfig))
|
||||||
|
|
||||||
if(!queryConfig.url && typeof mergedConfig.spec === "object" && Object.keys(mergedConfig.spec).length) {
|
if (fetchedConfig !== null) {
|
||||||
|
if (!queryConfig.url && typeof mergedConfig.spec === "object" && Object.keys(mergedConfig.spec).length) {
|
||||||
system.specActions.updateUrl("")
|
system.specActions.updateUrl("")
|
||||||
system.specActions.updateLoadingStatus("success")
|
system.specActions.updateLoadingStatus("success")
|
||||||
system.specActions.updateSpec(JSON.stringify(mergedConfig.spec))
|
system.specActions.updateSpec(JSON.stringify(mergedConfig.spec))
|
||||||
} else if(system.specActions.download && mergedConfig.url) {
|
} else if (system.specActions.download && mergedConfig.url) {
|
||||||
system.specActions.updateUrl(mergedConfig.url)
|
system.specActions.updateUrl(mergedConfig.url)
|
||||||
system.specActions.download(mergedConfig.url)
|
system.specActions.download(mergedConfig.url)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(mergedConfig.dom_id) {
|
if(mergedConfig.dom_id) {
|
||||||
system.render(mergedConfig.dom_id, "App")
|
system.render(mergedConfig.dom_id, "App")
|
||||||
@@ -95,7 +97,9 @@ module.exports = function SwaggerUI(opts) {
|
|||||||
return system
|
return system
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!system.specActions.getConfigByUrl || (system.specActions.getConfigByUrl && !system.specActions.getConfigByUrl(downloadSpec))) {
|
let configUrl = queryConfig.config || constructorConfig.configUrl
|
||||||
|
|
||||||
|
if (!configUrl || !system.specActions.getConfigByUrl || system.specActions.getConfigByUrl && !system.specActions.getConfigByUrl(configUrl, downloadSpec)) {
|
||||||
return downloadSpec()
|
return downloadSpec()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,7 @@ export default function configPlugin (toolbox) {
|
|||||||
return fetch(url)
|
return fetch(url)
|
||||||
},
|
},
|
||||||
|
|
||||||
getConfigByUrl: (callback)=> ({ specActions }) => {
|
getConfigByUrl: (configUrl, cb)=> ({ specActions }) => {
|
||||||
let config = parseSeach()
|
|
||||||
let configUrl = config.config
|
|
||||||
if (configUrl) {
|
if (configUrl) {
|
||||||
return specActions.downloadConfig(configUrl).then(next, next)
|
return specActions.downloadConfig(configUrl).then(next, next)
|
||||||
}
|
}
|
||||||
@@ -37,9 +35,12 @@ export default function configPlugin (toolbox) {
|
|||||||
function next(res) {
|
function next(res) {
|
||||||
if (res instanceof Error || res.status >= 400) {
|
if (res instanceof Error || res.status >= 400) {
|
||||||
specActions.updateLoadingStatus("failedConfig")
|
specActions.updateLoadingStatus("failedConfig")
|
||||||
|
specActions.updateLoadingStatus("failedConfig")
|
||||||
|
specActions.updateUrl("")
|
||||||
console.error(res.statusText + " " + configUrl)
|
console.error(res.statusText + " " + configUrl)
|
||||||
|
cb(null)
|
||||||
} else {
|
} else {
|
||||||
callback(parseYamlConfig(res.text))
|
cb(parseYamlConfig(res.text))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user