-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Closed
Labels
Description
Is your feature request related to a problem? Please describe.
The current handling of oneOf does not allow switch expressions on the generated type to be exhaustive.
Currently oneOf generates an interface:
Animal:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
generates
public interface Animal {...}
public class Cat implements Animal {...}
public class Dog implements Animal {...}
Switching over this requires a default clause:
switch (myAnimal) {
case Dog d -> "dog"
case Cat c -> "cat"
default -> "There is no other class that implements Animal but I still need this clause here"
}
Avoiding default clauses in switch expressions is considered good practice as it allows the compiler to check for omissions.
Describe the solution you'd like
Animal:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
generates
public sealed interface Animal permits Cat, Dog {...}
public class Cat implements Animal {...}
public class Dog implements Animal {...}
Describe alternatives you've considered
The suggested feature is the canonical way to express sum types in Java, hence the canonical fit for oneOf.
Additional context
Reactions are currently unavailable