Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix imports and property name when using anyof/oneof in services #3639

Merged
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 @@ -4884,41 +4884,54 @@ public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, S
imports.add(codegenParameter.baseType);
} else {
CodegenProperty codegenProperty = fromProperty("property", schema);
if (ModelUtils.getAdditionalProperties(schema) != null) {// http body is map
LOGGER.error("Map should be supported. Please report to openapi-generator github repo about the issue.");
} else if (codegenProperty != null) {
String codegenModelName, codegenModelDescription;

if (codegenModel != null) {
codegenModelName = codegenModel.classname;
codegenModelDescription = codegenModel.description;
} else {
LOGGER.warn("The following schema has undefined (null) baseType. " +
"It could be due to form parameter defined in OpenAPI v2 spec with incorrect consumes. " +
"A correct 'consumes' for form parameters should be " +
"'application/x-www-form-urlencoded' or 'multipart/form-data'");
LOGGER.warn("schema: " + schema);
LOGGER.warn("codegenModel is null. Default to UNKNOWN_BASE_TYPE");
codegenModelName = "UNKNOWN_BASE_TYPE";
codegenModelDescription = "UNKNOWN_DESCRIPTION";
}

if (StringUtils.isEmpty(bodyParameterName)) {
codegenParameter.baseName = codegenModelName;
} else {
codegenParameter.baseName = bodyParameterName;
}

if (codegenProperty != null && codegenProperty.getComplexType() != null && codegenProperty.getComplexType().contains(" | ")) {
Copy link
Member

Choose a reason for hiding this comment

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

will it always be surrounded by spaces, i.e. |?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. But I must admit, the whole (any/one) of issue needs to be reconsidered as it's more of a hack rather than a sustainable fix. :|

List<String> parts = Arrays.asList(codegenProperty.getComplexType().split(" \\| "));
imports.addAll(parts);
String codegenModelName = codegenProperty.getComplexType();
codegenParameter.baseName = codegenModelName;
codegenParameter.paramName = toParamName(codegenParameter.baseName);
codegenParameter.baseType = codegenModelName;
codegenParameter.baseType = codegenParameter.baseName;
codegenParameter.dataType = getTypeDeclaration(codegenModelName);
codegenParameter.description = codegenModelDescription;
imports.add(codegenParameter.baseType);
codegenParameter.description = codegenProperty.getDescription();
} else {
if (ModelUtils.getAdditionalProperties(schema) != null) {// http body is map
LOGGER.error("Map should be supported. Please report to openapi-generator github repo about the issue.");
} else if (codegenProperty != null) {
String codegenModelName, codegenModelDescription;

if (codegenModel != null) {
codegenModelName = codegenModel.classname;
codegenModelDescription = codegenModel.description;
} else {
LOGGER.warn("The following schema has undefined (null) baseType. " +
"It could be due to form parameter defined in OpenAPI v2 spec with incorrect consumes. " +
"A correct 'consumes' for form parameters should be " +
"'application/x-www-form-urlencoded' or 'multipart/form-data'");
LOGGER.warn("schema: " + schema);
LOGGER.warn("codegenModel is null. Default to UNKNOWN_BASE_TYPE");
codegenModelName = "UNKNOWN_BASE_TYPE";
codegenModelDescription = "UNKNOWN_DESCRIPTION";
}

if (StringUtils.isEmpty(bodyParameterName)) {
codegenParameter.baseName = codegenModelName;
} else {
codegenParameter.baseName = bodyParameterName;
}

if (codegenProperty.complexType != null) {
imports.add(codegenProperty.complexType);
codegenParameter.paramName = toParamName(codegenParameter.baseName);
codegenParameter.baseType = codegenModelName;
codegenParameter.dataType = getTypeDeclaration(codegenModelName);
codegenParameter.description = codegenModelDescription;
imports.add(codegenParameter.baseType);

if (codegenProperty.complexType != null) {
imports.add(codegenProperty.complexType);
}
}
}

setParameterBooleanFlagWithCodegenProperty(codegenParameter, codegenProperty);
// set nullable
setParameterNullable(codegenParameter, codegenProperty);
Expand Down