Skip to content

[Bug]: OpenAPI3 merges discriminated union envelopes when variants share a payload type #11979

Description

@tadfisher

Describe the bug

With @typespec/openapi3 1.16.0, distinct variants of a discriminated union reuse the first envelope schema when their payload types match. The emitter repeats that schema in oneOf and points every discriminator mapping to it. The other envelope schemas are missing from the output.

For example:

@discriminated(#{
  discriminatorPropertyName: "tag",
  envelopePropertyName: "contents"
})
union Limit {
  daily: string,
  weekly: string,
  monthly: string,
}

This produces a oneOf schema that references LimitDaily three times, and rejects any payload with "tag":"weekly" or "tag":"monthly".

Reproduction

Playground

Checklist

Activity

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions