Agent skill

API Contract

by ChenyCHENYU in ChenyCHENYU/Robot_Admin

A skill your agent uses when: generating TypeScript API layer (type definitions + request functions) from page-spec JSON or Swagger/OpenAPI docs.

MITAuto-check passedBackend & APIs

Install API Contract

skills CLI
$ npx skills add ChenyCHENYU/Robot_Admin --skill api-contract -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install ChenyCHENYU/Robot_Admin api-contract --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/ChenyCHENYU/Robot_Admin.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.github/skills/api-contract .claude/skills/api-contract && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
api-contract
GitHub stars
1k
Token cost
~1.9k tokens
SKILL.md length
184 words
Files
1
Skills in repo
7
Repo updated
First seen
Licence
MIT

At a glance

A skill your agent uses when: generating TypeScript API layer (type definitions + request functions) from page-spec JSON or Swagger/OpenAPI docs.

  • Works in 4 steps: 从 page-spec 推导类型 → 生成类型定义文件 → 生成 API 请求函数文件 → …
  • : generating TypeScript API layer (type definitions + request functions) from page-spec JSON
  • SKILL.md covers 触发, 前置约定, 步骤 and 验证规则映射, plus 2 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

API Contract is an agent skill from ChenyCHENYU/Robot_Admin. Use when: generating TypeScript API layer (type definitions + request functions) from page-spec JSON or Swagger/OpenAPI docs. Triggers on: api contract, api generation, 接口约定, 生成api, swagger to ts, openapi, 接口文件, api层.

Its SKILL.md is about 1.9k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Backend & APIs, covering OpenAPI specifications and API design. It works with OpenAPI and TypeScript. The repository describes itself as: 一款专为开发者省时间、提效率的现代化中后台模板,跳过低质造轮子,上手即开工!Vue 3 + TS + Naive UI,更有 Bun+Vite 双引擎,性能直接拉满💥 毫秒级热更新不卡顿,开发丝滑,您试试!还有49 个成熟组件,演示页+文档双重完善,无残缺、无坑点,复制即用无需额外调试;配套 8 个 @robot-admin…. The licence is MIT.

When your agent uses it

  • : generating TypeScript API layer (type definitions + request functions) from page-spec JSON
  • Swagger/OpenAPI docs

Example prompts

  • “/api-contract”

Workflow steps

4 steps, taken from the step headings in SKILL.md.

  1. 从 page-spec 推导类型
  2. 生成类型定义文件
  3. 生成 API 请求函数文件
  4. useTableCrud 集成(可选)

What it can do on your machine

Read from SKILL.md and the folder at commit 48ce6e9. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are typescript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

API Contract loads about 1.9k tokens when it runs. Until then it costs about 58 tokens; SKILL.md has 184 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~58
When it runs · the whole SKILL.md, loaded when a task matches
~1.9k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from ChenyCHENYU/Robot_Admin at commit 48ce6e9, republished under its MIT licence (© ChenyCHENYU). 184 words, ~1,921 tokens.

Download SKILL.mdSave it as .claude/skills/api-contract/SKILL.md (or your agent's skills folder).
name
api-contract
description
Use when: generating TypeScript API layer (type definitions + request functions) from page-spec JSON or Swagger/OpenAPI docs. Triggers on: api contract, api generation, 接口约定, 生成api, swagger to ts, openapi, 接口文件, api层.

Skill: 接口约定(api-contract)

根据 page-spec JSON(来自 prototype-scan)或 Swagger/OpenAPI/接口文档, 生成符合 Robot Admin 规范的 TypeScript 类型定义 + API 请求函数。


触发

  • 模式 A:接收 page-spec JSON → 按页面字段推导请求/响应类型
  • 模式 B:接收 Swagger/OpenAPI JSON/YAML → 自动映射为 TS 类型
  • 模式 C:接收接口设计文档(MD/表格) → 手动解析接口定义

前置约定

请求方法(@robot-admin/request-core)
typescript
import {
  getData,
  postData,
  putData,
  deleteData,
} from '@robot-admin/request-core/axios'
工具函数HTTP Method典型场景
getData<T>(url, params?)GET列表查询、详情获取
postData<T>(url, data?)POST新增、登录、复杂查询
putData<T>(url, data?)PUT修改更新
deleteData<T>(url, params?)DELETE删除
URL 约定
/<domain>/<resource>             — 列表/新增
/<domain>/<resource>/:id         — 详情/修改/删除
/<domain>/<resource>/:id/<sub>   — 子资源

示例:

GET    /sys/users                 → 用户列表
POST   /sys/users                 → 新增用户
GET    /sys/users/:id             → 用户详情
PUT    /sys/users/:id             → 修改用户
DELETE /sys/users/:id             → 删除用户
GET    /sys/users/:id/roles       → 用户角色
统一响应体结构
typescript
interface ApiResponse<T = unknown> {
  code: string | number // '0' | '200' | 0 | 200 为成功
  data: T
  msg: string
}

列表响应:

typescript
interface ListResponse<T = Record<string, unknown>> {
  code: string | number
  data: {
    list: T[]
    total: number
  }
  msg: string
}

步骤

1. 从 page-spec 推导类型

根据 page-spec JSON 中的 columns、form、query 字段自动生成类型。

命名规则:

HTTP Method命名模式示例
GET(列表)Get{Domain}{Resource}ListResponseGetSysUsersListResponse
GET(详情)Get{Domain}{Resource}ByIdResponseGetSysUsersByIdResponse
POST(新增)Post{Domain}{Resource}ResponsePostSysUsersResponse
PUT(修改)Put{Domain}{Resource}ByIdResponsePutSysUsersByIdResponse
DELETE(删除)Delete{Domain}{Resource}ByIdResponseDeleteSysUsersByIdResponse
2. 生成类型定义文件

输出文件:src/api/generated/index.ts(追加或更新已有类型)

typescript
/*
 * @Author: ChenYu ycyplus@gmail.com
 * @Date: {{date}}
 * @Description: API 自动生成类型 — {{module}} 模块
 * Copyright (c) {{year}} by CHENY, All Rights Reserved 😎.
 */

/** {{资源}}列表查询参数 */
export interface Get{{Resource}}ListParams {
  page?: number
  pageSize?: number
  keyword?: string
  // ... 从 page-spec.query 推导
}

/** {{资源}}列表响应 */
export interface Get{{Resource}}ListResponse {
  code: string
  data: {
    list: {{Resource}}Item[]
    total: number
  }
  msg: string
}

/** {{资源}}数据项 */
export interface {{Resource}}Item {
  id: number | string
  // ... 从 page-spec.columns + page-spec.form 合并推导
  createTime?: string
  updateTime?: string
}

/** {{资源}}新增/编辑表单数据 */
export interface {{Resource}}FormData {
  // ... 从 page-spec.form 推导
}

/** {{资源}}详情响应 */
export interface Get{{Resource}}ByIdResponse {
  code: string
  data: {{Resource}}Item
  msg: string
}

/** {{资源}}新增响应 */
export interface Post{{Resource}}Response {
  code: string
  data: {{Resource}}Item
  msg: string
}

/** {{资源}}更新响应 */
export interface Put{{Resource}}ByIdResponse {
  code: string
  data: {{Resource}}Item
  msg: string
}

/** {{资源}}删除响应 */
export interface Delete{{Resource}}ByIdResponse {
  code: string
  data: Record<string, unknown>
  msg: string
}
3. 生成 API 请求函数文件

输出文件:src/api/<domain>-<resource>.ts

typescript
/*
 * @Author: ChenYu ycyplus@gmail.com
 * @Date: {{date}}
 * @Description: {{模块中文名}} — API 接口
 * Copyright (c) {{year}} by CHENY, All Rights Reserved 😎.
 */

import { getData, postData, putData, deleteData } from '@robot-admin/request-core/axios'
import type {
  Get{{Resource}}ListResponse,
  Get{{Resource}}ByIdResponse,
  Post{{Resource}}Response,
  Put{{Resource}}ByIdResponse,
  Delete{{Resource}}ByIdResponse,
} from './generated'

/**
 * * @description: 查询{{资源中文名}}列表
 * ? @param {Record<string, any>} params 查询参数
 * ! @return {Promise<Get{{Resource}}ListResponse>} 列表响应
 */
export const get{{Resource}}ListApi = (params?: Record<string, any>) =>
  getData<Get{{Resource}}ListResponse>('/<domain>/<resource>', params)

/**
 * * @description: 新增{{资源中文名}}
 * ? @param {Record<string, any>} data 表单数据
 * ! @return {Promise<Post{{Resource}}Response>} 新增响应
 */
export const create{{Resource}}Api = (data: Record<string, any>) =>
  postData<Post{{Resource}}Response>('/<domain>/<resource>', data)

/**
 * * @description: 获取{{资源中文名}}详情
 * ? @param {number|string} id 资源ID
 * ! @return {Promise<Get{{Resource}}ByIdResponse>} 详情响应
 */
export const get{{Resource}}ByIdApi = (id: number | string) =>
  getData<Get{{Resource}}ByIdResponse>(`/<domain>/<resource>/${id}`)

/**
 * * @description: 更新{{资源中文名}}
 * ? @param {number|string} id 资源ID
 * ? @param {Record<string, any>} data 更新数据
 * ! @return {Promise<Put{{Resource}}ByIdResponse>} 更新响应
 */
export const update{{Resource}}Api = (id: number | string, data: Record<string, any>) =>
  putData<Put{{Resource}}ByIdResponse>(`/<domain>/<resource>/${id}`, data)

/**
 * * @description: 删除{{资源中文名}}
 * ? @param {number|string} id 资源ID
 * ! @return {Promise<Delete{{Resource}}ByIdResponse>} 删除响应
 */
export const delete{{Resource}}Api = (id: number | string) =>
  deleteData<Delete{{Resource}}ByIdResponse>(`/<domain>/<resource>/${id}`)
4. useTableCrud 集成(可选)

当页面模式为 LIST 且使用 C_Table 时,额外输出 useTableCrud 配置:

typescript
import { useNaiveTableCrud } from '@robot-admin/request-core/naive'

const table = useNaiveTableCrud({
  api: {
    list: '/<domain>/<resource>',
    create: '/<domain>/<resource>',
    update: '/<domain>/<resource>/:id',
    remove: '/<domain>/<resource>/:id',
    get: '/<domain>/<resource>/:id',
  },
  columns: [...],
  defaultPageSize: 20,
})

验证规则映射

page-spec 中的 rules 字段转换为 @robot-admin/form-validate 的预设规则:

typescript
import { PRESET_RULES } from '@robot-admin/form-validate'
规则描述转换结果
必填PRESET_RULES.required('字段名')
长度2-20PRESET_RULES.length('字段名', 2, 20)
数值 18-65PRESET_RULES.range('字段名', 18, 65)
邮箱PRESET_RULES.email('邮箱')
手机号PRESET_RULES.mobile('手机号')
URLPRESET_RULES.url('URL')
身份证PRESET_RULES.idCard('身份证')
IPPRESET_RULES.ip('IP')

输出文件清单

文件说明
src/api/generated/index.ts追加自动生成的 TS 类型(接口响应/参数)
src/api/<domain>-<resource>.tsAPI 请求函数(CRUD 全套)

注意事项

  1. 不破坏已有文件:src/api/generated/index.ts 采用追加模式,不清空已有类型
  2. JSDoc 强制:所有导出函数必须包含 JSDoc(* @description / ? @param / ! @return)
  3. 文件头注释:每个新建文件必须包含 @Author / @Date / @Description 文件头
  4. 类型优先:所有 API 函数必须标注泛型返回类型 getData<T>(...)
  5. 路径别名:内部导入使用 @/api/generated,不使用相对路径 ./generated
  6. request-core 唯一来源:请求方法从 /axios、Naive CRUD 从 /naive 导入,不直接使用 axios 或根兼容入口

© ChenyCHENYU, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .github/skills/api-contract of ChenyCHENYU/Robot_Admin.

Open the folder on GitHubat commit 48ce6e9

Compare with similar skills

API Contract next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

API Contract compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
API Contract this skillChenyCHENYU/Robot_Admin1k—~1.9kAutomated safety check: PassMIT
defineRoute Route Builderbighadj22/codflow343—~924Automated safety check: PassApache-2.0
API DesignerJeffallan/claude-skills12k2 repos~2kAutomated safety check: PassMIT
OpenAPI to MCP Servermcp-use/mcp-use11k—~5.2kAutomated safety check: PassApache-2.0
Old Coder API DesignAmazingAng/old-coder7491 repos~3.4kAutomated safety check: PassMIT
Api2clialexknowshtml/api2cli455—~2.9kAutomated safety check: PassMIT

Similar skills

  • defineRoute Route Builder

    bighadj22/codflow

    Creates new API endpoints, and converts older ones, with the defineRoute() pattern used in cod-server, including auth strategies, scopes and OpenAPI output.

    343 GitHub stars~924 tokensUpdated yesterday
    Backend & APIsAuto-check passed
  • API Designer

    Jeffallan/claude-skills

    Designs REST and GraphQL APIs from resource modeling to an OpenAPI 3.1 contract, with versioning, pagination and RFC 7807 error handling.

    12k GitHub starsUsed in 2 repos~2k tokens
    Backend & APIsAuto-check passed
  • OpenAPI to MCP Server

    mcp-use/mcp-use

    Turns an OpenAPI or Swagger spec into an MCP server with the mcp-use TypeScript SDK, mapping each operation to a tool, wiring auth, testing and deploying.

    11k GitHub stars~5.2k tokensUpdated yesterday
    Backend & APIsAuto-check passed
  • Old Coder API Design

    AmazingAng/old-coder

    Reviews or designs an HTTP/JSON API's endpoints, auth, pagination, versioning and deprecations, guarding against inventing a bespoke interface or silently breaking consumers.

    749 GitHub starsUsed in 1 repo~3.4k tokens
    Backend & APIsAuto-check passed
  • Api2cli

    alexknowshtml/api2cli

    Generate a working CLI from any API, then wrap it in a Claude Code skill.

    455 GitHub stars~2.9k tokensUpdated 7 mo ago
    Backend & APIsAuto-check passed
  • Project

    samchon/nestia

    Defines the nestia product contract, workspace layout, package boundaries, the Go plugin composition model, and canonical commands.

    2.2k GitHub stars~3k tokensUpdated today
    Backend & APIsAuto-check passed

More from ChenyCHENYU/Robot_Admin

  • Branch Sync

    ChenyCHENYU/Robot_Admin

    A skill your agent uses when: upgrading dependencies, adding common features, or when the user explicitly requests branch sync check.

    1k GitHub stars~883 tokensUpdated yesterday
    Auto-check passed
  • Convention Audit

    ChenyCHENYU/Robot_Admin

    A skill your agent uses when: reviewing code for compliance with Robot Admin project conventions, or when generating a compliance report.

    1k GitHub stars~1.5k tokensUpdated yesterday
    Auto-check passed
  • Mock Codegen

    ChenyCHENYU/Robot_Admin

    A skill your agent uses when: generating mock data for development without a backend.

    1k GitHub stars~1.2k tokensUpdated yesterday
    Auto-check passed
  • Page Codegen

    ChenyCHENYU/Robot_Admin

    A skill your agent uses when: generating Vue 3 page code from either a page-spec JSON or a natural language description.

    1k GitHub stars~3.5k tokensUpdated yesterday
    Auto-check passed
  • Prototype Scan

    ChenyCHENYU/Robot_Admin

    A skill your agent uses when: analyzing Axure exported HTML prototype files or detailed design documents to extract page inventory, classify interaction patterns, and produce a structured page-spec…

    1k GitHub stars~1.6k tokensUpdated yesterday
    Auto-check passed
  • Route Sync

    ChenyCHENYU/Robot_Admin

    A skill your agent uses when: registering new pages into the dynamic router system.

    1k GitHub stars~1.5k tokensUpdated yesterday
    Auto-check passed

Categories

Questions about API Contract

What does API Contract do?

A skill your agent uses when: generating TypeScript API layer (type definitions + request functions) from page-spec JSON or Swagger/OpenAPI docs. API Contract is an agent skill from ChenyCHENYU/Robot_Admin. Use when: generating TypeScript API layer (type definitions + request functions) from page-spec JSON or Swagger/OpenAPI docs.

When should I use API Contract?

API Contract fits situations like: : generating TypeScript API layer (type definitions + request functions) from page-spec JSON; swagger/OpenAPI docs.

How do I install API Contract in Claude Code?

Run `npx skills add ChenyCHENYU/Robot_Admin --skill api-contract -a claude-code`. Or copy the skill folder (.github/skills/api-contract in ChenyCHENYU/Robot_Admin) into .claude/skills/api-contract in your project. Claude Code loads it when a task matches its description.

How do I install API Contract in Codex?

Run `npx skills add ChenyCHENYU/Robot_Admin --skill api-contract -a codex`. Or copy the skill folder (.github/skills/api-contract in ChenyCHENYU/Robot_Admin) into .agents/skills/api-contract in your project. Codex loads it when a task matches its description.

Can I use API Contract in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add ChenyCHENYU/Robot_Admin --skill api-contract -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/api-contract, .gemini/skills/api-contract, .github/skills/api-contract and .opencode/skills/api-contract in your project.

What does API Contract need to run?

SKILL.md names no scripts, command-line tools or credentials: API Contract is instructions for the agent only.

Does API Contract access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is API Contract safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does API Contract use?

API Contract is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does API Contract use?

About 1.9k tokens (SKILL.md is roughly 7.7k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to API Contract?

Skills that share tags, products or a category with API Contract: defineRoute Route Builder (bighadj22/codflow, 343 stars), API Designer (Jeffallan/claude-skills, 12k stars), OpenAPI to MCP Server (mcp-use/mcp-use, 11k stars) and Old Coder API Design (AmazingAng/old-coder, 749 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains API Contract?

ChenyCHENYU (a GitHub user) maintains it in ChenyCHENYU/Robot_Admin, which has 1,020 GitHub stars. The repository holds 7 skills in this directory. The repository was last updated on October 6, 2026.

Source: ChenyCHENYU/Robot_Admin on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.