generate-models
Generate TypeScript Models
Generate TypeScript interfaces/enums from OpenAPI via aptx-ft.
Prerequisites
pnpm add -D @aptx/frontend-tk-cli
Discovery Phase - MANDATORY FIRST STEP
Before executing any generation command, you MUST discover the actual project configuration.
For Monorepo Projects
-
Find packages directory:
ls -d packages/*/ -
Identify model package and get its name:
# Find package that likely contains models (domains, models, types, shared, etc.) cat packages/domains/package.json 2>/dev/null || cat packages/models/package.json 2>/dev/nullExtract the
"name"field - this is your--model-pathvalue.
Critical Rules
| ❌ NEVER Do This | ✅ ALWAYS Do This |
|---|---|
| Guess package name from project directory | Read package.json to get actual "name" |
Assume @project-name/models |
Use the exact value from "name" field |
Infer from packages/domains/ path |
Package name ≠ directory name |
Example Discovery
# User says: "generate to packages/domains"
$ cat packages/domains/package.json
{ "name": "@repo/domains", ... } ← Package name is @repo/domains
Workflow
- Discovery → Read
package.jsonfiles to get actual package names - Identify project type → recommend parameters
- Check output directory → determine if
--preserveis needed - Confirm with user → output dir, style, filters
- Execute → show command, get approval, run
Preserve Parameter Logic
ALWAYS check if target directory contains existing models before generating:
# Check if output directory has existing model files
ls ./src/models/*.ts 2>/dev/null || echo "empty"
| Directory State | Action |
|---|---|
| Empty or not exists | Generate WITHOUT --preserve |
| Has existing .ts files | Generate WITH --preserve to keep enum translations |
Why: When regenerating models in a non-empty directory, --preserve keeps manually translated enum names while adding new values. Only skip --preserve for fresh generation.
Project Types
| Type | Output | Command |
|---|---|---|
| Single project | ./src/models |
pnpm exec aptx-ft -i ./openapi.json model gen --output ./src/models --style module |
| Monorepo | ./packages/models/src |
pnpm exec aptx-ft -i ./openapi.json model gen --output ./packages/models/src --style module |
Key Options
| Option | Purpose |
|---|---|
--style module |
ES modules, individual exports (default, recommended) |
--style declaration |
Single declaration file (legacy compatibility) |
--name <Schema> |
Generate only specified models (repeatable) |
--preserve |
Keep manually translated enum names on regeneration |
Manifest Tracking
The CLI automatically tracks generated files and detects changes between generations.
Manifest CLI Options
| Option | Default | Purpose |
|---|---|---|
--no-manifest |
false | Disable manifest tracking |
--manifest-dir <path> |
.generated |
Custom manifest directory |
--dry-run |
false | Preview mode: generate report without updating manifest |
Generated Manifest Files
When manifest tracking is enabled (default), the following files are generated:
<output>/
├── .generated/
│ ├── manifest.json # Tracks all generated files
│ ├── deletion-report.json # Machine-readable change report
│ └── deletion-report.md # Human-readable change report with LLM suggestions
└── models...
Manifest Report Contents
The deletion-report.md includes:
- Summary table: Added/deleted/unchanged file counts
- Deleted files: List of files removed since last generation
- Added files: List of new files added
- LLM suggestions: Follow-up actions for handling deleted files
When to Use Manifest Options
| Scenario | Command |
|---|---|
| Normal generation | Omit manifest options (default) |
| CI/CD without tracking | Add --no-manifest |
| Preview changes before applying | Add --dry-run |
| Custom manifest location | Add --manifest-dir ./meta |
Automatic Barrel Updates
The CLI automatically updates barrel files (index.ts) after generation.
You no longer need to manually run barrel gen after generating models - the model gen command handles this automatically.
What Gets Updated
<output>/index.ts- Barrel file for the models directory
When Manual Barrel Update is Needed
The automatic update handles most cases. Use manual barrel gen only when:
- Fixing corrupted barrel files
- Processing non-standard directory structures
- One-time batch updates across multiple directories
Preserve Workflow
Preserve Workflow
Recommended when regenerating models after API updates. Keeps manually translated enum names while adding new values.
- Generate models
- Manually translate enums (e.g.,
Value1→Success) - API updates with new enum values
- Regenerate with
--preserve→ keeps translations, adds new values
# First generation
pnpm exec aptx-ft -i ./openapi.json model gen --output ./src/models
# After translating enums, regenerate with preserve
pnpm exec aptx-ft -i ./openapi.json model gen --output ./src/models --preserve
Quick Reference
# Check if output directory has existing models first
ls ./src/models/*.ts 2>/dev/null
# First generation (empty directory)
pnpm exec aptx-ft -i ./openapi.json model gen --output ./src/models
# Regeneration (non-empty directory) - use --preserve
pnpm exec aptx-ft -i ./openapi.json model gen --output ./src/models --preserve
# Declaration style
pnpm exec aptx-ft -i ./openapi.json model gen --output ./src/models --style declaration
# Selective generation
pnpm exec aptx-ft -i ./openapi.json model gen --output ./src/models --name User --name Role
# Preview changes without updating manifest
pnpm exec aptx-ft -i ./openapi.json model gen --output ./src/models --dry-run
# Disable manifest tracking (CI/CD)
pnpm exec aptx-ft -i ./openapi.json model gen --output ./src/models --no-manifest
# Custom manifest directory
pnpm exec aptx-ft -i ./openapi.json model gen --output ./src/models --manifest-dir ./meta
# Without pnpm
npx aptx-ft -i ./openapi.json model gen --output ./src/models
Output
TypeScript model files (interface/enum). Does not include request layer code.
Boundaries
This skill generates TypeScript models only:
- Does NOT generate request layer code (functions, hooks) → use
generate-artifacts - Does NOT adapt Materal-specific enum semantics → use
adapt-materal-enums - Does NOT validate OpenAPI specification correctness
- Only supports JSON format (not YAML)
Related Skills
- generate-artifacts: Full generation (models + request layer)
- adapt-materal-enums: Materal framework enum adaptation
- download-openapi: Fetch OpenAPI spec from URL
More from haibaraaiaptx/frontend-openapi-skills
download-openapi
Download remote OpenAPI/Swagger JSON specification from a URL to local file using aptx-ft CLI. TRIGGER when user mentions: (1) fetch/pull/download swagger or openapi from URL, (2) save API spec to openapi.json locally, (3) get API documentation from server, or (4) prepare local input for code generation. DO NOT TRIGGER when: generating code/types from local file, reading existing openapi.json, downloading non-OpenAPI files, or authentication is required.
25generate-artifacts
Generate frontend artifacts from OpenAPI via aptx-ft, including models and request clients. Use when user wants: (1) to generate API code from OpenAPI/Swagger, (2) React Query hooks from API spec, (3) Vue Query composables from API spec, (4) function-based API clients, (5) a standard flow for frontend projects without framework-specific business adaptation, (6) track generated files with manifest, (7) preview changes before generation, or (8) update barrel files automatically.
24adapt-materal-enums
Materal-specific enum adaptation workflow: fetch enum values from provider API, let LLM fill suggested_name, then apply patch with aptx-ft. Use ONLY when: (1) user mentions Materal framework, (2) Materal naming rules are required, or (3) adapting Materal enum semantics. Do NOT use for generic OpenAPI projects.
23generate-barrels
Generate barrel index.ts files for TypeScript projects. Use when user mentions: (1) barrel files, (2) index.ts exports, (3) re-export files, (4) simplify import paths, (5) create index files for directory, or (6) generate export aggregators.
18download-swagger-file
从 URL 下载 OpenAPI 3.x JSON 规范文件。用于:(1)从远程服务器获取 API 规范,(2)将 OpenAPI JSON 保存到本地,(3)为 TypeScript 模型生成准备规范。
6write-plugin
Write custom JS plugins for the aptx-ft CLI to add commands, generate code, or analyze OpenAPI specs. Use when: (1) writing or loading a plugin file (.js/.ts), (2) using --plugin/-p CLI flag, (3) creating custom CLI subcommands, (4) accessing parsed OpenAPI data via ctx.getIr/PluginContext/GeneratorInput, (5) building custom code generators (e.g. Axios clients), (6) producing reports from OpenAPI specs, (7) questions about PluginDescriptor/CommandDescriptor/OptionDescriptor. Do NOT use for standard generation (models, react-query, vue-query, barrel files) — use generate-artifacts or generate-models instead.
5