Merge pull request #2877 from bodnia/config-with-url

config passed with configUrl in constructor
This commit is contained in:
Anna
2017-04-07 16:04:05 +03:00
committed by GitHub
2 changed files with 19 additions and 15 deletions

View File

@@ -68,15 +68,16 @@ 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 (fetchedConfig !== null) {
if (!queryConfig.url && typeof mergedConfig.spec === "object" && Object.keys(mergedConfig.spec).length) {
system.specActions.updateUrl("")
system.specActions.updateLoadingStatus("success")
@@ -85,6 +86,7 @@ module.exports = function SwaggerUI(opts) {
system.specActions.updateUrl(mergedConfig.url)
system.specActions.download(mergedConfig.url)
}
}
if(mergedConfig.dom_id) {
system.render(mergedConfig.dom_id, "App")
@@ -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()
}

View File

@@ -1,5 +1,4 @@
import YAML from "js-yaml"
import { parseSeach } from "core/utils"
import yamlConfig from "../../../swagger-config.yaml"
const CONFIGS = [ "url", "spec", "validatorUrl", "onComplete", "onFailure", "authorizations", "docExpansion",
@@ -27,9 +26,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 +34,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))
}
}
}