Improvement: Hash-keyed Try-It-Out parameter value storage (#4670)
* allow param update by identity + hashed value storage * add specActions.changeParamByIdentity * add identity-based lookup support in spec selectors * migrate `changeParam` usage to `changeParamByIdentity` * migrate usage of `parameterWithMeta` to `parameterWithMetaByIdentity` * update invocations of `changeParamByIdentity` to match fn signature * use OrderedMap throughout hash-based selectors for consistency * normalize usage of ParameterRow `onChange` * migrate bug 4557 tests to reflect new ParameterRow interface * remove exclusive test blocks * linter fixes * copy Parameters changes into OAS3 wrapper * use rawParam for meta lookups in ParameterRow
This commit is contained in:
@@ -234,6 +234,13 @@ export function changeParam( path, paramName, paramIn, value, isXml ){
|
||||
}
|
||||
}
|
||||
|
||||
export function changeParamByIdentity( pathMethod, param, value, isXml ){
|
||||
return {
|
||||
type: UPDATE_PARAM,
|
||||
payload:{ path: pathMethod, param, value, isXml }
|
||||
}
|
||||
}
|
||||
|
||||
export const updateResolvedSubtree = (path, value) => {
|
||||
return {
|
||||
type: UPDATE_RESOLVED_SUBTREE,
|
||||
|
||||
@@ -51,12 +51,21 @@ export default {
|
||||
},
|
||||
|
||||
[UPDATE_PARAM]: ( state, {payload} ) => {
|
||||
let { path: pathMethod, paramName, paramIn, value, isXml } = payload
|
||||
let { path: pathMethod, paramName, paramIn, param, value, isXml } = payload
|
||||
|
||||
let paramKey
|
||||
|
||||
// `hashCode` is an Immutable.js Map method
|
||||
if(param && param.hashCode && !paramIn && !paramName) {
|
||||
paramKey = `${param.get("name")}.${param.get("in")}.hash-${param.hashCode()}`
|
||||
} else {
|
||||
paramKey = `${paramName}.${paramIn}`
|
||||
}
|
||||
|
||||
const valueKey = isXml ? "value_xml" : "value"
|
||||
|
||||
return state.setIn(
|
||||
["meta", "paths", ...pathMethod, "parameters", `${paramName}.${paramIn}`, valueKey],
|
||||
["meta", "paths", ...pathMethod, "parameters", paramKey, valueKey],
|
||||
value
|
||||
)
|
||||
},
|
||||
|
||||
@@ -294,34 +294,42 @@ export const allowTryItOutFor = () => {
|
||||
return true
|
||||
}
|
||||
|
||||
export const operationWithMeta = (state, path, method) => {
|
||||
const op = specJsonWithResolvedSubtrees(state).getIn(["paths", path, method], Map())
|
||||
const meta = state.getIn(["meta", "paths", path, method], Map())
|
||||
export const parameterWithMetaByIdentity = (state, pathMethod, param) => {
|
||||
const opParams = specJsonWithResolvedSubtrees(state).getIn(["paths", ...pathMethod, "parameters"], OrderedMap())
|
||||
const metaParams = state.getIn(["meta", "paths", ...pathMethod, "parameters"], OrderedMap())
|
||||
|
||||
const mergedParams = op.get("parameters", List()).map((param) => {
|
||||
return Map().merge(
|
||||
param,
|
||||
meta.getIn(["parameters", `${param.get("name")}.${param.get("in")}`])
|
||||
const mergedParams = opParams.map((currentParam) => {
|
||||
const nameInKeyedMeta = metaParams.get(`${param.get("name")}.${param.get("in")}`)
|
||||
const hashKeyedMeta = metaParams.get(`${param.get("name")}.${param.get("in")}.hash-${param.hashCode()}`)
|
||||
return OrderedMap().merge(
|
||||
currentParam,
|
||||
nameInKeyedMeta,
|
||||
hashKeyedMeta
|
||||
)
|
||||
})
|
||||
|
||||
return Map()
|
||||
.merge(op, meta)
|
||||
.set("parameters", mergedParams)
|
||||
return mergedParams.find(curr => curr.get("in") === param.get("in") && curr.get("name") === param.get("name"), OrderedMap())
|
||||
}
|
||||
|
||||
export const parameterWithMeta = (state, pathMethod, paramName, paramIn) => {
|
||||
const opParams = specJsonWithResolvedSubtrees(state).getIn(["paths", ...pathMethod, "parameters"], Map())
|
||||
const metaParams = state.getIn(["meta", "paths", ...pathMethod, "parameters"], Map())
|
||||
|
||||
const mergedParams = opParams.map((param) => {
|
||||
return Map().merge(
|
||||
param,
|
||||
metaParams.get(`${param.get("name")}.${param.get("in")}`)
|
||||
)
|
||||
export const parameterWithMeta = (state, pathMethod, paramName, paramIn) => {
|
||||
const opParams = specJsonWithResolvedSubtrees(state).getIn(["paths", ...pathMethod, "parameters"], OrderedMap())
|
||||
const currentParam = opParams.find(param => param.get("in") === paramIn && param.get("name") === paramName, OrderedMap())
|
||||
|
||||
return parameterWithMetaByIdentity(state, pathMethod, currentParam)
|
||||
}
|
||||
|
||||
export const operationWithMeta = (state, path, method) => {
|
||||
const op = specJsonWithResolvedSubtrees(state).getIn(["paths", path, method], OrderedMap())
|
||||
const meta = state.getIn(["meta", "paths", path, method], OrderedMap())
|
||||
|
||||
const mergedParams = op.get("parameters", List()).map((param) => {
|
||||
return parameterWithMetaByIdentity(state, [path, method], param)
|
||||
})
|
||||
|
||||
return mergedParams.find(param => param.get("in") === paramIn && param.get("name") === paramName, Map())
|
||||
return OrderedMap()
|
||||
.merge(op, meta)
|
||||
.set("parameters", mergedParams)
|
||||
}
|
||||
|
||||
// Get the parameter value by parameter name
|
||||
|
||||
Reference in New Issue
Block a user