swagger-api/swagger-codegen
View on GitHub[JAVA] codegen with negative integer enum values compile error
Open
#4,780 opened on Feb 13, 2017
Client: JavaFeature: EnumIssue: Workaround availablehelp wanted
Description
Description
I have an enum in my swagger doc:
enums/TimeValidationZone:
description: TimeValidationZone
type: object
properties:
description:
description: description
type: string
data:
enum:
- '-720'
- '-660'
- '-600'
- '-540'
- '-480'
- '-420'
- '-360'
- '-300'
- '-240'
- '-210'
- '-180'
- '-120'
- '-60'
- '0'
- '60'
- '120'
- '180'
- '210'
- '240'
- '270'
- '300'
- '330'
- '345'
- '360'
- '390'
- '420'
- '480'
- '540'
- '570'
- '600'
- '660'
- '720'
- '780'
type: string
The salient point being that there is negative values with the same absolute value e.g. -60 and 60.
This generates invalid Java code:
@ApiModel(description = "TimeValidationZone")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2017-02-13T15:17:56.985+13:00")
public class EnumsTimeValidationZone {
@SerializedName("description")
private String description = null;
/**
* Gets or Sets data
*/
public enum DataEnum {
...
@SerializedName("-60")
_60("-60"),
@SerializedName("0")
_0("0"),
@SerializedName("60")
_60("60"),
...
Swagger-codegen version
λ java -jar swagger-codegen\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar version
2.2.2-SNAPSHOT
Swagger declaration file content or url
See above for relevant portion.
Command line used for generation
java -jar swagger-codegen\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar generate -i http://localhost/revapi/swagger/docs/v2 -l java -o .\swagger-java-client\
Steps to reproduce
Create swagger file with enum type as declared above, run codegen.