swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.91k stars 6.03k forks source link

Double Equals enum value(==) is not generated properly in Java #10493

Open mrajaian opened 3 years ago

mrajaian commented 3 years ago
Description

When the model code to be generated is an enum and if one of the values is "==", then generation is not happening properly, it only gives a '_'

Swagger-codegen version

4.3.1

Swagger declaration file content or url
         OperatorExample:
            type: string
            enum:
            - '>'
            - '>='
            - ==
Command line used for generation

java -jar openapi-generator-cli.jar generate -i resources/openapi.yaml -g java -o mypkg/instana/openapi --skip-validate-spec -p dateLibrary=java8 --library native

Steps to reproduce

The generated client code is

 public enum OperatorExampleEnum {

    GREATER_THAN(">"),

    GREATER_THAN_OR_EQUAL_TO(">="),

    _("==");
}
Suggest a fix/enhancement

Special characters are replaced in https://github.com/swagger-api/swagger-codegen/blob/9de1f7baf0f681bb5b8b278c38550c9fe0bfb82b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java#L916

but the "==" is not covered here, perhaps, adding below in line number 948 would resolve this

        specialCharReplacements.put("==", "Equal_To");
b3nk4n commented 3 years ago

In addition what was written in the initial question, the compilation-error that this causes is the following when:

[ERROR] /some/path/openapi/src/main/java/org/openapitools/client/model/ModelExample.java:[109,5] as of release 9, '_' is a keyword, and may not be used as an identifier