swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

Enumeration not working for case sensitive values

Open sbelan opened this issue 10 years ago • 9 comments

Hi @wing328 , I am using swagger stable version 2.1.5 for java client code generator. In my case server expecting values as case sensitive whereas swagger not able to generate case sensitive values for enum. Please find below scenario details:

Below is the sample swagger specification for my newPet model which consist of enum as case sensitive:

newPet: type: object required: - name properties: id: type: integer format: int64 name: type: string Status: type: string enum: [Success, Failure] tag: type: string

While generating java client codegen using Swagger 2.1.5, below enum code getting generated in my model:

`public enum StatusEnum { @SerializedName("Success") SUCCESS("Success"),

@SerializedName("Failure") FAILURE("Failure");

private String value;

StatusEnum(String value) { this.value = value; }

@Override public String toString() { return value; } }`

Then I set enum value into the request as

StatusEnum.SUCCESS

whereas it is expecting as

StatusEnum.Success

Because of this server throwing exception as its expecting value as case sensitive. Please let me know if you require any more input on this or any sample code.

sbelan avatar Apr 04 '16 12:04 sbelan

@wing328 .. from where I will get change-log for codegen V 2.1.6?

sbelan avatar Apr 10 '16 05:04 sbelan

@sbelan see here: https://github.com/swagger-api/swagger-codegen/releases/tag/v2.1.6

fehguy avatar Apr 10 '16 06:04 fehguy

thanks @fehguy

sbelan avatar Apr 10 '16 07:04 sbelan

@sbelan it should be fixed by https://github.com/swagger-api/swagger-codegen/pull/3531. Please pull the latest master to give it a try.

wing328 avatar Aug 05 '16 04:08 wing328

@wing328 @fehguy Thanks for the fix. I will check. :+1: I have one proposal for enhancement, Will it be possible to have String Template instead of mustache, as those are much better than mustache templates.

sbelan avatar Aug 08 '16 15:08 sbelan

Please open a new issue about your suggestion to use the "String" template so that the community can also join the discussion.

wing328 avatar Aug 08 '16 15:08 wing328

We used to use STL and found it impossible to get contributions to the library so I don't expect we would go back to it

fehguy avatar Aug 08 '16 16:08 fehguy

Hi. I see the ENUM conversion is hardcoded to use .equals. Is it possible to configure it to use .equalsIgnoreCase ?

anandbibek avatar Oct 20 '20 12:10 anandbibek

At least this should be configurable

fdomingues-sky avatar Aug 16 '21 15:08 fdomingues-sky