Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #3388
Closed
Open
Issue created Jul 18, 2019 by Administrator@rootContributor

[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.

Assignee
Assign to
Time tracking