Skip to content

Add warning when @defaultResponse is used on model with status code or @error#10555

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-duplicate-ref-in-return-type
Draft

Add warning when @defaultResponse is used on model with status code or @error#10555
Copilot wants to merge 3 commits intomainfrom
copilot/fix-duplicate-ref-in-return-type

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 29, 2026

Using @defaultResponse on a model that already has @statusCode or @error produces duplicate $ref entries in OpenAPI output (e.g., anyOf with two identical refs). Rather than silently generating invalid output, emit a diagnostic warning at the source.

Changes

  • packages/openapi/src/lib.ts — New default-response-with-status-code diagnostic with statusCode and error message variants
  • packages/openapi/src/decorators.ts$defaultResponse now checks the target model for existing @statusCode properties and @error decoration before setting the wildcard status code
  • packages/openapi/test/decorators.test.ts — Tests for both warning cases and the clean no-warning path

Example

// This now emits a warning:
@error
@defaultResponse
model DefaultError is Error<500>;

// Recommended alternatives:
@error
model MyError { message: string; }
op read(): Data | MyError;

// Or split concerns:
@error model Error500 is Error<500>;
@error @defaultResponse model DefaultError { message: string; }
alias Result<T> = T | Error500 | DefaultError;

…code or @error

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/2d6ca218-090a-4b98-8bfd-f31ddb57b9c9

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix duplicate $ref in return type union for defaultResponse model Add warning when @defaultResponse is used on model with status code or @error Apr 29, 2026
Copilot AI requested a review from timotheeguerin April 29, 2026 17:32
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 29, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/openapi@10555

commit: 49c122f

@timotheeguerin
Copy link
Copy Markdown
Member

@copilot fix lint

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 29, 2026

@copilot fix lint

Fixed in c10f3ab — removed the unnecessary escape character \@@ in the regex, and added the missing changeset for @typespec/openapi.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: @defaultResponse model included in return type union generates anyOf with duplicate $ref

2 participants