microsoft / microsoft/typespec
oneOf should be allowed on a model with a discriminator
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
Context: oneOf with union has proven to create issues with code generation from openapi spec generated from Typespec. As a result, we moved to use model with a discriminator, which solves the issue with code generation, but creates another one. Swagger UI doesn't visualize full data models of possible options (models B and C in example below), but only array of enums. This is unacceptable from API user perspective, as oneOf is where the complexity of the API request for the user is.
The below structure would allow the best of both worlds, where ideally swagger UI visualizes the full data models of B and C.
```
enum Kind {
B,
C
}
@discriminator("kind")
@oneOf
model A {
kind: Kind
}
model B extends A {
kind: Kind.B
}
model C extends A {
kind: Kind.C
}
```
Contributor guide
Assessment
This issue has not been assessed yet.