Skip to content

feat(typespec-metadata): add apiVersion field using TCGC resolution - #5065

Open
iscai-msft wants to merge 19 commits into
Azure:mainfrom
iscai-msft:iscai-msft-add-apiversion-to-metadata
Open

feat(typespec-metadata): add apiVersion field using TCGC resolution#5065
iscai-msft wants to merge 19 commits into
Azure:mainfrom
iscai-msft:iscai-msft-add-apiversion-to-metadata

Conversation

@iscai-msft

Copy link
Copy Markdown
Contributor

Summary

Adds an apiVersion field to the LanguagePackageMetadata interface in packages/typespec-metadata, resolved via createSdkContext from @azure-tools/typespec-client-generator-core.

Changes

  • src/metadata.ts: Added apiVersion?: string to LanguagePackageMetadata with doc comment explaining possible values
  • src/emitter.ts: Calls createSdkContext and resolves sdkPackage.metadata.apiVersions map
  • src/collector.ts: Threads resolvedApiVersion through collectLanguagePackagesbuildLanguageMetadatacreateLanguageMetadata
  • package.json: Added @azure-tools/typespec-client-generator-core as "workspace:^" dependency
  • test/collector.test.ts: Added "apiVersion extraction" describe block with 5 tests

Resolution Logic

Map state Resolved value
size > 1 "multiple-versions"
size == 1 The single value ("all" or actual version like "2023-10-01")
empty/undefined undefined

@iscai-msft
iscai-msft force-pushed the iscai-msft-add-apiversion-to-metadata branch from f3029f1 to a532259 Compare July 27, 2026 15:11
Add apiVersion to LanguagePackageMetadata interface, resolved via
createSdkContext from @azure-tools/typespec-client-generator-core.

Resolution logic:
- Map size > 1 → "multiple-versions"
- Map size == 1 → the single value ("all" or actual version string)
- Empty/undefined → undefined

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c95a24d5-2785-44e4-9599-ac2f5cb37a2c
@iscai-msft
iscai-msft force-pushed the iscai-msft-add-apiversion-to-metadata branch from a532259 to 0ce39ea Compare July 27, 2026 15:12
iscai-msft and others added 6 commits July 27, 2026 11:16
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c95a24d5-2785-44e4-9599-ac2f5cb37a2c
Add integration tests that compile TypeSpec input and verify the
apiVersions map from TCGC, matching the test style in
typespec-client-generator-core/test/package/api-versions-metadata.test.ts.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c95a24d5-2785-44e4-9599-ac2f5cb37a2c
… output

Tests now compile TypeSpec input, run the full emitter, and assert
the apiVersion field on the emitted metadata snapshot (not just the
TCGC map). Also adds api-version as a passthrough emitter option.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c95a24d5-2785-44e4-9599-ac2f5cb37a2c
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c95a24d5-2785-44e4-9599-ac2f5cb37a2c
The e2e tests in api-version.test.ts fully cover apiVersion behavior
by testing the actual emitter output.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c95a24d5-2785-44e4-9599-ac2f5cb37a2c
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c95a24d5-2785-44e4-9599-ac2f5cb37a2c
* - An actual resolved version string (e.g. `"2023-10-01"`) for a single version
* - `undefined` when no API version information is available
*/
apiVersion?: string;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in language metadata or typespec metadata? Is it possible to have different API version value for each language?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, I guess each language could specify different values in tspconfig.yaml, so it shouldn't be the case but it could be

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you prefer to ignore that possibility and move it to typespec metadata, or keep it where it is in language metadata

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. Let's keep it in language metadata. It's easier to parse all get the distinct on the consumer side.

Comment thread packages/typespec-metadata/test/tester.ts Outdated
The lockfile was generated with internal registry URLs that fail CI
tarball verification. workspace:^ dependencies don't need lockfile changes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c95a24d5-2785-44e4-9599-ac2f5cb37a2c
@iscai-msft
iscai-msft force-pushed the iscai-msft-add-apiversion-to-metadata branch from 17f535c to 2a8df3d Compare July 27, 2026 15:58
@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @azure-tools/typespec-metadata
Show changes

@azure-tools/typespec-metadata - feature ✏️

Add apiVersion field to LanguagePackageMetadata resolved via TCGC's createSdkContext. Values: "all" when configured for all versions, "multiple-versions" for multi-service configs, the actual resolved version string, or undefined when unavailable. Also adds api-version as a passthrough emitter option.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7d63e253-0c42-46ea-88b1-3e0aa1dddebe
@pkg-pr-new

pkg-pr-new Bot commented Jul 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-metadata@5065

commit: 897c048

…erTester

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c95a24d5-2785-44e4-9599-ac2f5cb37a2c
@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

iscai-msft and others added 5 commits July 27, 2026 14:47
… for passthrough

Remove api-version from MetadataEmitterOptions and its schema since TCGC
reads it directly from EmitContext. Set additionalProperties: true so
unknown options like api-version pass through in tspconfig without
validation errors.

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

Read apiVersion directly from sdkContext (which TCGC populates from
context.options["api-version"]) to handle the 'all' case. Fall back to
resolved apiVersions map for specific version resolution.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 75e5e691-2de3-4305-9855-bee4534c6690
api-version passthrough is not needed — TCGC resolves versions from
TypeSpec versioning decorators when no explicit api-version is configured.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 75e5e691-2de3-4305-9855-bee4534c6690
…tadata

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 75e5e691-2de3-4305-9855-bee4534c6690
Add an isPreview boolean field to sdkPackage.metadata so consumers can
determine if the SDK targets preview API versions without recomputing
from version strings.

- true if any targeted API version matches the preview string regex
- false if all versions are stable
- undefined if no versioning is present

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4d3f5528-7e0e-4828-ab85-b85ba9dffc5d
@microsoft-github-policy-service microsoft-github-policy-service Bot added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Jul 27, 2026
@iscai-msft
iscai-msft force-pushed the iscai-msft-add-apiversion-to-metadata branch from f89aac7 to f82a9fb Compare July 27, 2026 19:31
Resolves whether the SDK targets preview or stable API versions by checking
client apiVersions against TCGC's previewStringRegex. The @previewVersion
decorator case will be handled once TCGC exposes isPreview on its metadata.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c95a24d5-2785-44e4-9599-ac2f5cb37a2c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants