Skip to content

[http-client-python] Keep REST example values for client-renamed body parameters - #12688

Open
Minh Triet Nguyen (binnguyenx) wants to merge 1 commit into
microsoft:mainfrom
binnguyenx:python/body-rename-sample-values
Open

Minh Triet Nguyen (binnguyenx) wants to merge 1 commit into
microsoft:mainfrom
binnguyenx:python/body-rename-sample-values

Conversation

@binnguyenx

Copy link
Copy Markdown
Contributor

Fixes #12433

Problem

When an explicitly named request body is renamed only for the client (for example @body @clientName("topic") resource: Topic), generated samples use placeholder values instead of the REST example's values:

# before
client.topics.create_or_replace(topic={"state": "str", "title": "str"})

emitHttpBodyParameter set the body's wireName to TCGC's name, which already includes the client rename. sample_serializer.py looks up example values with self.sample_params.get(param.wire_name), and the raw example is still keyed by the REST name (resource), so the lookup missed.

Fix

Use bodyParam.serializedName for the body's wireName. clientName is unchanged, and implicit (generated-name) bodies still use "body".

# after
client.topics.create_or_replace(topic={"state": "Normal", "title": "Product updates"})

I checked the generator for other readers of a body parameter's wire_name: the multipart path reads the wire names of the body's entries, and the _headers / _params pop path only handles header and query parameters. So this changes sample output only, not request serialization.

Tests

  • New emitter test covering a client-renamed body (clientName: "topic", wireName: "resource"), an explicit unrenamed body, and a spread body (body / body). It fails without the fix.
  • All emitter tests pass (76/76), and the emitter type-checks.
  • End-to-end: generated a small SDK with generate-sample: true and a REST example keyed by resource. Without the fix the sample has "str" placeholders; with the fix it has the example values.

Note

#12480 took the same approach and was closed without merging or comments. If that approach was rejected for a reason, please let me know and I'll rework this.

… parameters

An explicitly named request body used TCGC's `name` as its wire name, which
already includes client-only renames such as `@clientName`. Sample generation
looks up REST example values by wire name, so a renamed body missed its example
entry and fell back to placeholder values. Use `serializedName` instead; the
SDK-facing client name is unchanged.

Fixes microsoft#12433
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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 Python client sample-generation fix.

No open issues 🎉

What changed in this PR

Fixes #12433 by preserving REST example lookup names in the Python client emitter, so client-only body parameter renames no longer cause generated samples to use placeholders.

Changes:

  • Uses serializedName for explicit body wire names, preserving client-facing names and the generated "body" fallback.
  • Adds emitter regression coverage for renamed, unrenamed, and spread bodies.
  • Adds a changelog entry describing the sample-generation fix.
File Description
packages/​http-client-python/​emitter/​test/​emitter.test.ts Verifies client and wire names for three body parameter cases.
packages/​http-client-python/​emitter/​src/​http.ts Preserves the REST body name for example lookup.
.chronus/​changes/​python-body-rename-sample-values-2026-10-30-17-0-0.md Documents the Python sample-generation fix.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:python Issue for the Python client emitter: @typespec/http-client-python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Python sample generation loses REST body example values when the SDK parameter is renamed

2 participants