Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.

Centralize import/helper tracking via CodegenContext and add behavior…#7

Merged
mromaszewicz merged 2 commits intomainfrom
feat/import-handling
Feb 8, 2026
Merged

Centralize import/helper tracking via CodegenContext and add behavior…#7
mromaszewicz merged 2 commits intomainfrom
feat/import-handling

Conversation

@mromaszewicz
Copy link
Copy Markdown
Member

…al 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

mromaszewicz and others added 2 commits February 7, 2026 23:16
…al 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>
@mromaszewicz mromaszewicz merged commit 97b43ac into main Feb 8, 2026
4 checks passed
@mromaszewicz mromaszewicz deleted the feat/import-handling branch February 8, 2026 07:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant