Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,7 @@ public String toDefaultValue(Schema schema) {

/**
* Return property value depending on property type.
*
* @param schema property type
* @return property value
*/
Expand Down Expand Up @@ -1450,7 +1451,8 @@ private static String getPrimitiveType(Schema schema) {
} 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)) {
Expand Down Expand Up @@ -1891,7 +1893,7 @@ public String getterAndSetterCapitalize(String name) {
*/
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);
Expand Down Expand Up @@ -2041,7 +2043,7 @@ public CodegenProperty fromProperty(String name, Schema p) {
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));
Expand Down Expand Up @@ -2123,7 +2125,7 @@ public CodegenProperty fromProperty(String name, Schema p) {
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);
Expand Down Expand Up @@ -2515,8 +2517,8 @@ public CodegenOperation fromOperation(String path,
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) {
Expand Down Expand Up @@ -4194,7 +4196,8 @@ public void writePropertyBack(String propertyKey, boolean value) {

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";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we fallback to a valid mime type such as application/octet-stream?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, we can definitely do that but the reason why I did this is to make it consistent with similar unknown cases in the code (e.g. https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L3131) so that users can easily grep "UNKNOWN" to identify which operations/models need to be fixed.

If later users have feedback on having a better default (e.g. application/octet-stream), we can definitely make the switch.

}
return new ArrayList<>(requestBody.getContent().keySet()).get(0);
}
Expand Down Expand Up @@ -4275,7 +4278,9 @@ public boolean hasFormParameter(OpenAPI openAPI, Operation operation) {
}

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;
}
}
Expand Down Expand Up @@ -4849,7 +4854,7 @@ public List<CodegenServerVariable> fromServerVariables(Map<String, ServerVariabl
}

private void setParameterNullable(CodegenParameter parameter, CodegenProperty property) {
if(parameter == null || property == null) {
if (parameter == null || property == null) {
return;
}
parameter.isNullable = property.isNullable;
Expand Down Expand Up @@ -4898,7 +4903,7 @@ public boolean isEnableMinimalUpdate() {
/**
* 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) {
Expand Down