Fix sample generation for nested @bodyRoot parameters#3969
Open
JialinHuang803 wants to merge 1 commit into
Open
Fix sample generation for nested @bodyRoot parameters#3969JialinHuang803 wants to merge 1 commit into
JialinHuang803 wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When an operation has a
@bodyRootproperty nested inside a wrapper model (e.g.,body: { @bodyRoot stopParameters: StopParameters }), the generated sample code insamples-dev/was missing the requiredbodyparameter entirely.Root Cause
In
emitSamples.tsandexampleValueHelpers.ts,prepareExampleParametersusesbodyParam.name("stopParameters") as the example parameter name. However, the function signature parameter is the wrapper"body". When the reorder logic doesparamValueMap.get("body"), it returnsundefinedbecause the map key is"stopParameters", causing the body parameter to be dropped.Fix
Use
bodyParam.methodParameterSegmentsto detect nested body parameters. When nested (single path with >1 segments):Testing
Fixes #3968