forked from loafle/openapi-generator-original
Better handling of form data (#2818)
* better warning message, better handling of form payload * fix form data detection * better format
This commit is contained in:
parent
250e5284cd
commit
9c89e6af25
@ -1286,6 +1286,7 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return property value depending on property type.
|
* Return property value depending on property type.
|
||||||
|
*
|
||||||
* @param schema property type
|
* @param schema property type
|
||||||
* @return property value
|
* @return property value
|
||||||
*/
|
*/
|
||||||
@ -1450,7 +1451,8 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
} else if (ModelUtils.isDoubleSchema(schema)) {
|
} else if (ModelUtils.isDoubleSchema(schema)) {
|
||||||
return SchemaTypeUtil.DOUBLE_FORMAT;
|
return SchemaTypeUtil.DOUBLE_FORMAT;
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warn("Unknown `format` detected for " + schema.getName() + ": " + schema.getFormat());
|
LOGGER.warn("Unknown `format` {} detected for type `number`. Defaulting to `number`", schema.getFormat());
|
||||||
|
return "number";
|
||||||
}
|
}
|
||||||
} else if (ModelUtils.isIntegerSchema(schema)) {
|
} else if (ModelUtils.isIntegerSchema(schema)) {
|
||||||
if (ModelUtils.isLongSchema(schema)) {
|
if (ModelUtils.isLongSchema(schema)) {
|
||||||
@ -2515,8 +2517,8 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
CodegenParameter bodyParam = null;
|
CodegenParameter bodyParam = null;
|
||||||
RequestBody requestBody = operation.getRequestBody();
|
RequestBody requestBody = operation.getRequestBody();
|
||||||
if (requestBody != null) {
|
if (requestBody != null) {
|
||||||
if ("application/x-www-form-urlencoded".equalsIgnoreCase(getContentType(requestBody)) ||
|
if (getContentType(requestBody).toLowerCase(Locale.ROOT).startsWith("application/x-www-form-urlencoded") ||
|
||||||
"multipart/form-data".equalsIgnoreCase(getContentType(requestBody))) {
|
getContentType(requestBody).toLowerCase(Locale.ROOT).startsWith("multipart/form-data")) {
|
||||||
// process form parameters
|
// process form parameters
|
||||||
formParams = fromRequestBodyToFormParameters(requestBody, imports);
|
formParams = fromRequestBodyToFormParameters(requestBody, imports);
|
||||||
for (CodegenParameter cp : formParams) {
|
for (CodegenParameter cp : formParams) {
|
||||||
@ -4194,7 +4196,8 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
protected String getContentType(RequestBody requestBody) {
|
protected String getContentType(RequestBody requestBody) {
|
||||||
if (requestBody == null || requestBody.getContent() == null || requestBody.getContent().isEmpty()) {
|
if (requestBody == null || requestBody.getContent() == null || requestBody.getContent().isEmpty()) {
|
||||||
return null;
|
LOGGER.warn("Cannot determine the content type. Default to UNKNOWN_CONTENT_TYPE.");
|
||||||
|
return "UNKNOWN_CONTENT_TYPE";
|
||||||
}
|
}
|
||||||
return new ArrayList<>(requestBody.getContent().keySet()).get(0);
|
return new ArrayList<>(requestBody.getContent().keySet()).get(0);
|
||||||
}
|
}
|
||||||
@ -4275,7 +4278,9 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (String consume : consumesInfo) {
|
for (String consume : consumesInfo) {
|
||||||
if ("application/x-www-form-urlencoded".equalsIgnoreCase(consume) || "multipart/form-data".equalsIgnoreCase(consume)) {
|
if (consume != null &&
|
||||||
|
consume.toLowerCase(Locale.ROOT).startsWith("application/x-www-form-urlencoded") ||
|
||||||
|
consume.toLowerCase(Locale.ROOT).startsWith("multipart/form-data")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user