skills/contributing-to-z-schema/SKILL.md
Guides contributors through the z-schema codebase, PR workflow, and common development tasks. Use when the user wants to contribute to z-schema, add a new feature or keyword, add an error code, add a format validator, modify options, write tests, run the test suite, fix a failing test, understand the validation pipeline, navigate the source code architecture, or submit a pull request. Also use when someone mentions contributing, PRs, the z-schema source code, or the JSON Schema Test Suite integration.
npx skillsauth add zaggino/z-schema contributing-to-z-schemaInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
z-schema is a JSON Schema validator (draft-04 through draft-2020-12) written in TypeScript. This skill covers the development workflow, codebase navigation, and common contribution tasks.
git clone --recursive https://github.com/zaggino/z-schema.git
cd z-schema
npm install
If already cloned without --recursive (needed for the json-schema-spec/ submodule):
git submodule update --init --recursive
Run all checks before pushing:
npm run check # ultracite check (oxlint type-aware + oxfmt format check)
npm run build # TypeScript + Rollup
npm run build:tests # Type-check tests
npm test # Vitest (node + browser)
Pre-commit hooks auto-run lint + format on staged files. Pre-push hooks run build + type-check.
src/
index.ts → Public API (all exports)
z-schema.ts → Factory + ZSchema/ZSchemaSafe/ZSchemaAsync/ZSchemaAsyncSafe
z-schema-base.ts → Core validation orchestration
schema-compiler.ts → $ref resolution, id collection, schema compilation
schema-validator.ts → Schema-level validation against meta-schemas
json-validation.ts → Validation orchestration (validate, recurse*, collectEvaluated)
validation/ → Keyword validators split by category
shared.ts → Shared types (JsonValidatorFn), vocab helpers, caching utilities
type.ts → type, enum, const validators
numeric.ts → multipleOf, minimum, maximum, exclusiveMin/Max validators
string.ts → minLength, maxLength, pattern, format, content* validators
array.ts → items, prefixItems, contains, min/maxItems, uniqueItems validators
object.ts → properties, patternProperties, additionalProperties, required, etc.
combinators.ts → allOf, anyOf, oneOf, not, if/then/else validators
ref.ts → $dynamicRef/$recursiveRef resolution helpers
schema-cache.ts → Schema caching by URI/id
errors.ts → Error codes (Errors object) + ValidateError class
format-validators.ts → Built-in + custom format validators
report.ts → Error accumulation (Report, SchemaErrorDetail)
json-schema.ts → Common JSON Schema definitions + helpers
json-schema-versions.ts → Draft-specific type unions + version mappings
z-schema-options.ts → Options interface + defaults + normalizeOptions
z-schema-reader.ts → Schema reader type
z-schema-versions.ts → Registers bundled meta-schemas into cache
utils/ → Pure utilities (array, clone, json, uri, etc.)
schemas/ → Bundled meta-schemas (generated at build time)
schema-compiler.ts): resolves $ref, collects id/$id, registers in cacheschema-validator.ts): validates schema against its meta-schemajson-validation.ts + validation/*.ts): validates data against compiled schema — type checks, constraints, combiners (allOf/anyOf/oneOf/not), unevaluated* tracking, format checks. Keyword validators are split into modules under validation/ by categoryreport.ts): errors accumulate in a Report, then convert to ValidateErrorErrors object in src/errors.ts:
MY_NEW_ERROR: 'Description with {0} placeholder',
report.addError('MY_NEW_ERROR', [param]) in the validation logic.src/format-validators.ts:
const myFormatValidator: FormatValidatorFn = (input: unknown) => {
if (typeof input !== 'string') return true;
return /^pattern$/.test(input);
};
inbuiltValidators record:
const inbuiltValidators = {
// ...existing
'my-format': myFormatValidator,
};
test/spec/format-validators.spec.ts.ZSchemaOptions in src/z-schema-options.ts.defaultOptions.strictMode, add it to the strictMode block in normalizeOptions.docs/options.md.src/validation/*.ts module (e.g., array.ts for array keywords, object.ts for object keywords, combinators.ts for applicators) or src/schema-validator.ts (for schema-level validation). The orchestration layer in src/json-validation.ts calls into these modules.excludedFiles/excludedTests in test/spec/json-schema-test-suite.common.ts.npx vitest run --silent=false --project node -t "draft2020-12/newKeyword"
src/index.ts.globals: true.test/spec/.| Suffix | Runs in |
| ------------------- | --------------------- |
| *.spec.ts | Both node and browser |
| *.node-spec.ts | Node only |
| *.browser-spec.ts | Browser only |
npm test # all
npm run test:node # node only
npx vitest run --silent=false --project node -t "draft4/type" # single test
npm run test:coverage # coverage
import { ZSchema } from '../../src/z-schema.ts';
describe('Feature Name', () => {
it('should accept valid data', () => {
const validator = ZSchema.create();
expect(validator.validate('hello', { type: 'string' })).toBe(true);
});
it('should reject invalid data', () => {
const validator = ZSchema.create();
const { valid, err } = validator.validateSafe(42, { type: 'string' });
expect(valid).toBe(false);
expect(err?.details?.[0]?.code).toBe('INVALID_TYPE');
});
});
Official test cases loaded via test/spec/json-schema-test-suite.common.ts. To enable tests for a newly implemented feature, remove entries from excludedFiles / excludedTests and confirm they pass.
strict: true, ESM with .js import extensions in src/.ts import extensions in test/ (via allowImportingTsExtensions)import type for type-only imports (enforced by oxlint)PascalCase — functions/variables: camelCase — errors: UPPER_SNAKE_CASEsrc/index.tssrc/schemas/ are generated by scripts/copy-schemas.mts — do not edit manuallyjson-schema-spec/ is a git submodule — do not commit changes to it- [ ] Branch from `main`
- [ ] Changes follow code conventions
- [ ] npm run check passes (lint + format)
- [ ] npm run build passes
- [ ] npm run build:tests passes
- [ ] npm test passes (node + browser)
- [ ] New public types/values exported through src/index.ts
- [ ] New features have tests
- [ ] docs/ updated if public API changed
- [ ] JSON Schema Test Suite entries un-excluded if applicable
development
Inspects, filters, and maps z-schema validation errors for application use. Use when the user needs to handle validation errors, walk nested inner errors from anyOf/oneOf/not combinators, map error codes to user-friendly messages, filter errors with includeErrors or excludeErrors, build form-field error mappers, use reportPathAsArray, interpret SchemaErrorDetail fields like code/path/keyword/inner, or debug why validation failed.
development
Authors JSON Schema definitions for use with z-schema validation. Use when the user needs to write a JSON Schema, define a schema for an API payload, create schemas for form validation, structure schemas with $ref and $defs, choose between oneOf/anyOf/if-then-else, design object schemas with required and additionalProperties, validate arrays with items or prefixItems, add format constraints, organize schemas for reuse, or write draft-2020-12 schemas.
development
Validates JSON data against JSON Schema using the z-schema library. Use when the user needs to validate JSON, check data against a schema, handle validation errors, use custom format validators, work with JSON Schema drafts 04 through 2020-12, set up z-schema in a project, compile schemas with cross-references, resolve remote $ref, configure validation options, or inspect error details. Covers sync/async modes, safe error handling, schema pre-compilation, remote references, TypeScript types, and browser/UMD usage.
development
Create, improve, and test skills for the z-schema JSON Schema validator library. Use this skill whenever the user wants to create a new skill from scratch, turn a workflow into a reusable skill, update or refine an existing skill, write test cases for a skill, or organize reference material for a skill. Also use when someone mentions "skill", "SKILL.md", or wants to document a z-schema workflow for reuse by humans or AI agents.