Skip to content

codegen: add OpenAPI spec parser (PRINFRA-121) - #12

Closed
somanshreddy wants to merge 1 commit into
graphite-base/12from
03-31-codegen_add_openapi_spec_parser
Closed

somanshreddy wants to merge 1 commit into
graphite-base/12from
03-31-codegen_add_openapi_spec_parser

Conversation

@somanshreddy

@somanshreddy somanshreddy commented Mar 31, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Reads an OpenAPI 3.1 JSON spec and extracts the structured data needed for CLI command generation. This is the first stage of the codegen pipeline: raw spec → parsed endpoints.

Key parsing behaviors:

  • $ref resolution — dereferences request body schema references (one level deep)
  • Pydantic nullable handling — recognizes the `anyOf: [{type: T}, {type: null}]` pattern from HeyGen's Python-generated spec and extracts the real type
  • Field classification — categorizes each request body field as simple (scalar or array-of-scalar → becomes a CLI flag) or complex (nested object, discriminated union → omitted from flags, users reach it via --json-body)
  • Pagination detection — identifies list endpoints by looking for `has_more` boolean + a token field in the response schema
  • Multipart detection — identifies file upload endpoints from `multipart/form-data` content type
  • Type mapping — OpenAPI types to CLI flag types: string→string, integer→int, boolean→bool, number→float64, array of strings→string-slice

Output is a flat list of parsed endpoints. The grouper (next PR) organizes them into command groups.

Testing

Tested via golden file tests in a later PR. The parser is exercised by the full pipeline test with a mini OpenAPI spec covering all patterns.

Files

  • codegen/parser.go — Parse(), $ref resolution, field classification, pagination/multipart detection, x-cli-visible filtering

somanshreddy commented Mar 31, 2026 •

Copy link
Copy Markdown
Collaborator Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@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_openapi_spec_parser branch from 5b95564 to 735c417 Compare March 31, 2026 19:41
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_overrides_system_for_group_renames_skip_patterns_positional_promotions branch from 0963cc3 to 24ee2cb Compare March 31, 2026 19:41
Reads OpenAPI JSON, resolves \$ref references, extracts endpoints with
params and body fields. Handles Pydantic nullable pattern (anyOf with
null), classifies body fields as simple (→ flag) or complex (→ skip),
detects pagination (has_more + token field), detects multipart.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@somanshreddy
somanshreddy force-pushed the 03-31-codegen_add_openapi_spec_parser branch from 735c417 to 3511ac2 Compare March 31, 2026 20:08
@somanshreddy
somanshreddy changed the base branch from 03-31-codegen_add_overrides_system_for_group_renames_skip_patterns_positional_promotions to graphite-base/12 March 31, 2026 20:59
@somanshreddy

Copy link
Copy Markdown
Collaborator Author

Closed — parser merged into grouper. kin-openapi types used directly, no intermediate ParsedEndpoint.

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.

1 participant