Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity Property Type Override #177

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

LePips
Copy link
Contributor

@LePips LePips commented Dec 19, 2022

Implements individual property type override. This allows both general property naming and specific property type, mirroring the usage of rename.properties. I consider this an advanced feature, since this allows such fine control over single properties.

Overriding Optional

Since this is an advanced feature and by definition allows one to override the actual property type, it could be thought that his encompasses the entire type which includes whether it is an Optional.

For example, assume that Pet.tag would originally map to String?, but with the below:

entities:
  propertyTypeOverrides:
    Pet.tag: UUID

this would result in Pet.tag mapping to UUID, therefore making this required to the client. This can also happen the other way, making a non-optional property generate as an optional instead. This would also of course be a responsibility to the developer that the types can properly decode/encode.

I don't do this here (Optional is stable through the type override), however I think this should be a consideration.

@@ -696,6 +697,21 @@ extension Generator {

var propertyName = propertyName

if let parentType = parentType {
let entityPropertyPairs = options.entities.propertyTypeOverrides
.compactMapKeys({ EntityPropertyPair(rawValue: $0) })
Copy link
Contributor Author

@LePips LePips Dec 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required as a type of [EntityPropertyPair: String] for the propertyTypeOverrides configuration variable results in a decoding error when parsing the config, which is why it is [String: String].

@mgrider
Copy link
Contributor

mgrider commented Feb 3, 2023

FWIW, this looks good to me. 🤷‍♂️

@LePips LePips mentioned this pull request May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Entity Individual Property Swift Type Override
2 participants