CLI – fluent-wp-client
Overview
Section titled “Overview”fluent-wp-client ships a CLI for discovering live REST schemas from a WordPress site and generating code artifacts for downstream apps, validators, type checking, and AI/tooling workflows.
Command
Section titled “Command”npx fluent-wp-client schemas --url https://example.comThe schemas command discovers WordPress JSON Schema first, then generates a Zod-ready TypeScript module, standalone TypeScript types, JSON Schema, or multiple artifacts in one run.
Authentication
Section titled “Authentication”Use non-interactive auth flags when discovery needs authenticated schemas or when you are running in CI:
npx fluent-wp-client schemas \ --url https://example.com \ --username admin \ --password "xxxx xxxx xxxx xxxx"Supported auth flags:
--usernameand--passwordfor WordPress application passwords--tokenfor JWT bearer auth--auth-headerfor a prebuiltAuthorizationheader value
Use only one auth mode at a time.
Environment variables
Section titled “Environment variables”To avoid passing secrets through CLI arguments (which can appear in shell history and process listings), use environment variables instead:
export FLUENT_WP_USERNAME=adminexport FLUENT_WP_PASSWORD="xxxx xxxx xxxx xxxx"npx fluent-wp-client schemas --url https://example.comSupported environment variables:
FLUENT_WP_USERNAMEandFLUENT_WP_PASSWORDfor WordPress application passwordsFLUENT_WP_TOKENfor JWT bearer authFLUENT_WP_AUTH_HEADERfor a prebuiltAuthorizationheader value
CLI flags take precedence over environment variables when both are provided.
Resource filtering
Section titled “Resource filtering”Use --include and --exclude to limit generation to specific resources by slug or REST base:
npx fluent-wp-client schemas \ --url https://example.com \ --include posts,books,genre \ --exclude postsIn this example only books and genre are generated.
Output Files
Section titled “Output Files”npx fluent-wp-client schemas --url https://example.comnpx fluent-wp-client schemas --url https://example.com \ --zod-out wp-schemas.mjs \ --types-out wp-types.d.tsnpx fluent-wp-client schemas --url https://example.com \ --zod-out wp-schemas.ts \ --json-out wp-schemas.json \ --types-out wp-types.d.tsOutput paths define the artifacts to generate. If you omit all output paths, the CLI writes wp-schemas.ts.
--zod-outor--outwrites a Zod module with JSON Schema literals and validators..tsoutput also includes inferredz.infer<>aliases.--json-outwrites one JSON document keyed by REST base.--types-outwrites dependency-free TypeScript declaration files with interfaces and type aliases derived from the same normalized JSON Schemas.
Generated artifact extensions are intentionally strict:
- Zod output must be
.tsfor TypeScript or.mjsfor runtime JavaScript. - JSON Schema output must be
.json. - Standalone TypeScript declarations must be
.d.ts.
Use --types-out when you want a dedicated types file beside runtime validators:
npx fluent-wp-client schemas \ --url https://example.com \ --out wp-schemas.ts \ --types-out wp-types.d.tsInteractive mode
Section titled “Interactive mode”If you omit --url, the CLI prompts for the site URL and auth method interactively.
npx fluent-wp-client schemasGenerated artifacts
Section titled “Generated artifacts”schemas produces normalized item schemas suitable for downstream validation and codegen. Generated JSON Schema and Zod validators accept WordPress local datetime strings without strict date-time format checks. Optional scalar ACF fields also allow "" when WordPress can return an empty value; null appears only when the REST schema declares it.
Typical flow:
- Generate schema files from the target site.
- Import generated Zod validators when you need runtime validation.
- Import generated interfaces when you only need compile-time types.
- Validate input or output locally.
- Call the normal
fluent-wp-clientmethod with the validated data.
import { postsCreateSchema } from './wp-schemas';
const validatedInput = postsCreateSchema.parse({ title: 'CLI-validated post', status: 'draft',});
await wp.content('posts').create(validatedInput);import type { WPPost } from './wp-types';
function getTitle(post: WPPost): string { return post.title?.rendered ?? '';}Use runtime discovery from schema-discovery.mdx when you want live schemas inside the app instead of build-time generated files.