Skip to content

codegen: add file generator, templates, and CLI entry point (PRINFRA-121) - #14

Merged
somanshreddy merged 2 commits into
mainfrom
03-31-codegen_add_renderer_templates_and_cli_entry_point
Apr 1, 2026
Merged

somanshreddy merged 2 commits into
mainfrom
03-31-codegen_add_renderer_templates_and_cli_entry_point

Conversation

@somanshreddy

@somanshreddy somanshreddy commented Mar 31, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The output stage of the codegen pipeline. Takes the grouped command specs from the previous PR and writes them as Go source files.

What it produces: For each command group, a .go file with exported command.Spec variables. Plus a registry file that maps group names to their specs.

Example — given this grouper output:

command.Groups{
    "video": []*Spec{{Group: "video", Name: "list", Endpoint: "/v3/videos", Method: "GET"}},
}

The generator writes gen/video.go:

var VideoList = &command.Spec{
    Group:    "video",
    Name:     "list",
    Endpoint: "/v3/videos",
    Method:   "GET",
    ...
}

And gen/registry.go:

var Groups = command.Groups{
    "video": {VideoList, VideoGet, VideoCreate, VideoDelete},
}

How it works:

  • Generate() in generate.go iterates groups in sorted order, executes Go text/templates, and writes gofmt'd output
  • command.go.tmpl produces one file per group with all specs as exported vars. Variable names are PascalCase from group + command name (e.g., VideoList, WebhookEndpointsCreate)
  • registry.go.tmpl produces the Groups map that the runtime builder reads at startup
  • Template helpers: strcase.ToCamel for PascalCase, intPtrLiteral for min/max pointers, stringSlice for enum arrays

CLI entry point — go run ./codegen/ -spec <path> -out gen/ -examples codegen/examples.yaml orchestrates the full pipeline: load examples → load spec → group endpoints → validate examples → generate files. Fails if any command is missing examples.

make generate target — make generate SPEC=path/to/external-api.json clears gen/, runs codegen, formats output.

Testing

Tested via golden file tests in the next PR.

Files

  • codegen/generate.go — Generate function, template loading, gofmt, template helpers
  • codegen/main.go — CLI entry point with -spec, -out, -examples flags
  • codegen/templates/command.go.tmpl — per-group command file template
  • codegen/templates/registry.go.tmpl — registry map template
  • Makefile — added generate target

@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from 5a6a098 to a8b1753 Compare March 31, 2026 18:29
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from 803d72a to 1ac674a Compare March 31, 2026 18:29
@somanshreddy somanshreddy changed the title codegen: add renderer, templates, and CLI entry point codegen: add renderer, templates, and CLI entry point (PRINFRA-121) Mar 31, 2026
@linear

linear Bot commented Mar 31, 2026

Copy link
Copy Markdown
PRINFRA-121 CLI M1: OpenAPI codegen pipeline

Build the code generation pipeline that reads openapi/external-api.json and produces CommandSpec structs.

Scope

  • Go program in codegen/ using text/template
  • Parse OpenAPI spec, filter to v3 endpoints only
  • Generate CommandSpec data structs in gen/ (zero logic)
  • overrides.yaml for:
    • Positional arg promotion (prompt, text, file)
    • Command group naming (video-translations → translate, webhooks/endpoints → webhook)
    • Help examples per command
  • make generate SPEC=... target
  • Nested path collapsing (e.g., /webhooks/endpoints/{id}/rotate-secret → webhook rotate-secret)
  • Golden file tests for codegen output stability
  • Generate all ~30 commands, wire into Cobra at startup

Mapping Rules

  • OpenAPI tag → command group
  • POST → create, GET (list) → list, GET (by id) → get, DELETE → delete, PATCH → update
  • Path params → positional args, query params → flags, body fields → flags
  • overrides.yaml exceptions for positional promotion and group naming

Acceptance Criteria

  • make generate produces compilable CommandSpec files for all v3 endpoints
  • Adding a new endpoint to spec + re-running codegen produces new command
  • Generated help text includes descriptions and examples
  • Golden file tests pass
  • Override validation: make generate fails if overrides reference non-existent endpoints

@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from 1ac674a to 612f394 Compare March 31, 2026 19:41
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch 2 times, most recently from 0b9e0be to 2f5c57f Compare March 31, 2026 20:08
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from 612f394 to 16bd8ed Compare March 31, 2026 20:08
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from 2f5c57f to b3208f9 Compare March 31, 2026 20:59
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch 2 times, most recently from b29c389 to f03c006 Compare March 31, 2026 21:06
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from b3208f9 to 16055f5 Compare March 31, 2026 21:06
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from f03c006 to cfec8dd Compare March 31, 2026 21:25
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from 16055f5 to 7f8ff00 Compare March 31, 2026 21:25
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from cfec8dd to 868657e Compare March 31, 2026 21:31
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch 2 times, most recently from 8b6e2ae to 5e10411 Compare March 31, 2026 21:41
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from 868657e to 2c83785 Compare March 31, 2026 21:41
@somanshreddy somanshreddy changed the title codegen: add renderer, templates, and CLI entry point (PRINFRA-121) codegen: add renderer, templates, golden tests, and production overrides (PRINFRA-121) Mar 31, 2026
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from 5e10411 to a56bcde Compare March 31, 2026 21:55
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from 21f7dfa to c337bb8 Compare March 31, 2026 21:58
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch 2 times, most recently from 89b530d to 30040af Compare March 31, 2026 22:02
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch 2 times, most recently from 5a7da12 to a4d0678 Compare March 31, 2026 22:04
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from 5e0e76b to 1918c31 Compare April 1, 2026 07:23
@somanshreddy
somanshreddy changed the base branch from graphite-base/14 to 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm April 1, 2026 07:23
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from 1918c31 to 8e8040e Compare April 1, 2026 07:26
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from a61cb00 to 0a34434 Compare April 1, 2026 07:26
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from 8e8040e to ff74333 Compare April 1, 2026 07:41
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from 0a34434 to 23a6763 Compare April 1, 2026 07:41
@somanshreddy
somanshreddy changed the base branch from 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm to graphite-base/14 April 1, 2026 07:42
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from ff74333 to cb080cf Compare April 1, 2026 08:14
@somanshreddy
somanshreddy changed the base branch from graphite-base/14 to 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm April 1, 2026 08:14
@somanshreddy somanshreddy changed the title codegen: add renderer, templates, golden tests, and examples (PRINFRA-121) codegen: add renderer, templates, and CLI entry point (PRINFRA-121) Apr 1, 2026
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from cb080cf to c0cc301 Compare April 1, 2026 16:38
@somanshreddy somanshreddy changed the title codegen: add renderer, templates, and CLI entry point (PRINFRA-121) codegen: add generator, templates, and CLI entry point (PRINFRA-121) Apr 1, 2026
@somanshreddy somanshreddy changed the title codegen: add generator, templates, and CLI entry point (PRINFRA-121) codegen: add file generator, templates, and CLI entry point (PRINFRA-121) Apr 1, 2026
@somanshreddy
somanshreddy marked this pull request as ready for review April 1, 2026 16:49
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from c0cc301 to bc62a76 Compare April 1, 2026 17:01
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm branch from f6691d3 to 57dd9f1 Compare April 1, 2026 17:02
@somanshreddy
somanshreddy requested a review from jrusso1020 April 1, 2026 17:57

somanshreddy commented Apr 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

Merge activity

  • Apr 1, 7:16 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Apr 1, 7:20 PM UTC: Graphite rebased this pull request as part of a merge.
  • Apr 1, 7:22 PM UTC: @somanshreddy merged this pull request with Graphite.

@somanshreddy
somanshreddy changed the base branch from 03-31-codegen_add_endpoint_grouper_and_subcommand_naming_algorithm to graphite-base/14 April 1, 2026 19:18
@somanshreddy
somanshreddy changed the base branch from graphite-base/14 to main April 1, 2026 19:19
somanshreddy and others added 2 commits April 1, 2026 19:20
Go text/templates produce one file per command group + registry.go.
Renderer executes templates and runs gofmt. CLI entry point accepts
-spec, -out, -overrides flags and orchestrates the pipeline.
make generate target added.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Renderer executes Go text/templates to produce command.Spec struct
literals. CLI entry point orchestrates the full pipeline. make generate
target clears gen/ and runs codegen.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch from bc62a76 to 99252ba Compare April 1, 2026 19:20
@somanshreddy
somanshreddy merged commit 869b17e into main Apr 1, 2026
9 checks passed
@somanshreddy
somanshreddy deleted the 03-31-codegen_add_renderer_templates_and_cli_entry_point branch April 1, 2026 19:22
@somanshreddy somanshreddy added this to the M1: Codegen Pipeline milestone Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants