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

Get default value from case class default paramters #552

Closed
liewhite opened this issue May 5, 2023 · 9 comments · Fixed by #562
Closed

Get default value from case class default paramters #552

liewhite opened this issue May 5, 2023 · 9 comments · Fixed by #562

Comments

@liewhite
Copy link
Contributor

liewhite commented May 5, 2023

It's very convenient to define default value in case class, and zio-json do so.

@jdegoes
Copy link
Member

jdegoes commented May 9, 2023

/bounty $150

@algora-pbc
Copy link

algora-pbc bot commented May 9, 2023

💎 $150 bounty created by jdegoes
🙋 If you start working on this, comment /attempt #552 to notify everyone
👉 To claim this bounty, submit a pull request that includes the text /claim #552 somewhere in its body
📝 Before proceeding, please make sure you can receive payouts in your country
💵 Payment arrives in your account 2-5 days after the bounty is rewarded
💯 You keep 100% of the bounty award
🙏 Thank you for contributing to zio/zio-schema!

Attempt Started (GMT+0) Solution
🟢 @987Nabil May 19, 2023, 3:19:03 AM #562

@andrzejressel
Copy link
Contributor

From what I see schema does not have notion of default values for case classes.

To keep it as generic as possible I guess something like that should be added (+ support for custom deserializers like json)?

@liewhite
Copy link
Contributor Author

From what I see schema does not have notion of default values for case classes.

But Schema[T] is the only thing json codec can get from schema.

@jdegoes
Copy link
Member

jdegoes commented May 17, 2023

We already have an annotation that can be used by a user to add a default value to a case class field. I think we should reuse that, and, in the Scala 2/3 macros, we see if a parameter to a case class constructor has a default value, and if so, we bundle that up and add the annotation to the Schema, unless the annotation does / will exist because the user added it themselves.

This way, users of a Schema only need to check the annotation, rather than look at 2 possibly conflicting sources for default values.

@liewhite
Copy link
Contributor Author

Create instance of class can't make use of annotations.
This is a language feature, many people use it, I think we should use default parameter as far as possible.

@987Nabil
Copy link
Contributor

I'll /attempt #552 since this this is also useful for OpenAPI gen in zio-http.

@algora-pbc
Copy link

algora-pbc bot commented May 20, 2023

💡 @987Nabil submitted a pull request that claims the bounty. You can visit your org dashboard to reward.

@vigoo vigoo closed this as completed in #562 Sep 6, 2023
@algora-pbc
Copy link

algora-pbc bot commented Sep 6, 2023

🎉🎈 @987Nabil has been awarded $150! 🎈🎊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants