Skip to content

[Bug]: Implicit visibility with @discriminated unions can create duplicate type names #8677

@witemple-msft

Description

@witemple-msft

Describe the bug

import "@typespec/http";

using TypeSpec.Http;

model M {
  @visibility(Lifecycle.Create)
  prop: string;
}

@discriminated
union U {
  variant: M,
}

@put op createOrUpdate(@body body: U): U;

Because the @discriminated union creates its own envelope shapes, it wants to synthesize a schema named UVariant for variant's envelope shape. However, because the inner property prop is only visible in Create phases, implicit visibility is triggered. This causes OpenAPI to create two different schemas both named UVariant. Note that you have to use Create or Update visibility to trigger the bug. If you use Read visibility, the bug is not triggered because the same schema can be reused via. readOnly.

Reproduction

Minimal repro: TypeSpec Playground

Checklist

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions