Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Json spec overwrite attribute after fetch spec from URLs #9614

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dev-helpers/dev-helper-initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ window.onload = function() {
window["SwaggerUIStandalonePreset"] = window["swagger-ui-standalone-preset"]
// Build a system
const ui = SwaggerUIBundle({
url: "https://petstore.swagger.io/v2/swagger.json",
urls: [
{url:"https://petstore3.swagger.io/api/v3/openapi.json",name:"Pet Store Example",specOverwrite: {servers:[{ "url": "http://test.com" },{ "url": "http://real.org" }]}},
],
dom_id: "#swagger-ui",
presets: [
SwaggerUIBundle.presets.apis,
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/live-response.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class LiveResponse extends React.Component {
render() {
const { response, getComponent, getConfigs, displayRequestDuration, specSelectors, path, method } = this.props
const { showMutatedRequest, requestSnippetsEnabled } = getConfigs()

const curlRequest = showMutatedRequest ? specSelectors.mutatedRequestFor(path, method) : specSelectors.requestFor(path, method)
const status = response.get("status")
const url = curlRequest.get("url")
Expand Down
4 changes: 2 additions & 2 deletions src/core/plugins/download-url/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function downloadUrlPlugin(toolbox) {

const actions = {
download:
(url) =>
(url, specOverwrite = null) =>
({ errActions, specSelectors, specActions, getConfigs }) => {
let { fetch } = fn
const config = getConfigs()
Expand Down Expand Up @@ -42,7 +42,7 @@ export default function downloadUrlPlugin(toolbox) {
return
}
specActions.updateLoadingStatus("success")
specActions.updateSpec(res.text)
specActions.updateSpec(res.text, specOverwrite)
if (specSelectors.url() !== url) {
specActions.updateUrl(url)
}
Expand Down
9 changes: 7 additions & 2 deletions src/core/plugins/spec/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function updateJsonSpec(json) {
return {type: UPDATE_JSON, payload: json}
}

export const parseToJson = (str) => ({specActions, specSelectors, errActions}) => {
export const parseToJson = (str, specOverwrite = null) => ({specActions, specSelectors, errActions}) => {
let { specStr } = specSelectors

let json = null
Expand All @@ -76,7 +76,12 @@ export const parseToJson = (str) => ({specActions, specSelectors, errActions}) =
})
}
if(json && typeof json === "object") {
return specActions.updateJsonSpec(json)
let merged = {}
if (specOverwrite) {
console.log(specOverwrite)
Object.assign(merged, json, specOverwrite);
}
return specActions.updateJsonSpec(merged)
}
return {}
}
Expand Down
6 changes: 3 additions & 3 deletions src/standalone/plugins/top-bar/components/TopBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class TopBar extends React.Component {
})
}

loadSpec = (url) => {
loadSpec = (url, specOverwrite = null) => {
this.flushAuthData()
this.props.specActions.updateUrl(url)
this.props.specActions.download(url)
this.props.specActions.download(url, specOverwrite)
}

onUrlSelect =(e)=> {
Expand Down Expand Up @@ -99,7 +99,7 @@ class TopBar extends React.Component {
})
}

this.loadSpec(urls[targetIndex].url)
this.loadSpec(urls[targetIndex].url, urls[targetIndex].specOverwrite)
}
}

Expand Down