Skip to content

Fix sample generation for nested @bodyRoot parameters#3969

Open
JialinHuang803 wants to merge 1 commit into
Azure:mainfrom
JialinHuang803:fix/sample-nested-bodyroot
Open

Fix sample generation for nested @bodyRoot parameters#3969
JialinHuang803 wants to merge 1 commit into
Azure:mainfrom
JialinHuang803:fix/sample-nested-bodyroot

Conversation

@JialinHuang803
Copy link
Copy Markdown
Member

Problem

When an operation has a @bodyRoot property nested inside a wrapper model (e.g., body: { @bodyRoot stopParameters: StopParameters }), the generated sample code in samples-dev/ was missing the required body parameter entirely.

Root Cause

In emitSamples.ts and exampleValueHelpers.ts, prepareExampleParameters uses bodyParam.name ("stopParameters") as the example parameter name. However, the function signature parameter is the wrapper "body". When the reorder logic does paramValueMap.get("body"), it returns undefined because the map key is "stopParameters", causing the body parameter to be dropped.

Fix

Use bodyParam.methodParameterSegments to detect nested body parameters. When nested (single path with >1 segments):

  1. Use the first segment's name as the parameter name (the method-level wrapper)
  2. Wrap the example value with the intermediate property names to match the wrapper structure

Testing

  • All 639 unit tests pass
  • Regenerated networkGateway smoke test confirms sample now correctly includes the body parameter

Fixes #3968

When an operation has a @bodyRoot property nested inside a wrapper model,
the sample generator was dropping the body parameter due to a name mismatch
between the TCGC body param name and the method signature parameter name.

Use bodyParam.methodParameterSegments to detect nested body params and
resolve the correct method-level parameter name, wrapping the example value
in the appropriate wrapper structure.

Fixes Azure#3968

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

Sample generation missing body parameter for nested @bodyRoot operations

1 participant