This repository was archived by the owner on Apr 14, 2026. It is now read-only.
Commit 382d8d7
Centralize import/helper tracking via CodegenContext and add behavioral tests for helper templates
Replace the scattered ParamUsageTracker and per-phase import collection
with a single CodegenContext that all generators share. This eliminates
duplicate param tracker creation across client, server, webhook, and
callback code paths, and moves import registration, helper tracking,
param function tracking, and custom type tracking into one place.
Key changes to code generation pipeline:
- Add CodegenContext (codegen_context.go) as the centralized tracker for
imports, helpers, param functions, and custom type templates
- Refactor Generate() in codegen.go into three phases: (1) generate all
code sections, (2) render helpers/params/custom types, (3) assemble
output — eliminating repeated param/form-helper generation per phase
- Remove ParamUsageTracker from paramgen.go; its logic is absorbed by
CodegenContext.NeedParam(), GetRequiredParamTemplates(), etc.
- Update TypeGenerator to delegate imports and template tracking to ctx
- Update GatherOperations, GatherWebhookOperations, and
GatherCallbackOperations to accept *CodegenContext instead of
*ParamUsageTracker
- Move loadCustomType into CodegenContext.loadAndRegisterCustomType so
custom type imports are registered directly on the context
Add behavioral tests for helper function templates (test/helpers/):
- genhelpers/main.go: CLI generator tool that reads ParamHelpersTemplate,
MarshalFormHelperTemplate, and ParamTemplates registries, writes
.gen.go files with goimports to prune unused imports
- 16 generated .gen.go files: helpers, marshal_form, plus style/bind for
simple, simple_explode, form, form_explode, label, label_explode,
and deepObject
- 7 test files (55 tests) covering marshalForm, primitiveToString,
BindStringToObject, Date, escape/unescape, and roundtrip
style-then-bind for all parameter styles
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 32c2089 commit 382d8d7
34 files changed
Lines changed: 3417 additions & 474 deletions
File tree
- experimental/internal/codegen
- templates/test/helpers
- genhelpers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
106 | | - | |
| 105 | + | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
| 134 | + | |
| 135 | + | |
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
| |||
0 commit comments