Skip to content

Conversation

@ershov-konst
Copy link
Contributor

@ershov-konst ershov-konst commented Dec 24, 2025

This PR fixes an issue where example generation (@opExample) fails when used in a @versioned namespace on operations whose return type includes a union that references an enum.

Fixes: #8769

@ershov-konst ershov-konst force-pushed the fixes/opeanapi3-versioned-examples branch from b6ed95f to bfb7971 Compare December 29, 2025 08:18
return { example: serializeValueAsJson(program, example.value, type, encodeAs) };
const exactValueType = program.checker.getValueExactType(example.value);
return {
example: serializeValueAsJson(program, example.value, exactValueType ?? type, encodeAs),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution but I am not sure this is the right fix for this issue. I assume the problem must be that the enum must not be mutated correctly so it return a different instance for the value and the type. While this fix probably workaround this issue I think it also has some negative issues of lossing the original type information which might have encoding and other things

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 5, 2026

Open in StackBlitz

npm i https://pkg.pr.new/microsoft/typespec/@typespec/openapi@9268
npm i https://pkg.pr.new/microsoft/typespec/@typespec/openapi3@9268

commit: bfb7971

@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2026

All changed packages have been documented.

  • @typespec/openapi3
Show changes

@typespec/openapi3 - fix ✏️

Fixed examples generation for operations with unions and nested enums for versioned services

@ershov-konst
Copy link
Contributor Author

Hi @timotheeguerin,

Thanks for reviewing my PR and for the feedback.

I agree that the proposed solution is more of a workaround. My assumption was that since all checks for operation example value compatibility are already done earlier, it might not be necessary to validate the example data against the type again.

I also spent some time debugging the original cause and found that the decorator argument values are not being mutated correctly during the mutation process. Based on that, I prepared an additional PR #9308 that addresses this root issue.

I would really appreciate it if you could take a look at it.

Thanks in advance!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: @opExample generation fails in @versioned namespaces with union + enum

2 participants