Install
openclaw skills install @harrylabsj/openapi-spec-generatorAuto-generate OpenAPI 3.x specs from code, traffic logs, or packet captures — with interactive refinement.
openclaw skills install @harrylabsj/openapi-spec-generatorTurn raw API surfaces into production-ready OpenAPI 3.x specifications. Ingest code repositories, HAR files, traffic logs, or packet captures — then interactively refine until you have a validated, shareable spec file.
Input: User chooses one or more sources:
Output: Confirmed input source and format. If multiple, merge mode (union of endpoints).
Input based on source type:
router.GET("/users/:id", ...)@GetMapping("/users/{id}")@app.get("/users/{id}")app.get('/users/:id', ...)Action: Cluster similar paths to identify path parameters:
GET /users/1
GET /users/2
GET /users/42
→ GET /users/{id}
Output: Endpoint list: method + path template + count/confidence.
Input: Endpoint list + source data. For Code source: Extract request/response structs/classes:
json:"name" binding:"required")@RequestBody, @Valid, DTO class fields with annotationsFor Traffic source: Aggregate observed request bodies and response bodies per endpoint. Infer JSON Schema from samples:
Output: Per-endpoint: request schema + response schemas (by status code). Confidence score for each inferred field.
Input: Endpoint list + schemas. Action: Classify parameters:
{id}, {userId} — extracted from URL template?page=1&limit=20 — from HAR query stringsAuthorization, X-Request-ID, Content-TypeOutput: Complete parameter list per endpoint with type, location, required flag, description (auto-generated or from code comments).
Input: Code annotations or captured headers. Action: Detect auth patterns:
Authorization: Bearer eyJ... header patternX-API-Key: ... or ?api_key=... patternsAuthorization: Bearer ... + token refresh patterns in codeAuthorization: Basic ... headerOutput: Security scheme definition + applied endpoints.
Input: All analyzed data. Action: Generate OpenAPI 3.x YAML (default) or JSON:
openapi: 3.0.3
info:
title: {inferred from project name or user input}
version: 1.0.0
servers:
- url: {inferred from captured traffic or user input}
paths:
/users/{id}:
get:
summary: Get user by ID
parameters:
- name: id
in: path
required: true
schema:
type: integer
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/User'
components:
schemas:
User:
type: object
properties:
id:
type: integer
name:
type: string
required: [id, name]
Output: Draft OpenAPI spec file.
Input: Draft spec + user feedback. Action: Present spec summary:
User can:
Output: Refined spec. Regenerate and validate after each round.
Input: Refined OpenAPI spec. Action:
# prism-config.yml
mock:
dynamic: true
cors: true
Output: Validated OpenAPI spec file + optional mock server config.
User: "从这个Go项目生成OpenAPI文档 [path: ~/projects/user-service/]" Expected Output:
Discovered 12 endpoints across 3 route groups:
GET /health
GET /api/v1/users
POST /api/v1/users
GET /api/v1/users/{id}
PUT /api/v1/users/{id}
DELETE /api/v1/users/{id}
...
Generated 5 schemas: User, CreateUserRequest, UpdateUserRequest, ErrorResponse, Pagination
Auth: Bearer JWT (detected from middleware)
Draft spec saved: openapi.yaml (12 endpoints, 5 schemas)
Warnings: 2 endpoints missing response description
User: "我从浏览器导出了HAR文件,帮我生成API文档 [upload: api-capture.har]" Expected Output:
Parsed HAR: 287 requests across 3 domains
Deduplicated to 23 unique endpoints
Confidence: High (multiple samples per endpoint)
14 endpoints have ≥5 response samples (schema inference: high confidence)
9 endpoints have 1-4 samples (schema inference: medium confidence)
Draft spec: openapi.yaml (23 endpoints, 31 schemas)
⚠️ 5 endpoints only have 200 OK responses captured (error schemas may be incomplete)
User: "帮我写一个用户管理API的OpenAPI文档:注册、登录、获取个人信息、更新个人信息、注销账号" Expected Output: Full OpenAPI spec with 5 endpoints, User/AuthRequest/AuthResponse schemas, JWT auth scheme, and standard error responses. Interactive refinement offered.
User: "分析这个Charles抓包日志,生成API文档 [upload: charles-session.chls]" Expected Output: Parse Charles Proxy session export → extract HTTP requests → deduplicate → infer schemas → generate spec. Note: binary/protobuf bodies flagged as "unparseable."
User: "帮我检查这个OpenAPI文件有没有问题,并补充缺失的描述 [upload: api-spec.yaml]" Expected Output: Validation report: "3 missing response descriptions, 1 broken $ref, 2 schemas missing 'type' field. Fixed version: api-spec-v2.yaml."
User: "基于刚生成的OpenAPI文档,生成一个Mock服务器配置"
Expected Output: Prism-compatible config + docker-compose snippet to start mock server. Instructions: "Run docker-compose up and mock API is live at http://localhost:4010."
Scenario: Developer inherits a 5-year-old Go microservice with zero API documentation. Input: "这个老项目没有任何API文档,帮我从代码生成 [path: ~/projects/legacy-order-service/]" Steps:
json:"order_id" binding:"required" → required field.// DEPRECATED: use /v2/orders.Scenario: Integrating with a partner API that has no documentation. Input: "对接第三方API没有文档,只有这个HAR文件 [upload: partner-api.har]" Steps:
/orders/1001, /orders/1002 → /orders/{orderId}.Scenario: Team wants to enforce consistent API design across 3 microservices. Input: "我们有3个服务的API,帮我生成统一的OpenAPI规范,检查不一致的地方" Steps:
user_id vs userId vs userID).openapi-gen.sh scan ~/projects/user-service/ — discovers endpoints and detects frameworkopenapi-gen.sh infer ~/projects/user-service/ — reviews inferred request/response schemasopenapi-gen.sh generate ~/projects/user-service/ --output openapi.yaml — generates validated OpenAPI 3.x spec| Condition | Behavior |
|---|---|
| Code repo has 0 routes detected | Flag: "No API routes found. Supported frameworks: Gin, Spring, FastAPI, Express. Check path or specify framework." |
| HAR file contains non-HTTP entries | Filter automatically; warn if filtered >50% of entries |
| PCAP contains encrypted HTTPS traffic | Warn: "Cannot decrypt HTTPS without session keys. Provide SSLKEYLOGFILE or use browser HAR export instead." |
| Binary protocols (gRPC, Thrift) | Flag as "protobuf detected — OpenAPI spec for gRPC requires .proto files" |
| >500 endpoints detected | Paginate output; generate spec in sections |
| Duplicate path+method combinations | Merge and warn of possible overloading |
| No response body samples for an endpoint | Flag as "schema unknown"; mark response as {} with warning |
| Code uses custom/non-standard routing | Fall back to AST-based function analysis; lower confidence |
| Error Code | Scenario | Handling |
|---|---|---|
| E-NO-ROUTES | No API routes found in code | Request framework specification; offer manual entry mode |
| E-HAR-PARSE-FAIL | HAR file is corrupted or invalid JSON | Show parse error location; suggest re-export from browser |
| E-PCAP-DECRYPT | PCAP contains only encrypted traffic | Explain SSLKEYLOGFILE requirement; suggest HAR export |
| E-SCHEMA-CONFLICT | Conflicting schema inference (same field, different types) | Flag field; show evidence for each type; ask user to resolve |
| E-VALIDATION-FAIL | Generated spec fails OpenAPI validation | Show exact validation errors with line numbers; auto-fix common issues |
| E-OVERSIZED | Generated spec exceeds reasonable size (>10K lines) | Offer to split by tag into multiple spec files |
| E-UNSUPPORTED-FRAMEWORK | Codebase uses a framework without route scanner | Offer AST-based scan (lower confidence) or manual endpoint entry |
{{YOUR_API_KEY}} placeholder.