Skip to content

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

Merged
XiaofeiCao merged 4 commits intomicrosoft:mainfrom
XiaofeiCao:java_fix_discriminator_no_subtypes
Mar 19, 2026
Merged

[http-client-java] fix discriminator with no subtypes#10080
XiaofeiCao merged 4 commits intomicrosoft:mainfrom
XiaofeiCao:java_fix_discriminator_no_subtypes

Conversation

@XiaofeiCao
Copy link
Member

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

XiaofeiCao and others added 3 commits March 18, 2026 18:20
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-service microsoft-github-policy-service bot added the emitter:client:java Issue for the Java client emitter: @typespec/http-client-java label Mar 19, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

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

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
Copy link
Collaborator

azure-sdk commented Mar 19, 2026

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@XiaofeiCao XiaofeiCao enabled auto-merge March 19, 2026 05:23
@XiaofeiCao XiaofeiCao added this pull request to the merge queue Mar 19, 2026
Merged via the queue into microsoft:main with commit 63fc96b Mar 19, 2026
31 checks passed
@XiaofeiCao XiaofeiCao deleted the java_fix_discriminator_no_subtypes branch March 19, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants