Merge branch 'master' into target-blankv2
This commit is contained in:
@@ -7,7 +7,7 @@ export default class OnlineValidatorBadge extends React.Component {
|
||||
let { validatorUrl } = getConfigs()
|
||||
this.state = {
|
||||
url: specSelectors.url(),
|
||||
validatorUrl: validatorUrl
|
||||
validatorUrl: validatorUrl || "https://online.swagger.io/validator"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ export default class OnlineValidatorBadge extends React.Component {
|
||||
|
||||
this.setState({
|
||||
url: specSelectors.url(),
|
||||
validatorUrl: validatorUrl
|
||||
validatorUrl: validatorUrl || "https://online.swagger.io/validator"
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -59,12 +59,6 @@ export default class Operations extends React.Component {
|
||||
</small>
|
||||
}
|
||||
|
||||
<button className="expand-methods" title="Expand all methods">
|
||||
<svg className="expand" width="20" height="20">
|
||||
<use xlinkHref="#expand" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<button className="expand-operation" title="Expand operation" onClick={() => layoutActions.show(isShownKey, !showTag)}>
|
||||
<svg className="arrow" width="20" height="20">
|
||||
<use xlinkHref={showTag ? "#large-arrow-down" : "#large-arrow"} />
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -35,79 +36,69 @@ module.exports = function SwaggerUI(opts) {
|
||||
store: { },
|
||||
}
|
||||
|
||||
const config = deepExtend({}, defaults, opts)
|
||||
const constructorConfig = deepExtend({}, defaults, opts)
|
||||
|
||||
const storeConfigs = deepExtend({}, config.store, {
|
||||
const storeConfigs = deepExtend({}, constructorConfig.store, {
|
||||
system: {
|
||||
configs: config.configs
|
||||
configs: constructorConfig.configs
|
||||
},
|
||||
plugins: config.presets,
|
||||
plugins: constructorConfig.presets,
|
||||
state: {
|
||||
layout: {
|
||||
layout: config.layout
|
||||
layout: constructorConfig.layout
|
||||
},
|
||||
spec: {
|
||||
spec: "",
|
||||
url: config.url
|
||||
url: constructorConfig.url
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
let inlinePlugin = ()=> {
|
||||
return {
|
||||
fn: config.fn,
|
||||
components: config.components,
|
||||
state: config.state,
|
||||
fn: constructorConfig.fn,
|
||||
components: constructorConfig.components,
|
||||
state: constructorConfig.state,
|
||||
}
|
||||
}
|
||||
|
||||
var store = new System(storeConfigs)
|
||||
store.register([config.plugins, inlinePlugin])
|
||||
store.register([constructorConfig.plugins, inlinePlugin])
|
||||
|
||||
var system = store.getSystem()
|
||||
let queryConfig = parseSeach()
|
||||
|
||||
const downloadSpec = (configs) => {
|
||||
if(typeof config !== "object") {
|
||||
if(typeof constructorConfig !== "object") {
|
||||
return system
|
||||
}
|
||||
|
||||
let localConfig = system.specSelectors.getLocalConfig ? system.specSelectors.getLocalConfig() : {}
|
||||
let mergedConfig = deepExtend({}, config, configs, localConfig)
|
||||
let mergedConfig = deepExtend({}, constructorConfig, localConfig, 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)) {
|
||||
return downloadSpec(config)
|
||||
if (!system.specActions.getConfigByUrl || (system.specActions.getConfigByUrl && !system.specActions.getConfigByUrl(downloadSpec))) {
|
||||
return downloadSpec(constructorConfig)
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -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