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

[gen] support for normalized fields #3031

Closed
hochgi opened this issue Aug 18, 2024 · 5 comments · Fixed by #3069
Closed

[gen] support for normalized fields #3031

hochgi opened this issue Aug 18, 2024 · 5 comments · Fixed by #3069
Labels

Comments

@hochgi
Copy link
Contributor

hochgi commented Aug 18, 2024

Is your feature request related to a problem? Please describe.
APIs are messy, fields come in all flavors: snake_case, kebab-case, or even whitespaced tokens.
While illegal scala variable names are backtick escaped since #2839, we still end up with unconventional (ugly) generated code.
Even legal names, like snake_case, or UPPER_SNAKE which are not escaped does not look "pretty" in generated code.

Describe the solution you'd like
Add a flag in configuration, to allow change the field name, and add an annotation like:

import zio.schema.annotation.fieldName

case class User(
  @fieldName("user_id") userId: String,
  …
)

There would have to be some parser with heuristics involved. Which tokens casing to preserve, capitalize, lowercase, etc'…

Describe alternatives you've considered
putting up with ugly generated code? 😅

Additional context
There is no "right" answer on how to parse & transform field names.
e.g: perhaps arn_API-Gateway should preserve some casing and be converted to arnAPIGateway?
Or perhaps we prefer to always use capitalized tokens, and even break arn_APIGatway to arnApiGateway?
Anything would be better than backtick escaped

`arn_API-Gateway`

Moreover, maybe the configuration can also allow customization for some "unparseable" replacements (like when starting with a non-letter char), e.g:

"1st" -> "first
"2nd" -> "second"
"3rd" -> "third"
…

This might be only "cosmetics", but it can really improve generated code quality.

@hochgi hochgi added the enhancement New feature or request label Aug 18, 2024
@jdegoes
Copy link
Member

jdegoes commented Aug 29, 2024

/bounty $75

Copy link

algora-pbc bot commented Aug 29, 2024

💎 $75 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #3031 with your implementation plan
  2. Submit work: Create a pull request including /claim #3031 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-http!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🟢 @hochgi Aug 29, 2024, 8:15:16 PM #3069

@hochgi
Copy link
Contributor Author

hochgi commented Aug 29, 2024

/attempt #3031

Algora profile Completed bounties Tech Active attempts Options
@hochgi 2 ZIO bounties
Scala, Java
Cancel attempt

Copy link

algora-pbc bot commented Aug 30, 2024

💡 @hochgi submitted a pull request that claims the bounty. You can visit your bounty board to reward.

hochgi added a commit to hochgi/zio-http that referenced this issue Sep 3, 2024
…n for zio#3031 (which will add more annotations). Specifically: use imports insteads of inlined FQCN when adding annotations
Copy link

algora-pbc bot commented Sep 4, 2024

🎉🎈 @hochgi has been awarded $75! 🎈🎊

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

Successfully merging a pull request may close this issue.

2 participants