name: pikku-schema-ajv description: 'Use when setting up JSON schema validation with AJV in a Pikku app. Covers AjvSchemaService for request/response validation. TRIGGER when: code uses AjvSchemaService, user asks about AJV, JSON schema validation, or @pikku/schema-ajv. DO NOT TRIGGER when: user asks about Cloudflare Workers schema validation (use pikku-schema-cfworker).' installGroups: [core]
Pikku Schema AJV (JSON Schema Validation)
Agent Operating Procedure
Use this skill as an execution checklist, not reference material.
- Discover before editing. Prefer OpenCode tools such as
pikku-metawhen available; otherwise run the relevantpikku meta ... --jsoncommand and inspect only the focused output you need. - Identify the source files that own the behavior. Do not start by reading generated output,
.pikku,node_modules, vendored packages, or broad build artifacts. - Make the smallest source change that satisfies the task. Keep generated files generated, and avoid hand-editing SDKs, schema output, or typegen.
- Validate with the narrowest relevant command first, then run
pikku-verifyorpikku allwhen functions, wirings, schemas, or generated clients may have changed. - If validation fails, fix the source cause and rerun validation. Do not paper over generated errors by editing generated files.
@pikku/schema-ajv provides JSON schema validation using AJV. Implements the SchemaService interface from @pikku/core. This is the default schema validator for Node.js environments.
Installation
yarn add @pikku/schema-ajv
API Reference
AjvSchemaService
import { AjvSchemaService } from '@pikku/schema-ajv'
const schema = new AjvSchemaService(logger: Logger)
Methods:
compileSchema(schema: string, value: any): void— Compile and register a JSON schemavalidateSchema(schemaName: string, json: any): void— Validate data against a compiled schema (throws on failure)getSchemaNames(): Set<string>— Get all registered schema namesgetSchemaKeys(schemaName: string): string[]— Get property keys for a schema
Usage Patterns
With Pikku Services
import { AjvSchemaService } from '@pikku/schema-ajv'
const createSingletonServices = pikkuServices(async (config) => {
const logger = new ConsoleLogger()
const schema = new AjvSchemaService(logger)
return { config, logger, schema }
})
Pikku automatically uses the schema service to validate function inputs and outputs when schemas are defined in your function definitions.