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

Support top-level sum types #105

Open
Tomboyo opened this issue Oct 19, 2023 · 0 comments
Open

Support top-level sum types #105

Tomboyo opened this issue Oct 19, 2023 · 0 comments

Comments

@Tomboyo
Copy link
Owner

Tomboyo commented Oct 19, 2023

When a schema is a oneOf composition and has no properties keyword or other composition keywords, it should be treated as a sum type and rendered as a sealed interface of its components.

Foo:
  oneOf:
    - properties:
        foo:
          type: string
    - properties:
        bar:
          type: string
public sealed interface Foo permits FooAnonymous1, FooAnonymous2 {
  public static Anonymous1Builder newFooAnonymous1Builder() { ... }
  public static Anonymous2Builder newFooAnonymous2Builder() {. .. }
}

public record FooAnonymous1(String foo) implements Foo {}
public record FooAnonymous2(String bar) implements Foo {}

The interface exposes static factories to create builders for each component.

@Tomboyo Tomboyo added this to the Compositional Types milestone Oct 19, 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

No branches or pull requests

1 participant