PoC: Automatically document command JSON output schemas - #8283
Draft
gonzaloriestra wants to merge 1 commit into
Draft
PoC: Automatically document command JSON output schemas#8283gonzaloriestra wants to merge 1 commit into
gonzaloriestra wants to merge 1 commit into
Conversation
gonzaloriestra
force-pushed
the
gonzalo/automatic-json-output-help
branch
from
August 10, 2026 10:09
e305dbe to
8dd3211
Compare
This was referenced Aug 10, 2026
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
gonzaloriestra
force-pushed
the
gonzalo/automatic-json-output-help
branch
2 times, most recently
from
August 10, 2026 10:30
f6b121f to
d403c37
Compare
gonzaloriestra
force-pushed
the
gonzalo/automatic-json-output-help
branch
from
August 10, 2026 10:31
d403c37 to
4bc2c36
Compare
Contributor
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationspackages/cli-kit/dist/public/node/json-output-schema.d.tsimport { ZodTypeAny, type z } from 'zod';
export interface JsonOutputSchema<TSchema extends ZodTypeAny = ZodTypeAny> {
readonly name: string;
readonly schema: TSchema;
readonly definitions: Readonly<Record<string, ZodTypeAny>>;
}
export type InferJsonOutputSchema<TOutputSchema extends JsonOutputSchema> = z.infer<TOutputSchema['schema']>;
interface DefineJsonOutputSchemaOptions<TSchema extends ZodTypeAny> {
name: string;
schema: TSchema;
definitions?: Readonly<Record<string, ZodTypeAny>>;
}
/**
* Defines the runtime schema and named types for a command's JSON output.
*
* @param options - The root schema name, schema, and any named nested schemas.
* @returns Command metadata that can also be used to infer and validate the output type.
*/
export declare function defineJsonOutputSchema<TSchema extends ZodTypeAny>(options: DefineJsonOutputSchemaOptions<TSchema>): JsonOutputSchema<TSchema>;
/**
* Renders a command JSON output schema as TypeScript interfaces for help text.
*
* @param outputSchema - The command's JSON output schema metadata.
* @returns TypeScript interfaces describing the command's JSON output.
*/
export declare function renderJsonOutputSchema(outputSchema: JsonOutputSchema): string;
export {};
Existing type declarationspackages/cli-kit/dist/public/node/base-command.d.ts@@ -1,3 +1,4 @@
+import { type JsonOutputSchema } from './json-output-schema.js';
import { Command } from '@oclif/core';
import { OutputFlags, Input, ParserOutput, FlagInput, OutputArgs } from '@oclif/core/parser';
export type ArgOutput = OutputArgs<any>;
@@ -10,6 +11,8 @@ export interface NonTTYFlagRequirement {
}
declare abstract class BaseCommand extends Command {
static baseFlags: FlagInput<{}>;
+ static descriptionWithMarkdown?: string;
+ static get jsonOutputSchema(): JsonOutputSchema | undefined;
static nonTTYFlagRequirements(_flags: FlagOutput): NonTTYFlagRequirement[];
static descriptionWithoutMarkdown(): string | undefined;
static analyticsNameOverride(): string | undefined;
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Why
Commands that return JSON should expose their result contract in
--helpwithout manually duplicating TypeScript definitions in their descriptions.What
defineJsonOutputSchemahelper backed by ZodBaseCommandautomatically append those interfaces to command descriptionsTesting
The next PRs add schema contracts for some commands. Running the command help (
-h) should show them.Example: