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

Allow specifying custom code generation settings #131

Merged
merged 11 commits into from
Aug 3, 2023

Conversation

jhrcek
Copy link
Contributor

@jhrcek jhrcek commented Mar 20, 2023

I'm playing with ways that would allow resolving #129
while keeping the old behavior (stripping type name prefix) by default.

The important thing is that generated Elm encoders and decoders have to be compatible with ToJSON / FromJSON instances of Haskell types used across Haskell + Elm. This means that both Elm instance and ToJSON / FromJSON must use the same (what I call) CodeGenSettings that carry the "field label modifier" function (which for now is the only aspect of code generation that we allow to override).

See Type.hs for an example of how this could be used.

I'll need to think if this could be done more nicely over the next few days, but feel free to provide feedback if any.

@jhrcek jhrcek changed the title Allow overriding custom code generation settings Allow specifying custom code generation settings Mar 22, 2023
Copy link
Member

@turboMaCk turboMaCk left a comment

Choose a reason for hiding this comment

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

Looks great 👍

probably could use some documentation updates though

@jhrcek jhrcek marked this pull request as ready for review March 25, 2023 08:32
@jhrcek
Copy link
Contributor Author

jhrcek commented Mar 25, 2023

Thanks, docs updated.

test/golden/oneType.json Outdated Show resolved Hide resolved
@turboMaCk
Copy link
Member

Is anything blocking merge of this?

@jhrcek
Copy link
Contributor Author

jhrcek commented Aug 2, 2023

We didn't get any feedback from @silky who actually requested that change.
Let me revisit this PR and make it mergeable within the next few days if we don't hear from him.

@jhrcek jhrcek force-pushed the jan/configurable-field-label-modifier branch from e24f404 to 0fdca95 Compare August 2, 2023 12:32
@jhrcek jhrcek force-pushed the jan/configurable-field-label-modifier branch from 0fdca95 to 8b79edc Compare August 2, 2023 12:49
@silky
Copy link

silky commented Aug 2, 2023

Apologies for never getting around to responding to this; in the end I changed jobs since I needed it :)

But at a glance, it definitely does what I wanted, and I'll probably have cause to use it again at some point in the future; so that's great! Thanks :) 🙏🏻

Just (User {userName = "John", userAge = 42})


>>> data VeryLongType = VeryLongType { vltName :: String, vltAge :: Int } deriving (Generic, Show)
>>> instance FromJSON VeryLongType where parseJSON = elmStreetParseJson
>>> decode @VeryLongType "{ \"name\": \"John\", \"age\": 42 }"
>>> decode @VeryLongType "{\"age\":42,\"name\":\"John\",\"tag\":\"VeryLongType\"}"
Copy link
Member

Choose a reason for hiding this comment

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

doesn't seem that long to me 👀 ProjectContractChargingPeriodProjectAccountReferenceVMFactoryBuilderStrategy

@jhrcek jhrcek merged commit 609c5ec into master Aug 3, 2023
@jhrcek jhrcek deleted the jan/configurable-field-label-modifier branch August 3, 2023 04:28
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.

4 participants