OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.48k stars 6.5k forks source link

[BUG][JAVA] "ID" in class names altered to "Id" #8920

Open MBGIV opened 3 years ago

MBGIV commented 3 years ago
Description

The behaviour leads to compile errors because of the file name / class name mismatch. The issue unveiled when trying to generate the code for the jira rest client.

openapi-generator version

5.0.1 (openapi-generator-maven-plugin)

OpenAPI declaration file content or url

Below the execution configuration of the maven plugin:

<execution>
    <goals>
        <goal>generate</goal>
    </goals>
    <configuration>
        <inputSpec>https://developer.atlassian.com/cloud/jira/platform/swagger-v3.v3.json</inputSpec>
        <generatorName>java</generatorName>
        <library>resttemplate</library>
        <apiPackage>com.atlassian.jira.rest.client.api</apiPackage>
        <modelPackage>com.atlassian.jira.rest.client.model</modelPackage>
        <invokerPackage>com.atlassian.jira.rest.client</invokerPackage>
        <groupId>com.atlassian.jira.rest</groupId>
        <artifactId>client</artifactId>
        <configOptions>
            <dateLibrary>java8</dateLibrary>
        </configOptions>
    </configuration>
</execution>
Command line used for generation

See execution definition above.

Steps to reproduce

Add above execution definiton to any maven java project using openapi-generator. Run commands maven clean, maven install.

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/3428 https://github.com/OpenAPITools/openapi-generator/issues/1692

Suggest a fix/enhancement

Define separate rule to handle the (sub)string "ID". Classes must not be renamed.

MBGIV commented 3 years ago

Actually, the spec has to be downloaded and adapted locally as described here https://community.atlassian.com/t5/Jira-articles/Generating-a-REST-client-for-Jira-Cloud/ba-p/1307133 in section Making swagger-codegen happy.

I proceeded to adapt the spec and validated it using https://apitools.dev/swagger-parser/online/, which confirmed the spec to be valid.