fetch spec from url provided in query parameter

This commit is contained in:
Anna Bodnia
2017-03-19 13:28:10 +02:00
parent 5c77857b2d
commit 26d5305404
6 changed files with 30 additions and 24 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) {
@@ -73,9 +74,13 @@ module.exports = function SwaggerUI(opts) {
let localConfig = system.specSelectors.getLocalConfig ? system.specSelectors.getLocalConfig() : {}
let mergedConfig = deepExtend({}, config, configs, localConfig)
let search = parseSeach()
if (search.url) {
mergedConfig.url = search.url
}
store.setConfigs(filterConfigs(mergedConfig))
if(typeof mergedConfig.spec === "object" && Object.keys(mergedConfig.spec).length) {
if(!search.url && typeof mergedConfig.spec === "object" && Object.keys(mergedConfig.spec).length) {
system.specActions.updateUrl("")
system.specActions.updateLoadingStatus("success");
system.specActions.updateSpec(JSON.stringify(mergedConfig.spec))

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;
}

View File

@@ -1,4 +1,5 @@
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",
@@ -16,22 +17,6 @@ const parseYamlConfig = (yaml, system) => {
}
}
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;
}
export default function configPlugin (toolbox) {
let { fn } = toolbox