Fixes #3375 - Change order of logic for selecting requestContentType to prioritize consumes_value first
This commit is contained in:
@@ -277,12 +277,13 @@ export function parametersIncludeType(parameters, typeValue="") {
|
|||||||
export function contentTypeValues(state, pathMethod) {
|
export function contentTypeValues(state, pathMethod) {
|
||||||
let op = spec(state).getIn(["paths", ...pathMethod], fromJS({}))
|
let op = spec(state).getIn(["paths", ...pathMethod], fromJS({}))
|
||||||
const parameters = op.get("parameters") || new List()
|
const parameters = op.get("parameters") || new List()
|
||||||
const requestContentType = (
|
|
||||||
parametersIncludeType(parameters, "file") ? "multipart/form-data"
|
|
||||||
: parametersIncludeIn(parameters, "formData") ? "application/x-www-form-urlencoded"
|
|
||||||
: op.get("consumes_value")
|
|
||||||
)
|
|
||||||
|
|
||||||
|
const requestContentType = (
|
||||||
|
op.get("consumes_value") ? op.get("consumes_value")
|
||||||
|
: parametersIncludeType(parameters, "file") ? "multipart/form-data"
|
||||||
|
: parametersIncludeType(parameters, "formData") ? "application/x-www-form-urlencoded"
|
||||||
|
: undefined
|
||||||
|
)
|
||||||
|
|
||||||
return fromJS({
|
return fromJS({
|
||||||
requestContentType,
|
requestContentType,
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ describe("spec plugin - selectors", function(){
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("contentTypeValues", function(){
|
describe("contentTypeValues", function(){
|
||||||
|
|
||||||
it("should return { requestContentType, responseContentType } from an operation", function(){
|
it("should return { requestContentType, responseContentType } from an operation", function(){
|
||||||
// Given
|
// Given
|
||||||
let state = fromJS({
|
let state = fromJS({
|
||||||
@@ -77,6 +76,73 @@ describe("spec plugin - selectors", function(){
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should prioritize consumes value first from an operation", function(){
|
||||||
|
// Given
|
||||||
|
let state = fromJS({
|
||||||
|
resolved: {
|
||||||
|
paths: {
|
||||||
|
"/one": {
|
||||||
|
get: {
|
||||||
|
"consumes_value": "one",
|
||||||
|
"parameters": [{
|
||||||
|
"type": "file"
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// When
|
||||||
|
let contentTypes = contentTypeValues(state, [ "/one", "get" ])
|
||||||
|
// Then
|
||||||
|
expect(contentTypes.toJS().requestContentType).toEqual("one")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should fallback to multipart/form-data if there is no consumes value but there is a file parameter", function(){
|
||||||
|
// Given
|
||||||
|
let state = fromJS({
|
||||||
|
resolved: {
|
||||||
|
paths: {
|
||||||
|
"/one": {
|
||||||
|
get: {
|
||||||
|
"parameters": [{
|
||||||
|
"type": "file"
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// When
|
||||||
|
let contentTypes = contentTypeValues(state, [ "/one", "get" ])
|
||||||
|
// Then
|
||||||
|
expect(contentTypes.toJS().requestContentType).toEqual("multipart/form-data")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should fallback to application/x-www-form-urlencoded if there is no consumes value, no file parameter, but there is a formData parameter", function(){
|
||||||
|
// Given
|
||||||
|
let state = fromJS({
|
||||||
|
resolved: {
|
||||||
|
paths: {
|
||||||
|
"/one": {
|
||||||
|
get: {
|
||||||
|
"parameters": [{
|
||||||
|
"type": "formData"
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// When
|
||||||
|
let contentTypes = contentTypeValues(state, [ "/one", "get" ])
|
||||||
|
// Then
|
||||||
|
expect(contentTypes.toJS().requestContentType).toEqual("application/x-www-form-urlencoded")
|
||||||
|
})
|
||||||
|
|
||||||
it("should be ok, if no operation found", function(){
|
it("should be ok, if no operation found", function(){
|
||||||
// Given
|
// Given
|
||||||
let state = fromJS({ })
|
let state = fromJS({ })
|
||||||
|
|||||||
Reference in New Issue
Block a user