Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

api-contracts-and-zod-validationAPI contracts AND ZOD validation 搜索

Agent Skill

用于辅助 API 设计、接口文档、请求响应结构和服务集成说明。它适合让 Agent 梳理 endpoint、生成 OpenAPI 草稿、检查字段命名、整理错误码或辅助前后端联调。使用时需要确认真实业务语义、鉴权方式、分页和错误处理规则;涉及生成接口文档时,应避免凭空补字段,最好从现有代码、schema 或接口样例中提取事实。

总安装

267

周安装

11

GitHub Stars

3

下载量

87
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:api-contracts-and-zod-validation(API contracts AND ZOD validation 搜索)
来源仓库:https://github.com/hopeoverture/worldbuilding-app-skills
仓库路径:skills/api-contracts-and-zod-validation
安装命令:
npx skills add https://github.com/hopeoverture/worldbuilding-app-skills --skill api-contracts-and-zod-validation
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/hopeoverture/worldbuilding-app-skills --skill api-contracts-and-zod-validation

简介

基于 TypeScript 类型生成 Zod 验证模式,实现表单与 API 路由的双向类型安全。

  • 适用于 Server Actions 与路由处理器输入校验,自动推断 z.infer 类型映射。
  • 使用时需分析现有接口定义,导出等效 Zod schema 并集成到验证流程中。
  • 安装方式:通过 npx skills add 从指定仓库获取,兼容 Codex、Claude 等宿主环境。
  • 注意:生成的 schema 应覆盖边界条件,如空值、格式限制与嵌套对象校验。

SKILL.md

API Contracts and Zod Validation

Generate Zod schemas with TypeScript type inference for forms, API routes, and Server Actions. Validate inputs in Server Actions or route handlers with runtime type checking.

Core Capabilities

1. Generate Zod Schemas from TypeScript Types

When creating API contracts or form validations:

  • Analyze existing TypeScript interfaces or types
  • Generate equivalent Zod schemas with proper validation rules
  • Ensure bidirectional type compatibility (Zod -> TypeScript)
  • Use z.infer<typeof schema> for automatic type inference

2. Form Validation Schemas

To create form validation with Zod:

  • Generate schemas for React Hook Form, Formik, or native forms
  • Include field-level validation rules (min/max length, regex, custom validators)
  • Support nested objects, arrays, and complex data structures
  • Provide helpful error messages for validation failures
  • Use references/zod_patterns.md for common validation patterns

3. API Route and Server Action Validation

To add validation to API endpoints or Server Actions:

  • Wrap handler logic with schema validation using .parse() or .safeParse()
  • Return typed errors for validation failures
  • Generate request/response schemas for API contracts
  • Validate query parameters, body payloads, and route parameters
  • Ensure type safety between client and server code

4. Schema Generation Script

Use scripts/generate_zod_schema.py to automate schema generation:

python scripts/generate_zod_schema.py --input types/entities.ts --output schemas/entities.ts

The script:

  • Parses TypeScript interfaces/types
  • Generates Zod schemas with appropriate validators
  • Preserves JSDoc comments as descriptions
  • Handles common patterns (optional fields, unions, enums)

Resource Files

scripts/generate_zod_schema.py

Automated TypeScript-to-Zod schema generator. Parses TypeScript AST and generates equivalent Zod schemas.

references/zod_patterns.md

Common Zod validation patterns including:

  • String validation (email, URL, UUID, custom regex)
  • Number constraints (min, max, positive, integer)
  • Date validation and transformation
  • Array and tuple validation
  • Object shape validation
  • Union and discriminated unions
  • Optional and nullable fields
  • Custom refinements and transforms
  • Error message customization

assets/schema_templates/

Pre-built Zod schema templates:

  • form_schema_template.ts - Basic form validation
  • api_route_schema_template.ts - API route request/response
  • server_action_schema_template.ts - Server Action input/output
  • entity_schema_template.ts - Database entity validation

Usage Workflow

For New API Routes

  1. Define request/response TypeScript types
  2. Generate Zod schemas using scripts/generate_zod_schema.py or templates
  3. Add validation middleware to route handler
  4. Return typed validation errors on failure

For Server Actions

  1. Define input parameters as TypeScript types
  2. Create Zod schema for validation
  3. Use .safeParse() at the beginning of the action
  4. Return validation errors in action result
  5. Handle errors on the client side

For Forms

  1. Define form fields as TypeScript interface
  2. Generate Zod schema with field validators
  3. Integrate with form library (React Hook Form recommended)
  4. Display validation errors inline

Best Practices

  • Always use .safeParse() instead of .parse() to avoid throwing exceptions
  • Provide clear, user-friendly error messages
  • Validate early (at API boundary or Server Action entry)
  • Keep schemas colocated with routes/actions for maintainability
  • Use z.infer<typeof schema> for automatic TypeScript types
  • Document validation rules in schema comments
  • Test edge cases (empty values, invalid formats, boundary conditions)

Integration with Worldbuilding App

Common use cases for worldbuilding applications:

  • Entity creation forms: Validate character, location, faction data
  • Relationship APIs: Ensure valid entity IDs and relationship types
  • Timeline events: Validate dates, ordering, and event data
  • Search/filter endpoints: Validate query parameters and filters
  • Bulk operations: Validate arrays of entities or updates
  • Import/export: Validate file formats and data structure

Consult references/zod_patterns.md for specific validation patterns applicable to worldbuilding entities.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.42%
按下载量换算32

Claude

30.65%
按下载量换算27

Cursor

19.92%
按下载量换算17

Gemini CLI

10.13%
按下载量换算9

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills