apple / swift-openapi-generator

Generate Swift client and server code from an OpenAPI document.
https://swiftpackageindex.com/apple/swift-openapi-generator/documentation
Apache License 2.0
1.21k stars 87 forks source link

Generated enums should conform to `CaseIterable` #548

Closed rpecka closed 1 month ago

rpecka commented 2 months ago

Motivation

I would like to implement a dropdown picker in my app which lets users select one of the possible enum values to send to an API. I'm able to do this by conforming the enum to CaseIterable myself in an extension, but if I do that, I have to implement allCases myself which kind of defeats the purpose. I would like the declaration of the enum to have the CaseIterable conformance so that allCases is synthesized automatically.

Proposed solution

Add CaseIterable conformance synthesized enum declarations.

Alternatives considered

No response

Additional information

No response

simonjbeaumont commented 1 month ago

This seems totally reasonable.

czechboy0 commented 1 month ago

Agreed, we'd welcome a PR adding this to both string-based and int-based enums. I don't think it'll be possible for oneOf's, since they have associated values.

PARAIPAN9 commented 1 month ago

Hello, it’s been a while since my last contribution, but I find this issue interesting to work on. Is it available to pick up?

czechboy0 commented 1 month ago

@rpecka have you started working on this or can @PARAIPAN9 pick it up?

rpecka commented 1 month ago

I haven't started -- fine if someone else does.

czechboy0 commented 1 month ago

Ok go ahead, @PARAIPAN9

czechboy0 commented 1 month ago

This already landed in main, will be in the next release.