SuperAPI AI 工具集

api-schema-inferrer

编程与开发

查看项目

更新于 10-16 01:31

技能介绍

用途:在 OpenAPI 规范文件中,当接口的请求或响应含有 example/examples 但缺少 schema 时,自动依据示例数据推断并生成对应 schema,适合快速引导 schema 生成或从无显式 schema 的格式转换。

主要能力:自动检测 string、number、integer、boolean、array、object、null 类型;递归处理嵌套对象;从字符串模式推断 email、uri、date 等 format;将所有字段标记为 required(保守做法);添加占位描述;对请求和响应中的所有示例(包括 components.requestBodies 与 components.responses 下的共享 body)推断 schema;不覆盖已有 schema。此外会先把嵌套在 schema 块内的 example 迁移到 media-type 层级(OAS 规范位置)。

使用方式:先执行 pip install pyyaml。预览改动:python3 skills/api-schema-inferrer/scripts/infer_schemas.py path/to/spec.yaml --dry-run。应用改动:python3 skills/api-schema-inferrer/scripts/infer_schemas.py path/to/spec.yaml,会创建 spec.yaml.backup 备份。也可直接让 Claude 处理,如“Infer schemas from examples in my API spec at path/to/spec.yaml”。

限制与后续:推断后需人工复核类型、替换 TODO 描述、按需补充 enum、调整 required、添加 minLength/maxLength/minimum/maximum 等约束,并可用 api-spec-validator 技能验证。