Skip to content

fix(http-client-java): make YAML deserialization context-aware - #12434

Merged
Weidong Xu (weidongxu-microsoft) merged 3 commits into
microsoft:mainfrom
weidongxu-microsoft:fix/java-context-aware-yaml-reader
Oct 30, 2026
Merged

Weidong Xu (weidongxu-microsoft) merged 3 commits into
microsoft:mainfrom
weidongxu-microsoft:fix/java-context-aware-yaml-reader

Conversation

@weidongxu-microsoft

@weidongxu-microsoft Weidong Xu (weidongxu-microsoft) commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Make Java code-model YAML deserialization context-aware: preprocess structural properties only on their owning beans, leaving typed-map keys and example payloads untouched.

Extends #12428 to address collisions such as discriminator value responses, reported in Azure/azure-sdk-for-java#50875. Retains the existing tests and adds coverage for all special keys, other typed maps, schema types, and aliases.

Adds a permanent TypeSpec regression to discriminator-edge-cases.tsp covering all, immediate, responses, and exceptions.

Validation

  • Generator mvn verify, 53 emitter tests, build, formatting, and lint passed.
  • Real TypeSpec namespace and discriminator collisions generate successfully.
  • The permanent TypeSpec regression's emitted YAML fails with the original main reader at line 218 and loads successfully with the fixed reader.
  • Before adding the new fixture models, the existing discriminator scenario produced byte-identical code-model YAML and 26 Java sources.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 60868175-cb81-4b72-83af-4b789c536100
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 60868175-cb81-4b72-83af-4b789c536100
Copilot AI balanced review requested due to automatic review settings October 29, 2026 12:38
@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 Oct 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the context-aware YAML deserialization change.

No open issues 🎉

What changed in this PR

Makes the Java generator’s code-model YAML deserialization context-aware, preventing service-defined keys such as discriminator value responses from being mistaken for structural properties.

Changes:

  • Restricts structural preprocessing to the owning model classes, leaving typed-map keys and example payloads untouched.
  • Adds regression tests for special-key collisions, schema types, and alias identity.
  • Adds a Java emitter bug-fix changelog entry.
File Description
packages/​http-client-java/​generator/​http-client-generator-core/​src/​test/​java/​com/​microsoft/​typespec/​http/​client/​generator/​core/​extension/​model/​codemodel/​CodeModelCustomConstructorTests.java Tests key collisions, payload preservation, schema types, and aliases.
packages/​http-client-java/​generator/​http-client-generator-core/​src/​main/​java/​com/​microsoft/​typespec/​http/​client/​generator/​core/​extension/​model/​codemodel/​CodeModelCustomConstructor.java Scopes YAML preprocessing to owning beans and handles examples separately.
.chronus/​changes/​http-client-java-context-aware-yaml-reader.md Documents the service-defined map-key fix.

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @typespec/http-client-java
Show changes

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

Prevent service-defined YAML map keys, such as discriminator value responses, from being interpreted as code-model properties.

…ressions

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 60868175-cb81-4b72-83af-4b789c536100
Copilot AI balanced review requested due to automatic review settings October 29, 2026 12:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block approval of the context-aware YAML reader change.

No open issues 🎉

Review effort: Balanced

@azure-sdk-automation

azure-sdk-automation Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@weidongxu-microsoft

Copy link
Copy Markdown
Contributor Author

The regression combines two changes/conditions:

  1. Fix Java discriminator handling for untagged intermediates #12294 started populating discriminator.all from TCGC's subtype map. Published emitter 0.48.1 left that map empty; 0.48.3 emits service-defined keys such as responses.
  2. The Java YAML reader already had a context-insensitive key switch that also ran on typed dictionaries. It interpreted the discriminator key responses as an operation's response list and cast its mapping value to SequenceNode, causing the exception.

The emitter change exposed an existing reader defect; different TCGC output is not required to explain the regression. #12428 guarded all/immediate, but other key collisions remained, including in maps unrelated to discriminators.

This PR limits structural preprocessing to the owning Java beans, leaving dictionary keys untouched.

Merged via the queue into microsoft:main with commit cba4987 Oct 30, 2026
36 checks passed
@weidongxu-microsoft
Weidong Xu (weidongxu-microsoft) deleted the fix/java-context-aware-yaml-reader branch October 30, 2026 01:34
Weidong Xu (weidongxu-microsoft) added a commit to Azure/typespec-azure that referenced this pull request Oct 30, 2026
…es (#5900)

## Summary

- sync Java generator to core `6ba281975`
- fix YAML structural-key collisions (microsoft/typespec#12434)
- preserve ARM resource ID parameters for shared-model routes
(microsoft/typespec#12443)
- sync regression fixtures and tests; retain version 0.48.4 for a
separate publish PR

## Validation

- emitter/generator build and client regeneration
- all 7 generated-client resource ID parsing regressions pass
- Chronus verification, formatting, and lint

The earlier SDK sync run 7018297 timed out at 120 minutes; it has not
been rerun for this update.

---------

Copilot-Session: cd6f2e08-d6d3-42ae-affd-bc71e98086f7
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