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)) {
|
||||||
@ -1891,7 +1893,7 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
*/
|
*/
|
||||||
public CodegenProperty fromProperty(String name, Schema p) {
|
public CodegenProperty fromProperty(String name, Schema p) {
|
||||||
if (p == null) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
LOGGER.debug("debugging fromProperty for " + name + " : " + p);
|
LOGGER.debug("debugging fromProperty for " + name + " : " + p);
|
||||||
@ -2041,7 +2043,7 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
if (innerSchema == null) {
|
if (innerSchema == null) {
|
||||||
LOGGER.error("Undefined array inner type for `{}`. Default to String.", p.getName());
|
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");
|
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)) {
|
} else if (ModelUtils.isMapSchema(p)) {
|
||||||
Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, ModelUtils.getAdditionalProperties(p));
|
Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, ModelUtils.getAdditionalProperties(p));
|
||||||
@ -2123,7 +2125,7 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
if (innerSchema == null) {
|
if (innerSchema == null) {
|
||||||
LOGGER.error("Undefined array inner type for `{}`. Default to String.", p.getName());
|
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");
|
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);
|
CodegenProperty cp = fromProperty(itemName, innerSchema);
|
||||||
updatePropertyForArray(property, cp);
|
updatePropertyForArray(property, cp);
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4849,7 +4854,7 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setParameterNullable(CodegenParameter parameter, CodegenProperty property) {
|
private void setParameterNullable(CodegenParameter parameter, CodegenProperty property) {
|
||||||
if(parameter == null || property == null) {
|
if (parameter == null || property == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
parameter.isNullable = property.isNullable;
|
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
|
* 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
|
@Override
|
||||||
public void setEnableMinimalUpdate(boolean enableMinimalUpdate) {
|
public void setEnableMinimalUpdate(boolean enableMinimalUpdate) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user