Skip to content

generateInputSchema

Generated reference page for the generateInputSchema function export.

Signatures

ts
function generateInputSchema(schema: CommandSchema | CLISchema, options?: JsonSchemaOptions): Record<string, unknown>;
ParameterTypeDescription
schemaCommandSchema | CLISchemaA CLI schema or a single command schema.
optionsJsonSchemaOptions | undefinedGeneration options.

Members

Members

generateInputSchema

Generate a JSON Schema (draft 2020-12) for validating CLI input as JSON.

Accepts either a full CLISchema (producing a discriminated union across all commands) or a single CommandSchema (producing a flat object schema for that command's flags and args).

Single command — produces an object schema where flag/arg names are properties with appropriate JSON Schema types.

Multi-command CLI — produces a oneOf discriminated union with a command property identifying each branch. Nested subcommands use dot-delimited paths (e.g. "deploy.rollback").

Only commands with action handlers are included (group commands without actions are not directly invocable and are skipped).

ts
(schema: CommandSchema | CLISchema, options?: JsonSchemaOptions): Record<string, unknown>;

Examples

ts
// Validate a config file against the CLI's input shape
const inputSchema = generateInputSchema(app.schema);
writeFileSync('input-schema.json', JSON.stringify(inputSchema, null, 2));

See Also

Released under the MIT License.