apple / apple/swift-openapi-generator
Support case-insensitive string enums
- Dominant language
- Swift
- Stars
- 2k
- Forks
- 182
- Avg merge
- 13h 28m
- Merged PRs (30d)
- 5
Description
### Motivation
[I am stealing this request entirely from this request which resulted in a change to the Go cli.](https://github.com/OpenAPITools/openapi-generator/issues/16634)
Given the following enum spec:
```
enum:
- HDD
- SSD
- NVME
type: string
```
The Swift 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".
In my case specifically I needed it for state codes where someone may write "WA" or "Wa"
### Proposed solution
The Java generator supports a `useEnumCaseInsensitive` option; The Go generator supports a option via the `x-go-enum-ci` extension.
When that option is enabled, the generator will use case-insensitive equality checks for string enums. Copying that feature into the Swift generator would enable generator users to opt in to case-insensitive comparisons for string enums.
### Alternatives considered
Certainly can smooth this out by cleaning up server side implementation. Have tried a spec like
```
StateOrProvince:
type: object
oneOf:
- $ref: '#/components/schemas/KnownStateOrProvince'
- $ref: '#/components/schemas/UnknownStateOrProvince'
UnknownStateOrProvince:
type: string
KnownStateOrProvince:
type: string
enum:
- AL
- AK
- AZ
```
But while that fixes parsing it does not allow me to recognize "Wa" as .WA.
### Additional information
_No response_
Contributor guide
Research direction
No file or test path is named. Start by locating the Swift generator's string-enum generation entry point and compare its option plumbing with the Java useEnumCaseInsensitive and Go x-go-enum-ci precedents cited here. Done means an opt-in option makes generated Swift string enums compare case-insensitively, including values such as NVMe/NVME and Wa/WA.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, swift
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100