Skip to content

Carry OpenAPI numeric constraints into CLI flags#108

Merged
etbyrd merged 2 commits into
mainfrom
cli-openapi-numeric-flags
May 18, 2026
Merged

Carry OpenAPI numeric constraints into CLI flags#108
etbyrd merged 2 commits into
mainfrom
cli-openapi-numeric-flags

Conversation

@etbyrd
Copy link
Copy Markdown
Member

@etbyrd etbyrd commented May 18, 2026

Summary

Carries scalar parameter metadata from the OpenAPI spec into the generated operation manifest, then uses it when building generated CLI flags.

  • Adds optional default, minimum, and maximum metadata to PrimitiveParameterManifest.
  • Regenerates operations.generated.ts so list limit params expose their default/min/max values.
  • Passes integer min, max, and numeric default through to Flags.integer.
  • Adds a decimal number flag parser so future type: number params can validate min/max client-side too.

This keeps generated commands from accepting obviously out-of-range numeric values that the OpenAPI spec already describes.

Validation

  • pnpm --filter @primitivedotdev/api-core generate:openapi
  • pnpm --filter @primitivedotdev/cli test -- tests/oclif/api-command.test.ts
  • pnpm --filter @primitivedotdev/cli typecheck
  • pnpm --filter @primitivedotdev/cli lint
  • git diff --check

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 18, 2026

Greptile Summary

This PR carries OpenAPI numeric constraints (default, minimum, maximum) through the code-generation pipeline into the CLI's flag definitions, preventing users from supplying obviously out-of-range values that the spec already rejects server-side.

  • Adds a custom numberFlag parser for type: number fields with explicit empty-string, non-finite, and range guards; wires the same min/max/default options into the existing Flags.integer call for integer parameters.
  • Extends PrimitiveParameterManifest and the generator script to emit scalar constraints, then regenerates operations.generated.ts so limit query params carry their default: 50, minimum: 1, and maximum values.
  • String defaults (e.g. \"true\" for the highlight/facet params) are now captured in the manifest but not yet forwarded to the generated flag — intentionally out of scope per the PR description, which limits the wiring to numeric types.

Confidence Score: 5/5

Safe to merge — all changed paths are additive, well-tested, and the new number parser is guarded correctly for empty input, non-finite values, and out-of-range bounds.

The changes are purely additive: new fields on an existing interface, a new custom flag parser, and a regenerated artifact. The parser correctly handles every edge case (empty string, whitespace, Infinity/NaN, min/max bounds), and the test suite exercises all of those branches including both lower- and upper-bound rejection. No existing behavior is removed or altered in a breaking way.

No files require special attention.

Important Files Changed

Filename Overview
cli-node/src/oclif/api-command.ts Adds numberFlag custom parser with empty/whitespace/range validation; wires min, max, and numeric default into both Flags.integer and the new numberFlag for query and body fields; splits the former integer/number catch-all into distinct integer and number branches
cli-node/tests/oclif/api-command.test.ts New tests cover integer constraint passthrough, decimal parsing (including empty/whitespace/non-numeric/out-of-range inputs), and constraint propagation through the full createOperationCommand path for both integer and number body fields
packages/api-core/scripts/generate-openapi-artifacts.ts Extends OpenApiParameter and PrimitiveParameterManifest types with default, minimum, and maximum; emits those fields from the schema when they are scalars/numbers
packages/api-core/src/openapi/operations.generated.ts Re-generated artifact: adds default, minimum, and maximum to limit query params and string defaults to two highlight/facet params; type definition updated to match the generator

Reviews (2): Last reviewed commit: "Apply numeric constraints to body flags" | Re-trigger Greptile

Comment thread cli-node/src/oclif/api-command.ts Outdated
Comment thread cli-node/tests/oclif/api-command.test.ts
@etbyrd etbyrd added this pull request to the merge queue May 18, 2026
Merged via the queue into main with commit 04c2cb8 May 18, 2026
10 checks passed
@etbyrd etbyrd deleted the cli-openapi-numeric-flags branch May 18, 2026 01:52
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