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.86k stars 6.59k forks source link

[REQ][Go] Support case-insensitive string enums #16634

Open ctreatma opened 1 year ago

ctreatma commented 1 year ago

Is your feature request related to a problem? Please describe.

Given the following enum spec:

enum:
- HDD
- SSD
- NVME
type: string

The Go client generator will generate an enum that does strict == comparisons, so if the specified API returns NVMe instead of NVME, the response will fail validation because "NVMe" != "NVME".

Describe the solution you'd like

The Java generator supports a useEnumCaseInsensitive option; when that option is enabled, the generator will use case-insensitive equality checks for string enums. Copying that feature into the Go generator would enable generator users to opt in to case-insensitive comparisons for string enums.

Describe alternatives you've considered

Things I've tried:

Additional context

jpeach commented 7 months ago

FWIW go-swagger supports this with the x-go-enum-ci extension, see https://github.com/go-swagger/go-swagger/pull/2264.