npx skills add ...
npx skills add softaworks/agent-toolkit --skill openapi-to-typescript
Converts OpenAPI 3.0 JSON/YAML to TypeScript interfaces and type guards. This skill should be used when the user asks to generate types from OpenAPI, convert schema to TS, create API interfaces, or generate TypeScript types from an API specification.
npx skills add softaworks/agent-toolkit --skill openapi-to-typescript
Converts OpenAPI 3.0 specifications to TypeScript interfaces and type guards.
Input: OpenAPI file (JSON or YAML) Output: TypeScript file with interfaces and type guards
components/schemaspaths (request/response types)types/api.ts in current directory)Check before processing:
If invalid, report the error and stop.
| OpenAPI | TypeScript |
|---|---|
string | string |
number | number |
integer | number |
boolean | boolean |
null | null |
| Format | TypeScript |
|---|---|
uuid | string (comment UUID) |
date | string (comment date) |
date-time | string (comment ISO) |
email | string (comment email) |
uri | string (comment URI) |
Object:
Array:
Enum:
oneOf (Union):
allOf (Intersection/Extends):
For each schema in components/schemas:
required[] have no ?required[] have ?For each endpoint in paths:
Naming convention:
{Method}{Path}Request for params/body{Method}{Path}Response for responseFor each main interface, generate a type guard:
Type guard rules:
typeof value === 'object' && value !== null'field' in valuetypeofArray.isArray().includes()When encountering {"$ref": "#/components/schemas/Product"}:
Product)Input (OpenAPI):
Output (TypeScript):
| Error | Action |
|---|---|
| OpenAPI version != 3.0.x | Report that only 3.0 is supported |
| $ref not found | List missing refs |
| Unknown type | Use unknown and warn |
| Circular reference | Use type alias with lazy reference |