Skip to content

feat: wire up --data/--file flags and flatten allOf for body flag generation#4

Open
joshuayoes wants to merge 3 commits intovercel-labs:mainfrom
joshuayoes:feat/request-body-flags
Open

feat: wire up --data/--file flags and flatten allOf for body flag generation#4
joshuayoes wants to merge 3 commits intovercel-labs:mainfrom
joshuayoes:feat/request-body-flags

Conversation

@joshuayoes
Copy link

@joshuayoes joshuayoes commented Mar 23, 2026

Summary

  • Register --data and --file as CLI options for operations with request bodies. These were documented in the README but never wired into Commander. The existing loadBody() in body.ts was dead code — this connects it to buildRequest() in the request pipeline.
  • Flatten allOf schema compositions before generating body field flags. generateBodyFlags() previously required direct type: "object" + properties on the schema, which failed for specs using allOf (e.g. the YNAB API's ExistingTransaction). Added flattenAllOf() to recursively merge composed schemas.
  • Handle OpenAPI 3.1 nullable type arrays. Fields with type: ["string", "null"] were silently skipped by collectFlags() since it only matched scalar type strings. Added resolveType() to extract the non-null type from array-style nullable types.

--data / --file

Operations with a requestBody now accept:

Flag Description
--data <json> Inline request body
--file <path> Read request body from file

These take priority over expanded body field flags. Using both is an error.

allOf flattening

Before:

$ mycli update-item --help
# No body field flags shown for allOf-composed schemas

After:

$ mycli update-item --help
Options:
  --item.name <string>
  --item.amount <integer>
  ...

OpenAPI 3.1 nullable types

Fields using type: ["string", "null"] (OpenAPI 3.1 nullable syntax) now generate flags. Previously only scalar type: "string" was recognized, causing fields like payee_name, memo, category_id, and flag_color to be silently dropped.

Test plan

  • 9 new unit tests (3 allOf, 2 nullable types, 4 --data/--file)
  • All 282 tests pass (bun test)
  • Typecheck passes (bun run typecheck)
  • End-to-end: compiled a CLI from the YNAB OpenAPI spec and successfully updated a transaction using both --data and expanded body field flags

🤖 Generated with Claude Code

joshuayoes and others added 3 commits March 23, 2026 09:41
…eration

The --data and --file flags were documented in the README but never
registered as Commander options. This wires them into the CLI by
registering them in generated.ts and handling them in buildRequest(),
using the existing but previously dead-code loadBody() from body.ts.

Body field flag generation (--name, --address.city, etc.) failed for
OpenAPI specs using allOf schema composition because generateBodyFlags()
required direct type+properties on the schema. This adds flattenAllOf()
to recursively merge allOf compositions before generating flags, fixing
flag generation for specs like the YNAB API.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fields with `type: ["string", "null"]` (OpenAPI 3.1 nullable syntax)
were silently skipped by collectFlags() since it only matched scalar
type strings. Added resolveType() to extract the non-null type from
array-style nullable types.

This fixes missing flags for fields like payee_name, memo, category_id,
payee_id, and flag_color in specs like the YNAB API.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add a test that reproduces the exact schema shape that was broken:
wrapper object -> allOf with empty object + object containing mixed
scalar and nullable (["string", "null"]) properties. Verifies all 10
fields generate flags, including the 5 nullable ones that were
previously silently dropped.

Also add a --file happy path test that writes a temp file and verifies
buildRequest reads it as the request body.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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