config-schema-validator
Scannednpx machina-cli add skill a5c-ai/babysitter/config-schema-validator --openclawConfig Schema Validator
Generate configuration schema validators.
Generated Patterns
import { z } from 'zod';
export const configSchema = z.object({
server: z.object({
host: z.string().default('localhost'),
port: z.number().int().min(1).max(65535).default(3000),
cors: z.object({
origins: z.array(z.string().url()).default(['*']),
credentials: z.boolean().default(false),
}).default({}),
}).default({}),
logging: z.object({
level: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
format: z.enum(['json', 'pretty']).default('pretty'),
}).default({}),
}).strict();
export type Config = z.infer<typeof configSchema>;
export function validateConfig(input: unknown): Config {
return configSchema.parse(input);
}
export function getConfigWithDefaults(partial: Partial<Config> = {}): Config {
return configSchema.parse(partial);
}
Target Processes
- configuration-management-system
- mcp-tool-implementation
- cli-application-bootstrap
Source
git clone https://github.com/a5c-ai/babysitter/blob/main/plugins/babysitter/skills/babysit/process/specializations/cli-mcp-development/skills/config-schema-validator/SKILL.mdView on GitHub Overview
Config Schema Validator generates strict, typed validators for app configuration using Zod (and JSON Schema patterns). It provides a ready-to-use configSchema with nested sections like server and logging, each with sensible defaults, and helper functions to validate input or generate a config with defaults. This ensures runtime config integrity and clearer error messages.
How This Skill Works
It defines a Zod schema (configSchema) with nested objects (server, logging, etc.), uses default() to supply defaults, and .strict() to forbid unknown keys. It exports a Config type inferred from the schema and two helpers: validateConfig(input) which parses and validates input, and getConfigWithDefaults(partial) which fills in missing fields via the schema defaults.
When to Use It
- When building a CLI tool that reads config from a file or environment variables
- During development of a configuration-management system requiring strict validation
- When bootstrapping an MCP tool or CLI app and needing sensible defaults
- If you want to enforce constraints on server.host, server.port, and CORS settings
- To catch configuration errors early with clear, schema-driven error messages
Quick Start
- Step 1: Import { configSchema, validateConfig, getConfigWithDefaults } from the skill
- Step 2: Use validateConfig(input) to parse and validate user config
- Step 3: Use getConfigWithDefaults(partial) to apply defaults for missing fields
Best Practices
- Keep the schema as the single source of truth and export the Config type
- Use default() on fields to provide safe, predictable defaults
- Call .strict() to disallow unknown keys and surface misconfigurations
- Document and standardize error messages returned by validation
- Write tests that cover both valid configurations and common invalid cases
Example Use Cases
- Configuring server settings with host, port, and cors origins using the configSchema
- Defining logging settings with level and format and default values
- Validating a partial config with getConfigWithDefaults to fill in missing fields
- Parsing user-provided config.json into the Config type via validateConfig
- Integrating into configuration-management-system and mcp-tool-implementation workflows