Loading...
Loading...
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 skill4agent add zaggino/z-schema contributing-to-z-schemagit clone --recursive https://github.com/zaggino/z-schema.git
cd z-schema
npm install--recursivejson-schema-spec/git submodule update --init --recursivenpm run lint:check # ESLint
npm run format:check # Prettier
npm run build # TypeScript + Rollup
npm run build:tests # Type-check tests
npm test # Vitest (node + browser)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 → Instance validation (type, constraints, combiners)
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$refid$idschema-validator.tsjson-validation.tsallOfanyOfoneOfnotunevaluated*report.tsReportValidateErrorErrorssrc/errors.tsMY_NEW_ERROR: 'Description with {0} placeholder',report.addError('MY_NEW_ERROR', [param])src/format-validators.tsconst myFormatValidator: FormatValidatorFn = (input: unknown) => {
if (typeof input !== 'string') return true;
return /^pattern$/.test(input);
};inbuiltValidatorsconst inbuiltValidators = {
// ...existing
'my-format': myFormatValidator,
};test/spec/format-validators.spec.tsZSchemaOptionssrc/z-schema-options.tsdefaultOptionsstrictModestrictModenormalizeOptionsdocs/options.mdsrc/json-validation.tssrc/schema-validator.tsexcludedFilesexcludedTeststest/spec/json-schema-test-suite.common.tsnpx vitest run --silent=false --project node -t "draft2020-12/newKeyword"src/index.tsglobals: truetest/spec/| Suffix | Runs in |
|---|---|
| Both node and browser |
| Node only |
| 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 # coverageimport { 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');
});
});test/spec/json-schema-test-suite.common.tsexcludedFilesexcludedTestsstrict: true.jssrc/.tstest/allowImportingTsExtensionsimport typePascalCasecamelCaseUPPER_SNAKE_CASEsrc/index.tssrc/schemas/scripts/copy-schemas.mtsjson-schema-spec/- [ ] Branch from `main`
- [ ] Changes follow code conventions
- [ ] npm run lint:check passes
- [ ] npm run format:check passes
- [ ] 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