fix: Try-It-Out Consumes value regression (#4265)

* Migrate behavior of `operationConsumes` selector

* Improve accuracy of resolved subtree merger

* Check for Immutable Map _before_ using `get` method
This commit is contained in:
kyle
2018-02-27 18:55:59 -08:00
committed by GitHub
parent e6722d87aa
commit 1fb56c6f96
2 changed files with 109 additions and 3 deletions

View File

@@ -46,9 +46,31 @@ export const specResolvedSubtree = (state, path) => {
return state.getIn(["resolvedSubtrees", ...path], undefined)
}
const mergerFn = (oldVal, newVal) => {
if(Map.isMap(oldVal) && Map.isMap(newVal)) {
if(newVal.get("$$ref")) {
// resolver artifacts indicated that this key was directly resolved
// so we should drop the old value entirely
return newVal
}
return Map().mergeWith(
mergerFn,
oldVal,
newVal
)
}
return newVal
}
export const specJsonWithResolvedSubtrees = createSelector(
state,
spec => Map().merge(spec.get("json"), spec.get("resolvedSubtrees"))
spec => Map().mergeWith(
mergerFn,
spec.get("json"),
spec.get("resolvedSubtrees")
)
)
// Default Spec ( as an object )
@@ -369,7 +391,7 @@ export function contentTypeValues(state, pathMethod) {
// Get the consumes/produces by path
export function operationConsumes(state, pathMethod) {
pathMethod = pathMethod || []
return state.getIn(["meta", ...pathMethod, "consumes"], fromJS({}))
return specJsonWithResolvedSubtrees(state).getIn(["paths", ...pathMethod, "consumes"], fromJS({}))
}
// Get the currently selected produces value for an operation