Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move implementation specific behavior into implementing class
Browse files Browse the repository at this point in the history
Philzen committed May 29, 2024

Verified

This commit was signed with the committer’s verified signature.
kayabaNerve Luke Parker
1 parent 3229727 commit bf33a75
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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");
@@ -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;
}
}
@@ -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:
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit bf33a75

Please sign in to comment.