Skip to content

feat(typespec-go): emit apiview-properties.json with cross-language definition IDs - #5112

Open
Chenjie Shi (tadelesh) wants to merge 8 commits into
mainfrom
tadelesh/go-apiview-properties
Open

feat(typespec-go): emit apiview-properties.json with cross-language definition IDs#5112
Chenjie Shi (tadelesh) wants to merge 8 commits into
mainfrom
tadelesh/go-apiview-properties

Conversation

@tadelesh

@tadelesh Chenjie Shi (tadelesh) commented Jul 30, 2026

Copy link
Copy Markdown
Member

Fixes #4931

What

The Go emitter now writes testdata/apiview-properties.json alongside testdata/_metadata.json. It maps the Go APIView parser's line IDs for generated models, enums, enum values, clients, client factories, constructors, and methods to their TCGC crossLanguageDefinitionId values.

Line IDs

Keys match src/go/cmd/token_makers.go:

Symbol Line ID
Struct / enum / enum value / client <rel>.<Name>
Package-level function <rel>-<FunctionName>
Method <rel>-(<receiver> <receiverType>) <MethodName>

<rel> is the package path relative to the module root, with a /vN module suffix removed. For containing-module, the emitter uses the nearest go.mod to compute the complete relative path. If the module root is unavailable or does not contain the output path, it falls back to the output directory name.

Method names use fixUpMethodName, so LRO and pageable methods match their generated Begin<Name> and New<Name>Pager names. Only exported symbols are included.

Implementation

  • Threads crossLanguageDefinitionId from TCGC through the Go code model and carries crossLanguageVersion on Info.
  • Walks the generated package tree and emits a deterministic, sorted mapping, including ARM ClientFactory, NewClientFactory, and every New<Client> accessor.
  • Falls back to the output directory name when a module-relative path cannot be computed, preserving the previous behavior without blocking generation.

Notes

The APIView side is tracked by Azure/azure-sdk-tools#4282. This PR supplies the emitter metadata it will consume.

Validation

  • 52/52 unit tests pass, including module-root and multi-level containing-module paths
  • TypeScript build, oxlint, Prettier, and cspell clean
  • Real containingmod/v2 fixture generates APIView IDs prefixed with containingmod/subpkg

…efinition IDs

Emits `testdata/apiview-properties.json` mapping the line IDs produced by the
Go APIView parser to their TCGC `crossLanguageDefinitionId`, so APIView can
link the Go API surface to the other languages.

Covered symbols: models (incl. polymorphic), enums, enum values, clients,
client constructors, the ARM `ClientFactory` accessors, and client methods.
The file also carries `CrossLanguagePackageId` and `CrossLanguageVersion`.

Fixes #4931

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

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @azure-tools/typespec-go
Show changes

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

Emit testdata/apiview-properties.json mapping the Go APIView line IDs of the generated models, enums, enum values, clients, client factories, constructors and methods to their TCGC cross-language definition IDs, so APIView can link the Go API surface to the other languages.

@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Go emitter diff

Baseline gh:7c0c271f206bed1937962ca12b920e555588995e vs this PR.

Diff summary: 112 file(s), +3270 / -0

Rendered diff: inline on the run summary, or the emitter-diff-go-html artifact.

Informational check (core/eng/emitter-diff); does not block the PR.

@pkg-pr-new

pkg-pr-new Bot commented Jul 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: f9cf989

@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 July 30, 2026 08:25
Comment thread packages/typespec-go/test/unittest/scenarios/apiview-properties.md Outdated
Comment thread packages/typespec-go/src/codegen/core/apiview-properties.ts
Comment thread packages/typespec-go/src/codegen/core/apiview-properties.ts Outdated
tadelesh added 2 commits July 30, 2026 17:28
- emit apiview-properties.json for ContainingModule roots as well
- add azblob to the cspell word list

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

Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
Compute the full package path relative to the existing module's go.mod so root and nested package IDs match the Go APIView parser.

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

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

Copy link
Copy Markdown
Member Author

Fixed containing-module LineID qualification in c680046. The emitter now derives the complete package path from emitter-output-dir relative to the nearest go.mod, matching APIView Pkg.Name() for module-root, one-level, and multi-level packages. Added root and nested scenario coverage.

Keep using the output directory name when the containing module root is unavailable or does not contain the output path.

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

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

Copy link
Copy Markdown
Member Author

Adjusted in d4c3bc5: removed the new containing-module validation. The full path is used when the nearest go.mod establishes containment; otherwise generation continues and falls back to the output directory name. Added fallback scenario coverage.

Keep filesystem path resolution out of the TCGC adapter and apply it after code model construction.

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

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

Copy link
Copy Markdown
Member Author

Refactored in c2b648a. Adapter is restored to its original API and construction logic. $onEmit now applies the module-relative path after code model creation; the scenario runner mirrors only that orchestration step. The fallback remains in apiview-properties.ts.

Include ClientFactory, NewClientFactory, and verify each New<Client> accessor in APIView cross-language metadata.

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

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

Copy link
Copy Markdown
Member Author

Added the missing ARM factory symbols in 5dea213: ClientFactory and NewClientFactory map to the package cross-language ID, while every (c *ClientFactory) New<Client> method maps to that client's cross-language ID. The ARM scenario now has two clients to verify all accessors are included.

@tadelesh
Chenjie Shi (tadelesh) marked this pull request as ready for review August 3, 2026 08:03
Comment thread packages/typespec-go/src/codegen/core/apiview-properties.ts Outdated
Comment thread packages/typespec-go/src/codemodel/module.ts Outdated
tadelesh and others added 2 commits August 4, 2026 10:53
Require TCGC package metadata and pass containing-module paths directly to APIView generation instead of storing filesystem state in the Go code model.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a2fed377-7b26-45fc-b3aa-8b6d6df8b46a
Resolve TypeSpec Go emitter refactors while retaining APIView metadata generation.

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

Copilot-Session: 686715d2-367d-4fd7-a242-3e003b6b796c
@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 253.41 KB → 254.04 KB +648 B (+0.2%) 1.29 MB → 1.29 MB +3.66 KB (+0.3%)
@azure-tools/typespec-java 13.51 MB → 13.51 MB +79 B (+0.0%) 15.03 MB → 15.03 MB
@azure-tools/azure-http-specs 146.63 KB → 146.63 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.43 KB → 129.43 KB 702.77 KB → 702.77 KB
@azure-tools/typespec-azure-portal-core 42.40 KB → 42.40 KB 192.91 KB → 192.91 KB
@azure-tools/typespec-azure-resource-manager 171.16 KB → 171.16 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.69 KB → 226.69 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 42.20 KB → 42.20 KB 164.85 KB → 164.85 KB
@azure-tools/typespec-ts 527.17 KB → 527.17 KB 2.54 MB → 2.54 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.

Output cross-language definition IDs

2 participants