fetch spec from url provided in query parameter
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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)}`)
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user