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.
|
||||
*
|
||||
* @param schema property type
|
||||
* @return property value
|
||||
*/
|
||||
@ -1450,7 +1451,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
} else if (ModelUtils.isDoubleSchema(schema)) {
|
||||
return SchemaTypeUtil.DOUBLE_FORMAT;
|
||||
} 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)) {
|
||||
if (ModelUtils.isLongSchema(schema)) {
|
||||
@ -1891,7 +1893,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
*/
|
||||
public CodegenProperty fromProperty(String name, Schema p) {
|
||||
if (p == null) {
|
||||
LOGGER.error("Undefined property/schema for `{}`. Default to type:string.", name);
|
||||
LOGGER.error("Undefined property/schema for `{}`. Default to type:string.", name);
|
||||
return null;
|
||||
}
|
||||
LOGGER.debug("debugging fromProperty for " + name + " : " + p);
|
||||
@ -2041,7 +2043,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
if (innerSchema == null) {
|
||||
LOGGER.error("Undefined array inner type for `{}`. Default to String.", p.getName());
|
||||
innerSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to undefined type");
|
||||
((ArraySchema)p).setItems(innerSchema);
|
||||
((ArraySchema) p).setItems(innerSchema);
|
||||
}
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, ModelUtils.getAdditionalProperties(p));
|
||||
@ -2123,7 +2125,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
if (innerSchema == null) {
|
||||
LOGGER.error("Undefined array inner type for `{}`. Default to String.", p.getName());
|
||||
innerSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to undefined type");
|
||||
((ArraySchema)p).setItems(innerSchema);
|
||||
((ArraySchema) p).setItems(innerSchema);
|
||||
}
|
||||
CodegenProperty cp = fromProperty(itemName, innerSchema);
|
||||
updatePropertyForArray(property, cp);
|
||||
@ -2515,8 +2517,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
CodegenParameter bodyParam = null;
|
||||
RequestBody requestBody = operation.getRequestBody();
|
||||
if (requestBody != null) {
|
||||
if ("application/x-www-form-urlencoded".equalsIgnoreCase(getContentType(requestBody)) ||
|
||||
"multipart/form-data".equalsIgnoreCase(getContentType(requestBody))) {
|
||||
if (getContentType(requestBody).toLowerCase(Locale.ROOT).startsWith("application/x-www-form-urlencoded") ||
|
||||
getContentType(requestBody).toLowerCase(Locale.ROOT).startsWith("multipart/form-data")) {
|
||||
// process form parameters
|
||||
formParams = fromRequestBodyToFormParameters(requestBody, imports);
|
||||
for (CodegenParameter cp : formParams) {
|
||||
@ -4194,7 +4196,8 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
protected String getContentType(RequestBody requestBody) {
|
||||
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);
|
||||
}
|
||||
@ -4275,7 +4278,9 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -4849,7 +4854,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
private void setParameterNullable(CodegenParameter parameter, CodegenProperty property) {
|
||||
if(parameter == null || property == null) {
|
||||
if (parameter == null || property == null) {
|
||||
return;
|
||||
}
|
||||
parameter.isNullable = property.isNullable;
|
||||
@ -4898,7 +4903,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
/**
|
||||
* Set the boolean value indicating the state of the option for updating only changed files
|
||||
*
|
||||
* @param enableMinimalUpdate true to enable minimal update
|
||||
* @param enableMinimalUpdate true to enable minimal update
|
||||
*/
|
||||
@Override
|
||||
public void setEnableMinimalUpdate(boolean enableMinimalUpdate) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user