Merge branch 'url-from-query' of https://github.com/bodnia/swagger-ui into bodnia-url-from-query

This commit is contained in:
Kyle Shockey
2017-03-19 18:07:21 -07:00
10 changed files with 73 additions and 76 deletions

View File

@@ -4,6 +4,7 @@ import System from "core/system"
import ApisPreset from "core/presets/apis"
import * as AllPlugins from "core/plugins/all"
import { filterConfigs } from "plugins/configs"
import { parseSeach } from "core/utils"
module.exports = function SwaggerUI(opts) {
@@ -65,6 +66,7 @@ module.exports = function SwaggerUI(opts) {
store.register([config.plugins, inlinePlugin])
var system = store.getSystem()
let queryConfig = parseSeach()
const downloadSpec = (configs) => {
if(typeof config !== "object") {
@@ -72,42 +74,31 @@ module.exports = function SwaggerUI(opts) {
}
let localConfig = system.specSelectors.getLocalConfig ? system.specSelectors.getLocalConfig() : {}
let mergedConfig = deepExtend({}, config, configs, localConfig)
let mergedConfig = deepExtend({}, config, localConfig, configs, queryConfig)
store.setConfigs(filterConfigs(mergedConfig))
if(typeof mergedConfig.spec === "object" && Object.keys(mergedConfig.spec).length) {
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(mergedConfig.url) {
} else if(system.specActions.download && mergedConfig.url) {
system.specActions.updateUrl(mergedConfig.url)
system.specActions.download(mergedConfig.url)
}
if(mergedConfig.dom_id)
if(mergedConfig.dom_id) {
system.render(mergedConfig.dom_id, "App")
} else {
console.error("Skipped rendering: no `dom_id` was specified")
}
return system
}
if (system.specActions.getConfigByUrl && !system.specActions.getConfigByUrl(downloadSpec)) {
if (!system.specActions.getConfigByUrl || system.specActions.getConfigByUrl && !system.specActions.getConfigByUrl(downloadSpec)) {
return downloadSpec(config)
}
if (system.specActions.download && config.url) {
system.specActions.download(config.url)
}
if(config.spec && typeof config.spec === "string")
system.specActions.updateSpec(config.spec)
if(config.dom_id) {
system.render(config.dom_id, "App")
} else {
console.error("Skipped rendering: no `dom_id` was specified")
}
return system
}
// Add presets

View File

@@ -30,7 +30,7 @@ export default function downloadUrlPlugin (toolbox) {
},
updateLoadingStatus: (status) => {
let enums = [null, "loading", "failed", "success"]
let enums = [null, "loading", "failed", "success", "failedConfig"]
if(enums.indexOf(status) === -1) {
console.error(`Error: ${status} is not one of ${JSON.stringify(enums)}`)
}

View File

@@ -549,3 +549,19 @@ export const getSampleSchema = (schema, contentType="", config={}) => {
return JSON.stringify(memoizedSampleFromSchema(schema, config), null, 2)
}
export const parseSeach = () => {
let map = {}
let search = window.location.search
if ( search != "" ) {
let params = search.substr(1).split("&");
for (let i in params) {
i = params[i].split("=");
map[decodeURIComponent(i[0])] = decodeURIComponent(i[1]);
}
}
return map;
}