-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support serialization of object examples on unions #5180
Support serialization of object examples on unions #5180
Conversation
@microsoft-github-policy-service agree |
4cc2335
to
2f8d537
Compare
@RichardCPoint Thank you opening this pull request! This fix looks great! Do you mind running |
Thanks for the review! I've run the command above and committed the result – please let me know if there's anything else I should do. |
Hi @RichardCPoint. Your PR has had no update for 30 days and it is marked as a stale PR. If it is not updated within 30 days, the PR will automatically be closed. If you want to refresh the PR, please remove the |
…ect-examples-on-unions
@chrisradek, thanks for taking a look at this PR! Are there any further changes that you'd like to see, or is there any other way that I can help get this expedited? |
@RichardCPoint Thanks for the ping! Sorry for the radio silence - many of us just came back this week from holidays! I'm just running the CI now - assuming it still passes we'll get this merged right away! |
@chrisradek, awesome, thank you so much! |
This PR fixes this issue:
@example
decorator not supported forunion
s #4869Currently, the
@typespec/openapi3
emitter supports@example
s formodel
s, but outputs incorrect examples forunion
s.For example (playground link):
should output with
{ a: 1 }
as the example, but instead it is{}
.The issue manifests in the
serializeValueAsJson
function in packages/compiler/src/lib/examples.ts, and occurs because theresolveUnions
function in the same file fails to detect the appropriate union variant.With this PR, the example is emitted correctly. I've added a unit test to confirm this.