8000 Java support for literals in unions proposal by ajgateno · Pull Request #6822 · fern-api/fern · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Java support for literals in unions proposal #6822

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

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

Conversation

ajgateno
Copy link
Contributor
@ajgateno ajgateno commented Apr 22, 2025

Currently, the Java SDK generator doesn't have full support for literal types. We currently only support literals in objects, which are handled by having the generator hard-code the literal value into the getter method.

This is a proposal for how to handle literals in unions:

Discriminated Unions

Instead of taking in an argument in the constructor, pass in the value of the literal into the constructor ourselves, and only expose the label to the user, like in the case of no-properties union variants.

Undiscriminated Unions

Booleans

Handle like any other boolean

Strings

Expose a visitLiteral(String) method with a javadoc listing all the possible options, and an ofLiteral(String) which throws if the provided string is not one of the supported string literals.

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

Successfully merging this pull request may close these issues.

2 participants
0