From 8130168c97ac78e70e3cbe0d3afc6b10679052cf Mon Sep 17 00:00:00 2001 From: Anna Bodnia Date: Fri, 7 Apr 2017 15:17:27 +0300 Subject: [PATCH] config passed with configUrl in constructor --- src/core/index.js | 24 ++++++++++++++---------- src/plugins/configs/index.js | 9 +++++---- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/core/index.js b/src/core/index.js index 214de522..61945740 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -68,22 +68,24 @@ module.exports = function SwaggerUI(opts) { var system = store.getSystem() let queryConfig = parseSeach() - const downloadSpec = () => { + const downloadSpec = (fetchedConfig) => { if(typeof constructorConfig !== "object") { return system } 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)) - if(!queryConfig.url && typeof mergedConfig.spec === "object" && Object.keys(mergedConfig.spec).length) { - system.specActions.updateUrl("") - system.specActions.updateLoadingStatus("success") - system.specActions.updateSpec(JSON.stringify(mergedConfig.spec)) - } else if(system.specActions.download && mergedConfig.url) { - system.specActions.updateUrl(mergedConfig.url) - system.specActions.download(mergedConfig.url) + if (fetchedConfig !== null) { + if (!queryConfig.url && typeof mergedConfig.spec === "object" && Object.keys(mergedConfig.spec).length) { + system.specActions.updateUrl("") + system.specActions.updateLoadingStatus("success") + system.specActions.updateSpec(JSON.stringify(mergedConfig.spec)) + } else if (system.specActions.download && mergedConfig.url) { + system.specActions.updateUrl(mergedConfig.url) + system.specActions.download(mergedConfig.url) + } } if(mergedConfig.dom_id) { @@ -95,7 +97,9 @@ module.exports = function SwaggerUI(opts) { 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() } diff --git a/src/plugins/configs/index.js b/src/plugins/configs/index.js index 51317fc6..56dd80ff 100644 --- a/src/plugins/configs/index.js +++ b/src/plugins/configs/index.js @@ -27,9 +27,7 @@ export default function configPlugin (toolbox) { return fetch(url) }, - getConfigByUrl: (callback)=> ({ specActions }) => { - let config = parseSeach() - let configUrl = config.config + getConfigByUrl: (configUrl, cb)=> ({ specActions }) => { if (configUrl) { return specActions.downloadConfig(configUrl).then(next, next) } @@ -37,9 +35,12 @@ export default function configPlugin (toolbox) { function next(res) { if (res instanceof Error || res.status >= 400) { specActions.updateLoadingStatus("failedConfig") + specActions.updateLoadingStatus("failedConfig") + specActions.updateUrl("") console.error(res.statusText + " " + configUrl) + cb(null) } else { - callback(parseYamlConfig(res.text)) + cb(parseYamlConfig(res.text)) } } }