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:
kyle
2018-11-23 23:24:11 +01:00
committed by GitHub
parent 2977c93840
commit 971c6f7536
7 changed files with 400 additions and 39 deletions

View File

@@ -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 }

View File

@@ -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}

View File

@@ -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+\-.]*):/)