Skip to content

[http-client-java] fix discriminator with no subtypes - #10080

Merged
Xiaofei Cao (XiaofeiCao) merged 4 commits into
microsoft:mainfrom
XiaofeiCao:java_fix_discriminator_no_subtypes
Mar 19, 2026
Merged

[http-client-java] fix discriminator with no subtypes#10080
Xiaofei Cao (XiaofeiCao) merged 4 commits into
microsoft:mainfrom
XiaofeiCao:java_fix_discriminator_no_subtypes

Conversation

@XiaofeiCao

Copy link
Copy Markdown
Member

Codegen differs with Swagger and TypeSpec in generating models with discriminator but no subTypes. Align the behaviour with Swagger.

When a TypeSpec model has @Discriminator but no known subtypes,
the emitter condition required both discriminatorProperty AND
discriminatedSubtypes to be set. This caused the discriminator
property to be silently dropped from the generated Java code.
Changed the condition to only require discriminatorProperty,
with subtypes iteration nested inside a separate check.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Regenerated code after adding ModelWithDiscriminatorNoSubtypes
test case. Includes new generated client, async client, impl,
and model files.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsoft-github-policy-servicemicrosoft-github-policy-serviceBot added the emitter:client:java Issue for the Java client emitter: @typespec/http-client-java label Mar 19, 2026
@github-actions

github-actionsBot commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-client-java
Show changes

@typespec/http-client-java - fix✏️

Fix discriminator property not generated when model has Discriminator but no known subtypes

Xiaofei Cao (XiaofeiCao) added a commit to Azure/autorest.java that referenced this pull request Mar 19, 2026
Sync microsoft/typespec#10080
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-sdk

Azure SDK Bot (azure-sdk) commented Mar 19, 2026

Copy link
Copy Markdown
Collaborator

You can try these changes here

🛝 Playground🌐 Website🛝 VSCode Extension

@XiaofeiCao
Xiaofei Cao (XiaofeiCao) added this pull request to the merge queueMar 19, 2026
Merged via the queue into microsoft:main with commit 63fc96bMar 19, 2026
31 checks passed
@XiaofeiCao
Xiaofei Cao (XiaofeiCao) deleted the java_fix_discriminator_no_subtypes branch March 19, 2026 06:00
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:javaIssue for the Java client emitter: @typespec/http-client-java

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@XiaofeiCao@azure-sdk@weidongxu-microsoft