Skip to content

Fix Go path API version overrides - #5151

Open
Chenjie Shi (tadelesh) wants to merge 8 commits into
Azure:mainfrom
tadelesh:tadelesh/go-path-api-version-override
Open

Fix Go path API version overrides#5151
Chenjie Shi (tadelesh) wants to merge 8 commits into
Azure:mainfrom
tadelesh:tadelesh/go-path-api-version-override

Conversation

@tadelesh

@tadelesh Chenjie Shi (tadelesh) commented Aug 4, 2026

Copy link
Copy Markdown
Member

Summary

  • make ClientOptions.APIVersion override a defaulted API version embedded in an operation path
  • preserve the generated API-version literal as the default and replace it only when the configured override is non-empty
  • derive path-override support from the client parameters already present in the code model, without adding adapter or code-model state
  • keep existing client-parameter collection, subclient behavior, and query/header API-version policy behavior unchanged
  • support ARM clients by normalizing nil options before reading options.APIVersion
  • restore the Azure API-version path Spector test that was previously skipped

Override algorithm

  1. For a directly constructable client with a defaulted path API-version parameter, the constructor copies ClientOptions.APIVersion into a private apiVersion field.
  2. Each request builder starts with its generated API-version literal.
  3. If the stored override is non-empty, the request builder uses it before escaping and substituting the path segment.
  4. Query and header API versions continue to use azcore's existing API-version policy behavior.

This keeps generated literals as the source of default versions and avoids relying on azcore's path API-version policy, which intentionally does not rewrite URL paths.

Tests

  • generated-code scenarios cover regular and ARM clients, including nil ARM options
  • the default path test runs against the Spector mock server
  • the override test uses a capture transport that returns HTTP 200 and asserts the outgoing request path, so it can verify an arbitrary API version without requiring mock-server support for that version
  • regenerated versionedgroup retains its existing query API-version policy and its handwritten test remains unchanged
  • typespec-go unit tests, repository formatting, and lint pass

Closes #4940

Store defaulted path API versions on generated clients so ClientOptions.APIVersion is applied while constructing request paths. Propagate the value and query/header policy metadata across sub-client hierarchies.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @azure-tools/typespec-go
Show changes

@azure-tools/typespec-go - fix ✏️

Honor ClientOptions.APIVersion for API versions emitted in operation paths.

@pkg-pr-new

pkg-pr-new Bot commented Aug 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-go@5151

commit: 2ef8117

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

@tadelesh
Chenjie Shi (tadelesh) marked this pull request as draft August 4, 2026 07:44
tadelesh and others added 5 commits August 4, 2026 18:06
Store only the configured API version override on generated clients. Path request builders now retain their generated literal and replace it only when ClientOptions.APIVersion is non-empty, including ARM and hierarchical clients.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
Normalize ARM options before reading APIVersion, keep literal API-version metadata on the constructable client, and restore the Azure path Spector request test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
Assume a client uses one API-version location, select its first API-version parameter, and remove mixed-location scenario coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
Keep existing client parameter collection unchanged and limit path override marking to the current constructable client.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
Derive path API-version override support from existing client parameters, fully restore the adapter, codemodel, and versionedgroup test, and cover the override in the path-specific Spector test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
@tadelesh
Chenjie Shi (tadelesh) marked this pull request as ready for review August 5, 2026 10:01
Chenjie Shi (tadelesh) and others added 2 commits August 5, 2026 18:01
Resolve the Go operations refactor by moving path API-version substitution into request-handler.ts and retaining constructor support in operations.ts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
@github-actions

Copy link
Copy Markdown
Contributor

📦 Package size report

✅ No notable package size changes compared to the base branch.

13 package(s) with no notable change
Package Packed (base → head) Δ Packed Unpacked (base → head) Δ Unpacked
@azure-tools/typespec-go 244.79 KB → 245.33 KB +556 B (+0.2%) 1.25 MB → 1.25 MB +2.87 KB (+0.2%)
@azure-tools/typespec-java 13.51 MB → 13.51 MB -57 B (-0.0%) 15.03 MB → 15.03 MB
@azure-tools/azure-http-specs 146.21 KB → 146.21 KB 1.16 MB → 1.16 MB
@azure-tools/typespec-autorest 80.93 KB → 80.93 KB 395.06 KB → 395.06 KB
@azure-tools/typespec-autorest-canonical 7.42 KB → 7.42 KB 26.00 KB → 26.00 KB
@azure-tools/typespec-azure-core 129.41 KB → 129.41 KB 702.62 KB → 702.62 KB
@azure-tools/typespec-azure-portal-core 42.40 KB → 42.40 KB 192.87 KB → 192.87 KB
@azure-tools/typespec-azure-resource-manager 171.29 KB → 171.29 KB 1.04 MB → 1.04 MB
@azure-tools/typespec-azure-rulesets 5.16 KB → 5.16 KB 32.09 KB → 32.09 KB
@azure-tools/typespec-client-generator-core 226.23 KB → 226.23 KB 1.22 MB → 1.22 MB
@azure-tools/typespec-metadata 15.91 KB → 15.91 KB 62.26 KB → 62.26 KB
@azure-tools/typespec-python 46.21 KB → 46.21 KB 180.83 KB → 180.83 KB
@azure-tools/typespec-ts 524.71 KB → 524.71 KB 2.53 MB → 2.53 MB

Packed = gzipped .tgz published to npm. Unpacked = total extracted size. 🆕 added, 🗑️ removed. Packages from the core/ submodule are not included.
🔴 grew · 🟢 shrank — only changes of at least 512 B and 0.5% are marked.

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

Labels

emitter:go Issues for @azure-tools/typespec-go emitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API version in path can't be changed by ClientOptions.APIVersion in some cases

1 participant