swagger-api / swagger-api/swagger-codegen
Double Equals enum value(==) is not generated properly in Java
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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");
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java at the special-character replacement logic referenced in the issue. Reproduce with the supplied OpenAPI enum and Java generation command, then verify that the generated OperatorExampleEnum preserves a distinct valid name for "==" rather than only "_".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100