Skip to content

feat(openapi): add --schema flag to inspect request body shapes#66

Merged
dspangen merged 3 commits into
mainfrom
feat/body-schema-flag
Jun 26, 2026
Merged

feat(openapi): add --schema flag to inspect request body shapes#66
dspangen merged 3 commits into
mainfrom
feat/body-schema-flag

Conversation

@dspangen

@dspangen dspangen commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds --schema to every command that takes a request body. It prints the body's resolved JSON schema (types, descriptions, enums, formats, required) plus a filled-in example, then exits — no API call, no token. Closes the discovery gap: --help says a body is required but nothing about its shape, so agents guess and eat 400s.

omni ai generate-query --schema

For deeply nested bodies (e.g. documents v2-create, ~400KB) two flags narrow the output:

  • --depth N — cap expansion; --schema --depth 1 is a ~3KB top-level overview.
  • --field <dotpath> — drill to a sub-schema, e.g. queryPresentations.data.query. Auto-descends arrays and maps, so you name a leaf without knowing the container shape. Unknown segments error with the available fields (doubles as discovery).
omni documents v2-create --schema --depth 1
omni documents v2-create --schema --field queryPresentations.data.query

Map-typed fields (additionalProperties, e.g. queryPresentations.data) now expand their value schema instead of dropping it.

🤖 Generated with Claude Code

Every generated command that takes a request body now accepts --schema,
which prints the body's resolved JSON schema (types, descriptions, enums,
formats, required fields) plus a filled-in example, then exits without
making an API call or requiring a token. This closes the discovery gap
where --help told an agent a body was required but said nothing about its
shape.

The schema is derived entirely from the embedded spec, so it covers all
body operations (including the ~56 without a hand-written shorthand) with
no per-endpoint maintenance. allOf members are merged into a single
object; nesting is depth-capped and $ref cycles are guarded so deeply
nested or self-referential bodies can't blow up the output. The example
skeleton includes only required fields, filled from the spec's field-level
examples, then defaults, first enum value, or a typed placeholder.

The flag short-circuits before positional-arg validation, body assembly,
auth, and the HTTP call, so `omni <cmd> --schema` works with no args and
no token. Normal runs (arg validation, shorthands, --body/stdin) are
unchanged. Discovery is wired into per-command --help and agent-help.

go.yaml.in/yaml/v4 (already a transitive dep via libopenapi) is promoted
to a direct dependency for decoding schema example/default/enum nodes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017Egqycqj1GcK81yyLxNeg4
@dspangen
dspangen requested a review from n8agrin June 25, 2026 20:04
dspangen and others added 2 commits June 25, 2026 19:53
The --schema dump described map-typed fields by their `properties` and
`items` only, so fields that carry their value shape in
`additionalProperties` — e.g. documents v2-create's
`queryPresentations.data`, a tile object keyed by tab ID — rendered as a
bare `{type: object}` with the value schema dropped. The data was in the
spec (QueryPresentationPatchExternal) but never reached the output.

simplifySchema now expands additionalProperties (mirroring the Items
handling), and synthExample renders one representative `<key>` entry for
pure map types so the example shows the value shape. Recursion/depth
guards still bound the output.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H8ndoDtArqEjtDRjzjEJGE
Deeply nested bodies (notably documents v2-create) produce a ~400KB
--schema dump that's unwieldy to read. Two flags make it navigable:

  --field <dotpath>  drill to a sub-schema, e.g. queryPresentations.data.query.
                     The path auto-descends through array items and map
                     (additionalProperties) values, so a caller can name a leaf
                     without knowing the container shape. Unknown segments error
                     with the fields available at that level — which doubles as
                     discovery.
  --depth N          cap expansion depth; --schema --depth 1 gives a compact
                     top-level overview (428KB -> ~1.7KB on v2-create).

Both scope the body and the synthesized example, and compose. The recursive
describers move onto a small describer{maxDepth} value so --depth threads
through without a global. Schema errors silence cobra's usage block so only the
helpful message prints. agent-help documents the new flags.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H8ndoDtArqEjtDRjzjEJGE
@dspangen
dspangen force-pushed the feat/body-schema-flag branch from dc60f08 to 9c2abbe Compare June 26, 2026 01:28
@dspangen
dspangen merged commit b5cd01f into main Jun 26, 2026
2 checks passed
@dspangen
dspangen deleted the feat/body-schema-flag branch June 26, 2026 13:48
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