[BUG] [DefaultCodeGen] Map<String, X> is generated as API requestBody if Model class has additionalProperties=true
Created by: balazs-zsoldos
Description
In case a model class has additionalProperties=true, in the API a Map is inserted as requestBody parameter instead of the model class.
openapi-generator version
4.0.3
OpenAPI declaration file content or url
See steps to reproduce.
Command line used for generation
See steps to reproduce.
Steps to reproduce
I used the following pom.xml to generate the sources: https://gist.github.com/balazs-zsoldos/7c707b098d97bac59a3b411d5d6b0664
For an example, see GroupResourceAPI.addUserToGroup(...). The requestBody parameter here is a Map, but it should be UpdateUserToGroupBean.
Related issues/PRs
Suggest a fix
I analyzed the problem and I think the behavior could be changed in DefaultCodeGen.fromRequestBody(...) function, more specifically changing this and the next line to the following code solves the issue:
if (name != null) {
CodegenModel codegenModel = fromModel(name, schema);
codegenParameter.baseType = codegenModel.classname;
codegenParameter.dataType = getTypeDeclaration(codegenModel.classname);
imports.add(codegenParameter.baseType);
} else {
codegenParameter.dataType = getTypeDeclaration(schema);
codegenParameter.baseType = getSchemaType(inner);
}
However, I am not sure how this would affect all generators that already exist. If there is a specific reason why Map is inserted in this case instead of the model type. I would like to send a patch that does not cause any trouble.
Do you think this is a good fix? Or shall I create a new configuration property for the generator like useModelTypeForRequestBodyParamWhereAdditionalPropertiesIsTrue and make it default false? In that case, the current behavior is not changed only if explicitly sets this configuration to true.