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

[BUG] Model Name Mapping is not functional in Java codegen. #17189

Closed
2 of 6 tasks
krisnik opened this issue Nov 26, 2023 · 3 comments · Fixed by #18025
Closed
2 of 6 tasks

[BUG] Model Name Mapping is not functional in Java codegen. #17189

krisnik opened this issue Nov 26, 2023 · 3 comments · Fixed by #18025

Comments

@krisnik
Copy link

krisnik commented Nov 26, 2023

Bug Report Checklist

Hi, I have attempted to use the modelNameMapping configuration. But the generated SDK does not seem to render it.

Went through few reference PRs. #16209

The configuration was passed via pom.xml

           <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>6.3.0</version>
                <executions>
                    <execution>
                        <id>generate-java-sdk2</id>
                        <phase>install</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <skip>${sdk.codegen.skip}</skip>
                            <inputSpec>${project.build.directory}/openapi.json</inputSpec>
                            <generatorName>java</generatorName>
                            <groupId>${sdk2.java.groupId}</groupId>
                            <artifactId>${sdk2.java.artifactId}</artifactId>
                            <artifactVersion>${sdk2.java.version}</artifactVersion>
                            <packageName>${sdk2.java.packageName}</packageName>
                            <apiPackage>${sdk2.java.packageName}.api</apiPackage>
                            <modelPackage>${sdk2.java.packageName}.models</modelPackage>
                            <invokerPackage>${sdk2.java.packageName}.invoker</invokerPackage>
                            <generateModelTests>false</generateModelTests>
                            <output>${sdk2.java.outputDirectory}</output>
                            <library>webclient</library>
                            <verbose>true</verbose>
                            <importMappings>
                                <importMapping>User=com.foo.sdk.common.models.User</importMapping>
                                <importMapping>Link=com.foo.sdk.common.models.Link</importMapping>
                            </importMappings>
                            <schemaMappings>
                                <schemaMapping>EntityModelUserAccount=com.foo.sdk.models.UserAccount</schemaMapping>
                            </schemaMappings>
                            <!-- <modelNameMappings>
                                <modelNameMapping>EntityModelUserAccount=com.foo.sdk.models.UserAccount</modelNameMapping>
                            </modelNameMappings> -->
                            <configOptions>
                                <hateoas>true</hateoas>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Seems like the support is available only for select generators.

Could you please suggest how to proceed and enable support for java.

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
openapi-generator version
OpenAPI declaration file content or url
Steps to reproduce
Related issues/PRs
Suggest a fix
@wing328
Copy link
Member

wing328 commented Nov 27, 2023

which openapi generator are you using? can you share the full pom.xml to repeat the issue more easily?

@krisnik
Copy link
Author

krisnik commented Nov 27, 2023

which openapi generator are you using? can you share the full pom.xml to repeat the issue more easily?

@wing328 Sure, have updated the entire plugin. Please do note that the same thing didn't work even with plugin version 7.1.0. As a workaround what I have done is create a class and use it via schemaMapping.

My usecase is that if I have List<EntityModel<UserAccount>> to enable Spring Hateoas links, The generated class name is EntityModelUserAccount instead of UserAccount causing the SDK consumers to break. Hence, trying to make sure that the generated SDK will continue with the same name.

@meltsufin
Copy link

meltsufin commented Dec 12, 2023

I have the same problem. The --model-name-mappings option seems to have no effect for -g java --library okhttp-gson.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants