Support namespaces in OAS3 server state
This commit is contained in:
@@ -7,10 +7,10 @@ export const UPDATE_REQUEST_CONTENT_TYPE = "oas3_set_request_content_type"
|
|||||||
export const UPDATE_RESPONSE_CONTENT_TYPE = "oas3_set_response_content_type"
|
export const UPDATE_RESPONSE_CONTENT_TYPE = "oas3_set_response_content_type"
|
||||||
export const UPDATE_SERVER_VARIABLE_VALUE = "oas3_set_server_variable_value"
|
export const UPDATE_SERVER_VARIABLE_VALUE = "oas3_set_server_variable_value"
|
||||||
|
|
||||||
export function setSelectedServer (selectedServerUrl) {
|
export function setSelectedServer (selectedServerUrl, namespace) {
|
||||||
return {
|
return {
|
||||||
type: UPDATE_SELECTED_SERVER,
|
type: UPDATE_SELECTED_SERVER,
|
||||||
payload: selectedServerUrl
|
payload: {selectedServerUrl, namespace}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,9 +35,9 @@ export function setResponseContentType ({ value, path, method }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setServerVariableValue ({ server, key, val }) {
|
export function setServerVariableValue ({ server, namespace, key, val }) {
|
||||||
return {
|
return {
|
||||||
type: UPDATE_SERVER_VARIABLE_VALUE,
|
type: UPDATE_SERVER_VARIABLE_VALUE,
|
||||||
payload: { server, key, val }
|
payload: { server, namespace, key, val }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ import {
|
|||||||
} from "./actions"
|
} from "./actions"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
[UPDATE_SELECTED_SERVER]: (state, { payload: selectedServerUrl } ) =>{
|
[UPDATE_SELECTED_SERVER]: (state, { payload: { selectedServerUrl, namespace } } ) =>{
|
||||||
return state.setIn( [ "selectedServer" ], selectedServerUrl)
|
const path = namespace ? [ namespace, "selectedServer"] : [ "selectedServer"]
|
||||||
|
return state.setIn( path, selectedServerUrl)
|
||||||
},
|
},
|
||||||
[UPDATE_REQUEST_BODY_VALUE]: (state, { payload: { value, pathMethod } } ) =>{
|
[UPDATE_REQUEST_BODY_VALUE]: (state, { payload: { value, pathMethod } } ) =>{
|
||||||
let [path, method] = pathMethod
|
let [path, method] = pathMethod
|
||||||
@@ -21,7 +22,8 @@ export default {
|
|||||||
[UPDATE_RESPONSE_CONTENT_TYPE]: (state, { payload: { value, path, method } } ) =>{
|
[UPDATE_RESPONSE_CONTENT_TYPE]: (state, { payload: { value, path, method } } ) =>{
|
||||||
return state.setIn( [ "requestData", path, method, "responseContentType" ], value)
|
return state.setIn( [ "requestData", path, method, "responseContentType" ], value)
|
||||||
},
|
},
|
||||||
[UPDATE_SERVER_VARIABLE_VALUE]: (state, { payload: { server, key, val } } ) =>{
|
[UPDATE_SERVER_VARIABLE_VALUE]: (state, { payload: { server, namespace, key, val } } ) =>{
|
||||||
return state.setIn( [ "serverVariableValues", server, key ], val)
|
const path = namespace ? [ namespace, "serverVariableValues", server, key ] : [ "serverVariableValues", server, key ]
|
||||||
|
return state.setIn(path, val)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ function onlyOAS3(selector) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const selectedServer = onlyOAS3(state => {
|
export const selectedServer = onlyOAS3((state, namespace) => {
|
||||||
return state.getIn(["selectedServer"]) || ""
|
const path = namespace ? [namespace, "selectedServer"] : ["selectedServer"]
|
||||||
|
return state.getIn(path) || ""
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,19 +36,68 @@ export const responseContentType = onlyOAS3((state, path, method) => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
export const serverVariableValue = onlyOAS3((state, server, key) => {
|
export const serverVariableValue = onlyOAS3((state, locationData, key) => {
|
||||||
return state.getIn(["serverVariableValues", server, key]) || null
|
let path
|
||||||
|
|
||||||
|
// locationData may take one of two forms, for backwards compatibility
|
||||||
|
// Object: ({server, namespace?}) or String:(server)
|
||||||
|
if(typeof locationData !== "string") {
|
||||||
|
const { server, namespace } = locationData
|
||||||
|
if(namespace) {
|
||||||
|
path = [namespace, "serverVariableValues", server, key]
|
||||||
|
} else {
|
||||||
|
path = ["serverVariableValues", server, key]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const server = locationData
|
||||||
|
path = ["serverVariableValues", server, key]
|
||||||
|
}
|
||||||
|
|
||||||
|
return state.getIn(path) || null
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
export const serverVariables = onlyOAS3((state, server) => {
|
export const serverVariables = onlyOAS3((state, locationData) => {
|
||||||
return state.getIn(["serverVariableValues", server]) || OrderedMap()
|
let path
|
||||||
|
|
||||||
|
// locationData may take one of two forms, for backwards compatibility
|
||||||
|
// Object: ({server, namespace?}) or String:(server)
|
||||||
|
if(typeof locationData !== "string") {
|
||||||
|
const { server, namespace } = locationData
|
||||||
|
if(namespace) {
|
||||||
|
path = [namespace, "serverVariableValues", server]
|
||||||
|
} else {
|
||||||
|
path = ["serverVariableValues", server]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const server = locationData
|
||||||
|
path = ["serverVariableValues", server]
|
||||||
|
}
|
||||||
|
|
||||||
|
return state.getIn(path) || OrderedMap()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
export const serverEffectiveValue = onlyOAS3((state, server) => {
|
export const serverEffectiveValue = onlyOAS3((state, locationData) => {
|
||||||
let varValues = state.getIn(["serverVariableValues", server]) || OrderedMap()
|
var varValues, serverValue
|
||||||
let str = server
|
|
||||||
|
// locationData may take one of two forms, for backwards compatibility
|
||||||
|
// Object: ({server, namespace?}) or String:(server)
|
||||||
|
if(typeof locationData !== "string") {
|
||||||
|
const { server, namespace } = locationData
|
||||||
|
serverValue = server
|
||||||
|
if(namespace) {
|
||||||
|
varValues = state.getIn([namespace, "serverVariableValues", serverValue])
|
||||||
|
} else {
|
||||||
|
varValues = state.getIn(["serverVariableValues", serverValue])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
serverValue = locationData
|
||||||
|
varValues = state.getIn(["serverVariableValues", serverValue])
|
||||||
|
}
|
||||||
|
|
||||||
|
varValues = varValues || OrderedMap()
|
||||||
|
let str = serverValue
|
||||||
|
|
||||||
varValues.map((val, key) => {
|
varValues.map((val, key) => {
|
||||||
str = str.replace(new RegExp(`{${key}}`, "g"), val)
|
str = str.replace(new RegExp(`{${key}}`, "g"), val)
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ import {
|
|||||||
setServerVariableValue,
|
setServerVariableValue,
|
||||||
} from "corePlugins/oas3/actions"
|
} from "corePlugins/oas3/actions"
|
||||||
|
|
||||||
describe("OAS3 plugin - state", function() {
|
describe.only("OAS3 plugin - state", function() {
|
||||||
describe("action + reducer + selector integration", function() {
|
describe("action + reducer + selector integration", function() {
|
||||||
describe.only("selectedServer", function() {
|
describe("selectedServer", function() {
|
||||||
it("should set and get a global selectedServer", function() {
|
it("should set and get a global selectedServer", function() {
|
||||||
const state = new OrderedMap()
|
const state = new OrderedMap()
|
||||||
const system = {
|
const system = {
|
||||||
@@ -241,7 +241,7 @@ describe("OAS3 plugin - state", function() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
expect(globalRes.toJS()).toEqual({
|
expect(globalRes.toJS()).toEqual({
|
||||||
foo: "bar"
|
foo: "123"
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user