✓ Verified 💻 Development ✓ Enhanced Data

Neo Api To Ts Interface

Automatically generates TypeScript interfaces from REST API responses with Storybook-style documenta

Rating
4.4 (490 reviews)
Downloads
1,772 downloads
Version
1.0.0

Overview

Automatically generates TypeScript interfaces from REST API responses with Storybook-style documentation UI.

Complete Documentation

View Source →

api-to-ts-interface

Overview

The api-to-ts-interface skill automates the generation of TypeScript interfaces from REST API responses. It parses JSON/XML response payloads, infers type structures, and produces clean, compilable TypeScript code with accompanying Storybook-style documentation for easy exploration and sharing.

Key Benefits:

  • Eliminate manual interface writing
  • Ensure type accuracy across your codebase
  • Generate visual documentation instantly
  • Integrate seamlessly into agent workflows and CI/CD pipelines

Core Capabilities

  • Type Extraction: Recursively parses API responses to extract object structures, array types, unions, primitives, and nested hierarchies
  • Code Generation: Produces well-formatted, linted TypeScript interfaces with proper typing, readonly modifiers, and index signatures where appropriate
  • Storybook UI: Generates interactive documentation that visualizes type structures, shows examples, and provides searchable exploration
  • CLI Interface: Command-line tool for direct usage, scripting, and agent integration
  • Error-Free Output: Validates generated code syntax and ensures TypeScript compiler compatibility
  • Template System: Customizable templates for interfaces and Storybook components
  • Multi-Endpoint Support: Process multiple API responses and merge or separate interfaces as needed

Directory Structure

text
api-to-ts-interface/
├── scripts/               # Core implementation
│   ├── generator.ts       # TypeScript code generation
│   ├── parser.ts          # Response parsing & type inference
│   ├── storybook.ts       # Storybook UI generation
│   └── cli.ts             # CLI command handler
├── references/            # Templates & type definitions
│   ├── types.json         # Common TS type mappings
│   └── templates/
│       ├── interface.ts   # Interface code template
│       └── storybook.md   # Storybook doc template
├── assets/                # UI assets
│   └── ui/
│       ├── components/    # Storybook React components
│       └── styles/        # CSS/styling
├── package.json           # Dependencies & metadata
├── README.md              # User guide
└── SKILL.md               # This file (skill definition)

Key Components

Parser (scripts/parser.ts)

  • Accepts JSON/XML strings or file paths
  • Recursively traverses response structure
  • Infers types: primitive, object, array, union, nullable
  • Detects optional fields and discriminants
  • Outputs internal type definition representation

Generator (scripts/generator.ts)

  • Consumes parsed type definitions
  • Applies TypeScript best practices:
  • Uses readonly for constant properties
  • Adds index signatures for dynamic objects
  • Generates proper union types (string | null)
  • Handles recursive and circular references
  • Merges with reference types from references/types.json
  • Validates syntax via TypeScript compiler API
  • Outputs formatted .ts files

Storybook Renderer (scripts/storybook.ts)

  • Converts interfaces into Storybook CSF (Component Story Format)
  • Generates interactive type explorer UI
  • Renders nested structures with collapsible sections
  • Embeds example values from actual API responses
  • Produces standalone HTML or full Storybook project scaffolding

CLI (scripts/cli.ts)

  • Powered by Commander.js or Yargs
  • Commands:
  • generate: Single interface generation
  • batch: Process multiple responses
  • storybook: Create documentation UI
  • validate: Check TS syntax of generated code
  • Options for output paths, formatting, template selection
  • Exit codes for CI integration

Usage Examples

CLI Basic

bash
ts-interface generate --response api-response.json --output types.ts
ts-interface storybook --input types.ts --docs-dir ./docs

Agent Integration

javascript
// In an OpenClaw agent workflow:
const result = await message({
  to: "api-to-ts-interface",
  message: "Generate TypeScript interfaces from this API response: " + JSON.stringify(apiResponse)
});

Programmatic API

typescript
import { Parser, Generator, Storybook } from 'api-to-ts-interface';

const parser = new Parser();
const types = parser.parse(apiResponseJSON);

const generator = new Generator();
const tsCode = generator.generate(types, { template: 'interface' });

const storybook = new Storybook();
const html = storybook.render(types);

Configuration

The skill respects configuration files:

  • .apitotsrc.json: Project-level settings (output paths, template variants)
  • types.json in project root: Custom type overrides
Common options:
json
{
  "output": "src/types/",
  "mergeInterfaces": true,
  "storybook": true,
  "format": "prettier",
  "template": "default"
}

Trigger Phrases

This skill activates on phrases such as:

  • "Generate TypeScript interfaces from this API response"
  • "Convert this JSON response to TypeScript types"
  • "Create TS interfaces for my API responses"
  • "Document my API responses as TypeScript interfaces"
  • "Generate Storybook docs for my API response types"
  • "Automate TypeScript interface generation from API calls"
  • "Convert these REST API responses to TypeScript"

Acceptance Criteria Compliance

  • ✅ Trigger phrase recognition built into SKILL.md definition
  • ✅ Generates compilable TypeScript from nested JSON structures
  • ✅ Storybook UI renders type hierarchies with examples
  • ✅ Handles arrays, unions, optionals, and deep nesting
  • ✅ CLI supports expected command syntax
  • ✅ Clear error messages for malformed input
  • ✅ Follows TypeScript best practices (no any abuse)
  • ✅ Performance optimized for typical API response sizes (<10s for 100KB JSON)

Dependencies

  • typescript: TypeScript compiler API for validation
  • commander or yargs: CLI framework
  • prettier: Code formatting
  • json-schema-to-typescript (optional): For schema-based generation
  • react & @storybook/react: Storybook UI components
  • jsonschema or fast-xml-parser: XML support

License

MIT

Installation

Terminal bash

openclaw install neo-api-to-ts-interface
    
Copied!

💻Code Examples

└── SKILL.md # This file (skill definition)

-skillmd--this-file-skill-definition.txt
## Key Components

### Parser (`scripts/parser.ts`)
- Accepts JSON/XML strings or file paths
- Recursively traverses response structure
- Infers types: primitive, object, array, union, nullable
- Detects optional fields and discriminants
- Outputs internal type definition representation

### Generator (`scripts/generator.ts`)
- Consumes parsed type definitions
- Applies TypeScript best practices:
  - Uses `readonly` for constant properties
  - Adds index signatures for dynamic objects
  - Generates proper union types (`string | null`)
  - Handles recursive and circular references
- Merges with reference types from `references/types.json`
- Validates syntax via TypeScript compiler API
- Outputs formatted `.ts` files

### Storybook Renderer (`scripts/storybook.ts`)
- Converts interfaces into Storybook CSF (Component Story Format)
- Generates interactive type explorer UI
- Renders nested structures with collapsible sections
- Embeds example values from actual API responses
- Produces standalone HTML or full Storybook project scaffolding

### CLI (`scripts/cli.ts`)
- Powered by Commander.js or Yargs
- Commands:
  - `generate`: Single interface generation
  - `batch`: Process multiple responses
  - `storybook`: Create documentation UI
  - `validate`: Check TS syntax of generated code
- Options for output paths, formatting, template selection
- Exit codes for CI integration

## Usage Examples

### CLI Basic

const html = storybook.render(types);

const-html--storybookrendertypes.txt
## Configuration

The skill respects configuration files:
- `.apitotsrc.json`: Project-level settings (output paths, template variants)
- `types.json` in project root: Custom type overrides

Common options:
example.txt
api-to-ts-interface/
├── scripts/               # Core implementation
│   ├── generator.ts       # TypeScript code generation
│   ├── parser.ts          # Response parsing & type inference
│   ├── storybook.ts       # Storybook UI generation
│   └── cli.ts             # CLI command handler
├── references/            # Templates & type definitions
│   ├── types.json         # Common TS type mappings
│   └── templates/
│       ├── interface.ts   # Interface code template
│       └── storybook.md   # Storybook doc template
├── assets/                # UI assets
│   └── ui/
│       ├── components/    # Storybook React components
│       └── styles/        # CSS/styling
├── package.json           # Dependencies & metadata
├── README.md              # User guide
└── SKILL.md               # This file (skill definition)
example.js
// In an OpenClaw agent workflow:
const result = await message({
  to: "api-to-ts-interface",
  message: "Generate TypeScript interfaces from this API response: " + JSON.stringify(apiResponse)
});
example.ts
import { Parser, Generator, Storybook } from 'api-to-ts-interface';

const parser = new Parser();
const types = parser.parse(apiResponseJSON);

const generator = new Generator();
const tsCode = generator.generate(types, { template: 'interface' });

const storybook = new Storybook();
const html = storybook.render(types);
example.json
{
  "output": "src/types/",
  "mergeInterfaces": true,
  "storybook": true,
  "format": "prettier",
  "template": "default"
}

Tags

#web_and-frontend-development #api #script

Quick Info

Category Development
Model Claude 3.5
Complexity One-Click
Author martinforsulu
Last Updated 3/10/2026
🚀
Optimized for
Claude 3.5
🧠

Ready to Install?

Get started with this skill in seconds

openclaw install neo-api-to-ts-interface