fix: path-item $ref produces/consumes inheritance (via #5049)
* implement a selector for consumes options * fix incorrect comment, test names * add `consumesOptionsFor` selector * use `consumesOptionsFor` and drop `operationConsumes`
This commit is contained in:
@@ -401,12 +401,6 @@ export function contentTypeValues(state, pathMethod) {
|
||||
})
|
||||
}
|
||||
|
||||
// Get the consumes/produces by path
|
||||
export function operationConsumes(state, pathMethod) {
|
||||
pathMethod = pathMethod || []
|
||||
return specJsonWithResolvedSubtrees(state).getIn(["paths", ...pathMethod, "consumes"], fromJS({}))
|
||||
}
|
||||
|
||||
// Get the currently selected produces value for an operation
|
||||
export function currentProducesFor(state, pathMethod) {
|
||||
pathMethod = pathMethod || []
|
||||
@@ -425,6 +419,48 @@ export function currentProducesFor(state, pathMethod) {
|
||||
|
||||
}
|
||||
|
||||
// Get the produces options for an operation
|
||||
export function producesOptionsFor(state, pathMethod) {
|
||||
pathMethod = pathMethod || []
|
||||
|
||||
const spec = specJsonWithResolvedSubtrees(state)
|
||||
const operation = spec.getIn([ "paths", ...pathMethod], null)
|
||||
|
||||
if(operation === null) {
|
||||
// return nothing if the operation does not exist
|
||||
return
|
||||
}
|
||||
|
||||
const [path] = pathMethod
|
||||
|
||||
const operationProduces = operation.get("produces", null)
|
||||
const pathItemProduces = spec.getIn(["paths", path, "produces"], null)
|
||||
const globalProduces = spec.getIn(["produces"], null)
|
||||
|
||||
return operationProduces || pathItemProduces || globalProduces
|
||||
}
|
||||
|
||||
// Get the consumes options for an operation
|
||||
export function consumesOptionsFor(state, pathMethod) {
|
||||
pathMethod = pathMethod || []
|
||||
|
||||
const spec = specJsonWithResolvedSubtrees(state)
|
||||
const operation = spec.getIn(["paths", ...pathMethod], null)
|
||||
|
||||
if (operation === null) {
|
||||
// return nothing if the operation does not exist
|
||||
return
|
||||
}
|
||||
|
||||
const [path] = pathMethod
|
||||
|
||||
const operationConsumes = operation.get("consumes", null)
|
||||
const pathItemConsumes = spec.getIn(["paths", path, "consumes"], null)
|
||||
const globalConsumes = spec.getIn(["consumes"], null)
|
||||
|
||||
return operationConsumes || pathItemConsumes || globalConsumes
|
||||
}
|
||||
|
||||
export const operationScheme = ( state, path, method ) => {
|
||||
let url = state.get("url")
|
||||
let matchResult = url.match(/^([a-z][a-z0-9+\-.]*):/)
|
||||
|
||||
Reference in New Issue
Block a user