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:
@@ -83,7 +83,6 @@ export default class Operation extends PureComponent {
|
||||
|
||||
let operation = operationProps.getIn(["op"])
|
||||
let responses = operation.get("responses")
|
||||
let produces = operation.get("produces")
|
||||
let parameters = getList(operation, ["parameters"])
|
||||
let operationScheme = specSelectors.operationScheme(path, method)
|
||||
let isShownKey = ["operations", tag, operationId]
|
||||
@@ -216,7 +215,7 @@ export default class Operation extends PureComponent {
|
||||
specSelectors={ specSelectors }
|
||||
oas3Actions={oas3Actions}
|
||||
specActions={ specActions }
|
||||
produces={ produces }
|
||||
produces={specSelectors.producesOptionsFor([path, method]) }
|
||||
producesValue={ specSelectors.currentProducesFor([path, method]) }
|
||||
specPath={specPath.push("responses")}
|
||||
path={ path }
|
||||
|
||||
@@ -129,7 +129,7 @@ export default class ParameterRow extends Component {
|
||||
: <ParamBody getComponent={getComponent}
|
||||
fn={fn}
|
||||
param={param}
|
||||
consumes={ specSelectors.operationConsumes(pathMethod) }
|
||||
consumes={ specSelectors.consumesOptionsFor(pathMethod) }
|
||||
consumesValue={ specSelectors.contentTypeValues(pathMethod).get("requestContentType") }
|
||||
onChange={this.onChangeWrapper}
|
||||
onChangeConsumes={onChangeConsumes}
|
||||
|
||||
@@ -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