Skip to content

Commit eb4c814

Browse files
fairkingManweill
authored andcommitted
Prefer Json over other content types
1 parent 73447c8 commit eb4c814

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/requestCodegen/getContentType.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,28 @@ import { IRequestMethod } from '../swaggerInterfaces'
22

33
export function getContentType(reqProps: IRequestMethod, isV3: boolean) {
44
if (isV3) {
5+
// Prefer Json over other content types
6+
if (reqProps?.requestBody?.content['application/json']) {
7+
return 'application/json'
8+
}
59
if (reqProps?.requestBody?.content['multipart/form-data']) {
610
return 'multipart/form-data'
7-
} else if (reqProps?.requestBody?.content['application/x-www-form-urlencoded']) {
11+
}
12+
if (reqProps?.requestBody?.content['application/x-www-form-urlencoded']) {
813
return 'application/x-www-form-urlencoded'
9-
} else {
14+
}
15+
return 'application/json'
16+
} else {
17+
// Prefer Json over other content types
18+
if (reqProps?.consumes?.includes('application/json')) {
1019
return 'application/json'
1120
}
21+
if (reqProps?.consumes?.includes('multipart/form-data')) {
22+
return 'multipart/form-data'
23+
}
24+
if (reqProps?.consumes?.includes('application/x-www-form-urlencoded')) {
25+
return 'application/x-www-form-urlencoded'
26+
}
27+
return 'application/json'
1228
}
13-
14-
return reqProps.consumes && reqProps.consumes.includes('multipart/form-data')
15-
? 'multipart/form-data'
16-
: 'application/json'
1729
}

0 commit comments

Comments
 (0)