-
Notifications
You must be signed in to change notification settings - Fork 334
Description
We are not emitting proper OA3 for unions. In this example, I believe we need to emit oneOf somewhere. Right now we depend on references to the base type implicitly being a reference to some kind of union of anything that allOf's that type, but these semantics are not supported by the specification. @mikekistler agrees with this analysis.
oneOf two things need to happen for out output to be correct:
- Any references to
Baseare replaced by an inlineoneOfunion referencing all of the derived types. Basebecomes an allOf of the derived types and we generate a new type with a name likeBaseCommonthat holds the cadlBasetype's properties.
The latter is what @mikekistler prefers, and hinges on the fact that by putting discriminator on the base model you're essentially instructing cadl that "every time I reference this type, I'm referring to a union of its subtypes", but it does have the downside that we are generating a name in the openapi output (BaseCommon), and also munging a name users might expect to be generated as-is in client code (e.g. they might expect to see class A extends Base { } in their TS/C# code somewhere.
We have a third option here which is to delete @Discriminator on models and reserve it only for unions ala #335 where the Cadl author gives a good name to both the base type and the union separately.