重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
contributing-to-z-schema by zaggino/z-schema
npx skills add https://github.com/zaggino/z-schema --skill contributing-to-z-schemaz-schema 是一个用 TypeScript 编写的 JSON Schema 验证器(支持草案-04 至草案-2020-12)。本技能涵盖开发工作流程、代码库导航以及常见的贡献任务。
git clone --recursive https://github.com/zaggino/z-schema.git
cd z-schema
npm install
如果已经克隆但没有使用 --recursive(这是 json-schema-spec/ 子模块所必需的):
git submodule update --init --recursive
推送前运行所有检查:
npm run lint:check # ESLint
npm run format:check # Prettier
npm run build # TypeScript + Rollup
npm run build:tests # 类型检查测试
npm test # Vitest (node + browser)
预提交钩子会自动对暂存文件运行 lint + format。预推送钩子会运行 build + type-check。
src/
index.ts → 公共 API (所有导出)
z-schema.ts → 工厂 + ZSchema/ZSchemaSafe/ZSchemaAsync/ZSchemaAsyncSafe
z-schema-base.ts → 核心验证编排
schema-compiler.ts → $ref 解析,id 收集,模式编译
schema-validator.ts → 针对元模式的模式级验证
json-validation.ts → 验证编排 (validate, recurse*, collectEvaluated)
validation/ → 按类别分割的关键字验证器
shared.ts → 共享类型 (JsonValidatorFn),词汇表助手,缓存工具
type.ts → type, enum, const 验证器
numeric.ts → multipleOf, minimum, maximum, exclusiveMin/Max 验证器
string.ts → minLength, maxLength, pattern, format, content* 验证器
array.ts → items, prefixItems, contains, min/maxItems, uniqueItems 验证器
object.ts → properties, patternProperties, additionalProperties, required 等验证器
combinators.ts → allOf, anyOf, oneOf, not, if/then/else 验证器
ref.ts → $dynamicRef/$recursiveRef 解析助手
schema-cache.ts → 按 URI/id 的模式缓存
errors.ts → 错误代码 (Errors 对象) + ValidateError 类
format-validators.ts → 内置 + 自定义格式验证器
report.ts → 错误累积 (Report, SchemaErrorDetail)
json-schema.ts → 通用 JSON Schema 定义 + 助手
json-schema-versions.ts → 草案特定类型联合 + 版本映射
z-schema-options.ts → 选项接口 + 默认值 + normalizeOptions
z-schema-reader.ts → 模式读取器类型
z-schema-versions.ts → 将捆绑的元模式注册到缓存中
utils/ → 纯工具函数 (array, clone, json, uri 等)
schemas/ → 捆绑的元模式 (在构建时生成)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
schema-compiler.ts):解析 $ref,收集 id/$id,注册到缓存中schema-validator.ts):根据其元模式验证模式json-validation.ts + validation/*.ts):根据编译后的模式验证数据 —— 类型检查、约束、组合器 (allOf/anyOf/oneOf/not)、unevaluated* 跟踪、格式检查。关键字验证器按类别拆分到 validation/ 下的模块中report.ts):错误累积在 Report 中,然后转换为 ValidateErrorsrc/errors.ts 的 Errors 对象中添加错误:
typescript MY_NEW_ERROR: '描述包含 {0} 占位符', report.addError('MY_NEW_ERROR', [param])。src/format-validators.ts 中编写验证器函数:
typescript const myFormatValidator: FormatValidatorFn = (input: unknown) => { if (typeof input !== 'string') return true; return /^pattern$/.test(input); }; inbuiltValidators 记录中注册它:
typescript const inbuiltValidators = { // ...existing 'my-format': myFormatValidator, }; test/spec/format-validators.spec.ts 中添加测试。src/z-schema-options.ts 的 ZSchemaOptions 中添加选项。defaultOptions 中添加默认值。strictMode 的一部分,将其添加到 normalizeOptions 中的 strictMode 块。docs/options.md 中记录它。src/validation/*.ts 模块(例如,数组关键字用 array.ts,对象关键字用 object.ts,应用器用 combinators.ts)或 src/schema-validator.ts(用于模式级验证)中添加验证逻辑。src/json-validation.ts 中的编排层会调用这些模块。test/spec/json-schema-test-suite.common.ts 中的 excludedFiles/excludedTests 中移除相关条目。bash npx vitest run --silent=false --project node -t "draft2020-12/newKeyword" src/index.ts 导出任何新类型。globals: true。test/spec/。| 后缀 | 运行环境 |
|---|---|
*.spec.ts | node 和 browser 都运行 |
*.node-spec.ts | 仅 node |
*.browser-spec.ts | 仅 browser |
npm test # 全部
npm run test:node # 仅 node
npx vitest run --silent=false --project node -t "draft4/type" # 单个测试
npm run test:coverage # 覆盖率
import { ZSchema } from '../../src/z-schema.ts';
describe('功能名称', () => {
it('应该接受有效数据', () => {
const validator = ZSchema.create();
expect(validator.validate('hello', { type: 'string' })).toBe(true);
});
it('应该拒绝无效数据', () => {
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.ts 加载。要启用新实现功能的测试,请从 excludedFiles / excludedTests 中移除条目并确认它们通过。
strict: true,在 src/ 中使用带 .js 导入扩展名的 ESMtest/ 中使用 .ts 导入扩展名 (通过 allowImportingTsExtensions)import type (由 ESLint 强制执行)PascalCase — 函数/变量:camelCase — 错误:UPPER_SNAKE_CASEsrc/index.ts 导出src/schemas/ 中的模式由 scripts/copy-schemas.mts 生成 —— 请勿手动编辑json-schema-spec/ 是一个 git 子模块 —— 请勿提交对其的更改- [ ] 从 `main` 分支创建
- [ ] 更改遵循代码规范
- [ ] npm run lint:check 通过
- [ ] npm run format:check 通过
- [ ] npm run build 通过
- [ ] npm run build:tests 通过
- [ ] npm test 通过 (node + browser)
- [ ] 新的公共类型/值通过 src/index.ts 导出
- [ ] 新功能有测试
- [ ] 如果公共 API 更改,更新 docs/
- [ ] 如果适用,取消排除 JSON Schema 测试套件条目
每周安装数
52
仓库
GitHub 星标数
342
首次出现
2026年2月27日
安全审计
安装于
github-copilot52
mcpjam12
claude-code12
junie12
windsurf12
zencoder12
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 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)
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/), tracking, format checks. Keyword validators are split into modules under by categoryAdd the error to the Errors object in src/errors.ts:
MY_NEW_ERROR: 'Description with {0} placeholder',
Use report.addError('MY_NEW_ERROR', [param]) in the validation logic.
Write tests verifying the error code is produced.
Write the validator function in src/format-validators.ts:
const myFormatValidator: FormatValidatorFn = (input: unknown) => { if (typeof input !== 'string') return true; return /^pattern$/.test(input); };
Register it in the inbuiltValidators record:
const inbuiltValidators = { // ...existing 'my-format': myFormatValidator, };
Add tests in 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.Add validation logic in the appropriate 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.
Guard with a draft version check if the keyword is draft-specific.
Remove relevant entries from excludedFiles/excludedTests in test/spec/json-schema-test-suite.common.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 ESLint)PascalCase — functions/variables: camelCase — errors: UPPER_SNAKE_CASE- [ ] 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
Weekly Installs
52
Repository
GitHub Stars
342
First Seen
Feb 27, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
github-copilot52
mcpjam12
claude-code12
junie12
windsurf12
zencoder12
Caveman-Review:AI代码审查工具,提升PR评论效率与代码质量
7,700 周安装
Claude API 使用指南:Python/TypeScript SDK 安装、模型选择与工具调用教程
1,500 周安装
发票整理器 - 自动整理发票收据,PDF/图片提取信息,报税归档系统
1,400 周安装
工商业能源采购管理指南:电价分析、需量费用优化、可再生能源采购与预算风险管理策略
1,400 周安装
物流异常管理指南:货运损坏、延迟、丢失索赔处理与承运商争议解决
1,400 周安装
承运商关系管理指南:资深运输经理的RFP、费率协商与绩效记分卡实战技巧
1,400 周安装
maishou 买手技能:淘宝京东拼多多抖音快手全网比价,获取商品价格优惠券
1,400 周安装
notunevaluated*validation/report.ts): errors accumulate in a Report, then convert to ValidateErrorRun the JSON Schema Test Suite to confirm compliance:
npx vitest run --silent=false --project node -t "draft2020-12/newKeyword"
Export any new types through src/index.ts.
src/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