You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have the requirement that all of our entities and enums implement Hashable. For the entities this is mostly achievable by setting our config.yaml:
entities:
protocols: [Hashable, Codable]
However, two problems arise with this configuration:
There's no way to set Hashable conformance to enums, which breaks all Entities with an enum property at compile time: Entity does not conform to Hashable. This can be worked around by manually extending all enums:
extensionUserStatus:Hashable{}
If an entity has a map property, then create-api will generate an enum AnyJSON which also doesn't conform to Hashable. However, using the same extension workaround yields compile time error:
Extension outside of file declaring enum 'AnyJSON' prevents automatic synthesis of 'hash(into:)' for protocol 'Hashable'
Potential Solution
Add a configuration option that allows conformance for enums, in the same way that is afforded for entities:
enums:
protocols: [Hashable, Codable]
There's also the argument that Hashable should be universally used over Equatable by default in this library, since all Hashable constructs have Equatable conformance.
The text was updated successfully, but these errors were encountered:
Likewise, given recent developments in Swift 5.8, I would like to see additional conformance to Sendable in enums and other places. Otherwise, it is impossible to add proper Sendable conformance through the entities.protocols configuration.
Thanks for sharing this request! I agree that this would be a great addition to allowing us to customise enum generation 🙏 A similar configuration style was also proposed here: #130 (comment) so I think the enums option is a right approach to cover use cases like the one that @aaronsky raised with Sendable too.
It would be interesting to dig into Hashable by default, but there are some considerations to be had when using the generator to produce class types. We'd have to dig a bit further into that one, but in the meantime I think adding the enums.protocols support would be a good start 👍
We have the requirement that all of our entities and enums implement
Hashable
. For the entities this is mostly achievable by setting ourconfig.yaml
:However, two problems arise with this configuration:
Hashable
conformance to enums, which breaks all Entities with an enum property at compile time:Entity does not conform to Hashable
. This can be worked around by manually extending all enums:enum AnyJSON
which also doesn't conform toHashable
. However, using the same extension workaround yields compile time error:Potential Solution
Add a configuration option that allows conformance for enums, in the same way that is afforded for entities:
There's also the argument that
Hashable
should be universally used overEquatable
by default in this library, since allHashable
constructs haveEquatable
conformance.The text was updated successfully, but these errors were encountered: