Skip to content

Commit 15f680e

Browse files
jimschubertwing328
authored andcommitted
[core] Set isMultipart=true for multipart operations, fix possible NPE (#3750)
1 parent 0beb8ca commit 15f680e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,11 +2659,13 @@ public CodegenOperation fromOperation(String path,
26592659
CodegenParameter bodyParam = null;
26602660
RequestBody requestBody = operation.getRequestBody();
26612661
if (requestBody != null) {
2662-
if (getContentType(requestBody) != null &&
2663-
(getContentType(requestBody).toLowerCase(Locale.ROOT).startsWith("application/x-www-form-urlencoded") ||
2664-
getContentType(requestBody).toLowerCase(Locale.ROOT).startsWith("multipart"))) {
2662+
String contentType = getContentType(requestBody);
2663+
if (contentType != null &&
2664+
(contentType.toLowerCase(Locale.ROOT).startsWith("application/x-www-form-urlencoded") ||
2665+
contentType.toLowerCase(Locale.ROOT).startsWith("multipart"))) {
26652666
// process form parameters
26662667
formParams = fromRequestBodyToFormParameters(requestBody, imports);
2668+
op.isMultipart = contentType.toLowerCase(Locale.ROOT).startsWith("multipart");
26672669
for (CodegenParameter cp : formParams) {
26682670
postProcessParameter(cp);
26692671
}
@@ -4463,8 +4465,8 @@ public boolean hasFormParameter(OpenAPI openAPI, Operation operation) {
44634465

44644466
for (String consume : consumesInfo) {
44654467
if (consume != null &&
4466-
consume.toLowerCase(Locale.ROOT).startsWith("application/x-www-form-urlencoded") ||
4467-
consume.toLowerCase(Locale.ROOT).startsWith("multipart")) {
4468+
(consume.toLowerCase(Locale.ROOT).startsWith("application/x-www-form-urlencoded") ||
4469+
consume.toLowerCase(Locale.ROOT).startsWith("multipart"))) {
44684470
return true;
44694471
}
44704472
}

0 commit comments

Comments
 (0)