You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(typespec-client-generator-core): support per-service api-version map for multi-service packages (#4650)
Fixes#4009
## Summary
Extends the TCGC `api-version` emitter option to accept either a
`string` or a `Record<string, string>` (a map from each service
namespace's full name to its desired version), enabling per-service
version selection for multi-service packages.
## Behavior
- **`string`** (e.g. `"2024-10-01"`): applies to single-service packages
only. Ignored for multi-service.
- **`"latest"`**: global keyword, applies regardless of service count.
- **`"all"`**: single-service only. **Multi-service packages do not
support `all`** (in either string or map form) — it is ignored and each
service falls back to its latest version.
- **`Record<string, string>`** (e.g. `{ "ServiceA": "av1", "ServiceB":
"bv2" }`): maps each service namespace full name to a version. Services
not listed default to their latest version.
## Implementation notes
- Added `resolveApiVersionForService` as the single source of truth for
resolving the version that applies to a given service.
- `getServiceNamespaces` is memoized on the context
(`__serviceNamespaces`) since it is consulted on the per-type hot path
via `getAvailableApiVersions`.
- `handleVersioningMutationForGlobalNamespace` now mutates each service
independently using its resolved version.
## Validation
- Added multi-service map tests (per-service versions, fallback to
latest, `all` ignored).
- Full TCGC suite: 1330 passed / 2 skipped. TypeScript build and ESLint
clean.
---------
Co-authored-by: tadelesh <chenjieshi@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: iscai-msft <isabellavcai@gmail.com>
Support a per-service `api-version` map for multi-service packages. The `api-version` emitter option now accepts either a string (applied to single service packages, or the `latest`/`all` keywords) or a map from each service namespace's full name to its desired version. Services not listed in the map default to their latest version.
Copy file name to clipboardExpand all lines: packages/typespec-client-generator-core/README.md
+7-2Lines changed: 7 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,9 +62,14 @@ When set to `true`, the emitter will generate convenience methods for each servi
62
62
63
63
### `api-version`
64
64
65
-
**Type:** `string`
65
+
**Type:** `string | object`
66
+
67
+
Use this flag if you would like to generate the sdk only for a specific version. Default value is the latest version. Also accepts values `latest` and `all`. For multi-service packages, provide a map from each service namespace's full name to its desired version; services not listed default to their latest version.
68
+
69
+
**Options:**
66
70
67
-
Use this flag if you would like to generate the sdk only for a specific version. Default value is the latest version. Also accepts values `latest` and `all`.
Copy file name to clipboardExpand all lines: packages/typespec-client-generator-core/src/lib.ts
+20-6Lines changed: 20 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,25 @@ import {
5
5
UnbrandedSdkEmitterOptionsInterface,
6
6
}from"./internal-utils.js";
7
7
8
+
// `api-version` accepts either a string (single service / `latest` / `all`) or a
9
+
// map from service namespace full name to version (multi-service).
10
+
constapiVersionSchema={
11
+
oneOf: [
12
+
{
13
+
type: "string",
14
+
nullable: true,
15
+
},
16
+
{
17
+
type: "object",
18
+
additionalProperties: {type: "string"},
19
+
required: [],
20
+
nullable: true,
21
+
},
22
+
],
23
+
description:
24
+
"Use this flag if you would like to generate the sdk only for a specific version. Default value is the latest version. Also accepts values `latest` and `all`. For multi-service packages, provide a map from each service namespace's full name to its desired version; services not listed default to their latest version.",
"Use this flag if you would like to generate the sdk only for a specific version. Default value is the latest version. Also accepts values `latest` and `all`.",
0 commit comments