Skip to content

Commit

Permalink
Move implementation specific behavior into implementing class
Browse files Browse the repository at this point in the history
  • Loading branch information
Philzen committed May 29, 2024
1 parent fac1fa3 commit 22b3720
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4746,9 +4746,7 @@ public CodegenOperation fromOperation(String path,
if (contentType != null) {
contentType = contentType.toLowerCase(Locale.ROOT);
}
if (contentType != null &&
((!(this instanceof RustAxumServerCodegen) && contentType.startsWith("application/x-www-form-urlencoded")) ||
contentType.startsWith("multipart"))) {
if (isFormMimeType(contentType)) {
// process form parameters
formParams = fromRequestBodyToFormParameters(requestBody, imports);
op.isMultipart = contentType.startsWith("multipart");
Expand Down Expand Up @@ -7007,9 +7005,7 @@ public boolean hasFormParameter(Operation operation) {
}

for (String consume : consumesInfo) {
if (consume != null &&
(consume.toLowerCase(Locale.ROOT).startsWith("application/x-www-form-urlencoded") ||
consume.toLowerCase(Locale.ROOT).startsWith("multipart"))) {
if (isFormMimeType(consume)) {
return true;
}
}
Expand Down Expand Up @@ -8339,6 +8335,16 @@ public int hashCode() {
}
}

protected boolean isFormMimeType(String mime) {
if (mime == null) {
return false;
}

mime = mime.toLowerCase(Locale.ROOT);
return mime.startsWith("application/x-www-form-urlencoded")
|| mime.startsWith("multipart"); // ← maybe multipart/form-data would be more accurate?
}

/**
* Check if the given MIME is a JSON MIME.
* JSON MIME examples:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@ boolean isMimetypePlain(String mimetype) {
isMimetypeMultipartRelated(mimetype));
}

@Override protected boolean isFormMimeType(String mime) {
return mime != null
&& mime.toLowerCase(Locale.ROOT).startsWith("multipart"); // ← maybe multipart/form-data would be more accurate?
}

@Override
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
Expand Down

0 comments on commit 22b3720

Please sign in to comment.