Skip to content

Refactor operations.ts - #5185

Merged
Joel Hendrix (jhendrixMSFT) merged 1 commit into
Azure:mainfrom
jhendrixMSFT:go-op-refactor
Aug 7, 2026
Merged

Refactor operations.ts#5185
Joel Hendrix (jhendrixMSFT) merged 1 commit into
Azure:mainfrom
jhendrixMSFT:go-op-refactor

Conversation

@jhendrixMSFT

Copy link
Copy Markdown
Member

Split monolithic file into three files so it's easier to reason about. Added barrel files to clarify external APIs used by the emitter. Moved shared functions to helpers.ts.
Simplified a few bits of code to avoid more shared helpers.

No functional changes.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @azure-tools/typespec-go
Show changes

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

Split operations.ts into three files to better contain dependent code.

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.

Pull request overview

This PR refactors the TypeSpec Go emitter’s operation-generation implementation by extracting request/response handler generation into dedicated modules and introducing barrel (index.ts) exports for clearer API surfaces. The intent is improved readability/maintainability with no intended functional change, but I found a real behavioral bug introduced/retained in the new response-handler implementation.

Changes:

  • Split request/response handler generation out of core/operations.ts into core/request-handler.ts and core/response-handler.ts.
  • Added barrel exports for core/* and fake/* and updated the main emitter to import through them.
  • Moved shared helpers (e.g., fixUpMethodName, getClientReceiverDefinition, media/time helpers) into core/helpers.ts and updated call sites.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/typespec-go/src/codegen/fake/servers.ts Switches fixUpMethodName usage to helpers.fixUpMethodName after helper relocation.
packages/typespec-go/src/codegen/fake/index.ts New barrel exporting fake server generators.
packages/typespec-go/src/codegen/emitter.ts Refactors imports to use core/index.ts + fake/index.ts barrels.
packages/typespec-go/src/codegen/core/response-handler.ts New extracted response-handler generator (contains a confirmed unmarshal target bug).
packages/typespec-go/src/codegen/core/request-handler.ts New extracted request-handler generator (large move of existing logic).
packages/typespec-go/src/codegen/core/operations.ts Integrates new request/response handler modules and removes inlined implementations.
packages/typespec-go/src/codegen/core/index.ts New barrel exporting core generators used by the emitter.
packages/typespec-go/src/codegen/core/helpers.ts Adds/moves shared helper APIs (method naming, receiver formatting, media/time helpers).
packages/typespec-go/src/codegen/core/example.ts Updates example generation to use helpers.fixUpMethodName.
.chronus/changes/go-op-refactor-2026-7-6-15-44-32.md Adds internal changelog entry for the refactor.
Suppressed comments (2)

packages/typespec-go/src/codegen/core/response-handler.ts:160

  • generateResponseUnmarshaller() assigns array-of-datetime results to result.<field> instead of the provided unmarshalTarget, so callers that unmarshal into a temp var (e.g. val in the anyResult switch) won't work correctly.
    unmarshallerText += `${indent.get()}result.${helpers.getResultFieldName(method)} = cp\n`;

packages/typespec-go/src/codegen/core/response-handler.ts:173

  • generateResponseUnmarshaller() assigns map-of-datetime results to result.<field> instead of the provided unmarshalTarget, which will generate incorrect code when the unmarshaller is used with a local variable target.
    unmarshallerText += `${indent.get()}result.${helpers.getResultFieldName(method)} = cp\n`;

Comment thread packages/typespec-go/src/codegen/core/response-handler.ts Outdated
Comment thread packages/typespec-go/src/codegen/core/operations.ts Outdated
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

📦 Package size report

2 packages changed size compared to the base branch.

Package Packed (base → head) Δ Packed Unpacked (base → head) Δ Unpacked
@azure-tools/typespec-go 259.35 KB → 244.29 KB -15.06 KB (-5.8%) 1.34 MB → 1.24 MB -93.26 KB (-6.8%)
@azure-tools/typespec-java 13.51 MB → 13.51 MB -28 B (-0.0%) 15.03 MB → 15.03 MB
43 unchanged package(s)
Package Packed (base → head) Δ Packed Unpacked (base → head) Δ Unpacked
@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 127.87 KB → 127.87 KB 695.48 KB → 695.48 KB
@azure-tools/typespec-azure-portal-core 42.26 KB → 42.26 KB 192.36 KB → 192.36 KB
@azure-tools/typespec-azure-resource-manager 171.18 KB → 171.18 KB 1.04 MB → 1.04 MB
@azure-tools/typespec-azure-rulesets 5.15 KB → 5.15 KB 31.73 KB → 31.73 KB
@azure-tools/typespec-client-generator-core 225.96 KB → 225.96 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.22 KB → 46.22 KB 180.83 KB → 180.83 KB
@azure-tools/typespec-ts 524.66 KB → 524.66 KB 2.53 MB → 2.53 MB
@typespec/asset-emitter 33.73 KB → 33.73 KB 158.67 KB → 158.67 KB
@typespec/bundler 11.31 KB → 11.31 KB 41.97 KB → 41.97 KB
@typespec/compiler 762.04 KB → 762.04 KB 3.88 MB → 3.88 MB
@typespec/emitter-framework 273.87 KB → 273.87 KB 1.50 MB → 1.50 MB
@typespec/events 8.96 KB → 8.96 KB 35.22 KB → 35.22 KB
@typespec/graphql 131.35 KB → 131.35 KB 544.77 KB → 544.77 KB
@typespec/html-program-viewer 53.96 KB → 53.96 KB 218.99 KB → 218.99 KB
@typespec/http 103.94 KB → 103.94 KB 511.18 KB → 511.18 KB
@typespec/http-canonicalization 74.18 KB → 74.18 KB 478.11 KB → 478.11 KB
@typespec/http-client 56.51 KB → 56.51 KB 281.75 KB → 281.75 KB
@typespec/http-client-js 219.98 KB → 219.98 KB 1.06 MB → 1.06 MB
@typespec/http-server-csharp 100.97 KB → 100.97 KB 409.91 KB → 409.91 KB
@typespec/http-server-js 259.10 KB → 259.10 KB 1.27 MB → 1.27 MB
@typespec/http-specs 182.15 KB → 182.15 KB 1.26 MB → 1.26 MB
@typespec/json-schema 31.66 KB → 31.66 KB 155.69 KB → 155.69 KB
@typespec/library-linter 4.35 KB → 4.35 KB 12.71 KB → 12.71 KB
@typespec/mutator-framework 71.87 KB → 71.87 KB 462.42 KB → 462.42 KB
@typespec/openapi 20.62 KB → 20.62 KB 91.67 KB → 91.67 KB
@typespec/openapi3 160.96 KB → 160.96 KB 824.53 KB → 824.53 KB
@typespec/playground 59.09 KB → 59.09 KB 239.02 KB → 239.02 KB
@typespec/prettier-plugin-typespec 157.35 KB → 157.35 KB 817.89 KB → 817.89 KB
@typespec/protobuf 94.53 KB → 94.53 KB 400.95 KB → 400.95 KB
@typespec/rest 24.18 KB → 24.18 KB 125.95 KB → 125.95 KB
@typespec/spec-api 46.54 KB → 46.54 KB 210.02 KB → 210.02 KB
@typespec/spec-coverage-sdk 41.83 KB → 41.83 KB 190.89 KB → 190.89 KB
@typespec/spector 139.66 KB → 139.66 KB 590.91 KB → 590.91 KB
@typespec/sse 5.66 KB → 5.66 KB 19.01 KB → 19.01 KB
@typespec/streams 4.12 KB → 4.12 KB 12.47 KB → 12.47 KB
@typespec/tspd 97.82 KB → 97.82 KB 430.99 KB → 430.99 KB
@typespec/versioning 36.69 KB → 36.69 KB 201.84 KB → 201.84 KB
@typespec/xml 9.41 KB → 9.41 KB 39.14 KB → 39.14 KB
tmlanguage-generator 5.00 KB → 5.00 KB 15.32 KB → 15.32 KB

Packed = gzipped .tgz published to npm. Unpacked = total extracted size. 🆕 added, 🗑️ removed.

@pkg-pr-new

pkg-pr-new Bot commented Aug 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 3013ad9

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

Split monolithic file into three files so it's easier to reason about.
Added barrel files to clarify external APIs used by the emitter.
Moved shared functions to helpers.ts.
Simplified a few bits of code to avoid more shared helpers.
@jhendrixMSFT
Joel Hendrix (jhendrixMSFT) added this pull request to the merge queue Aug 7, 2026
Merged via the queue into Azure:main with commit 5f0eaa9 Aug 7, 2026
38 checks passed
@jhendrixMSFT
Joel Hendrix (jhendrixMSFT) deleted the go-op-refactor branch August 7, 2026 17:11
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.

3 participants