swagger-typescript-api
CLAUDE.md4.1k starsChanged 4 months agoMITView on GitHub
swagger-typescript-api generates TypeScript API clients (Fetch or Axios) from OpenAPI 2.0/3.0 specifications. It works as both a CLI tool (sta generate / swagger-typescript-api generate) and a library (generateApi()). The package outputs dual ESM/CJS formats. Templates live in templates/ with three tiers:
We split this CLAUDE.md into the rules it gives an agent
19 rules. About 0 are common, 10 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 89
Use import type for type-only imports.
- Very specific: line 90
Use namespace imports (import * as) for Node.js built-in modules.
- Distinctive: line 91
Use named imports for specific utilities from libraries.
- Very specific: line 92
All relative imports must include the .js extension (ESM requirement, even for .ts source files).
- Very specific: line 105
Use es-toolkit (and es-toolkit/compat) instead of lodash.
- Very specific: line 106
Use consola for all logging (consola.info, consola.debug, consola.warn, consola.success).
- Very specific: line 110
Avoid comments that restate the type signature or function name.
- Distinctive: line 111
Use comments to explain _why_, not _what_.
- Distinctive: line 112
When documentation seems redundant with the type signature, it is still acceptable in broadly-used public API surfaces.
- Very specific: line 116
Prefer unknown over any. Use any only when interfacing with untyped external APIs where unknown would require excessive casting.
- Very specific: line 117
Avoid @ts-ignore — use @ts-expect-error with the specific error code instead, so the suppression breaks when the underlying issue is fixed.
- Distinctive: line 118
Avoid catch-all pattern matches.
- Distinctive: line 119
Use labeled arguments (object parameters) for functions with multiple parameters of the same type to prevent argument transposition.
- Very specific: line 124
Do not use Conventional Commits format (e.g., feat:, fix:, chore:).
- Distinctive: line 126
Use imperative mood: "Add feature" not "Added feature" or "Adds feature"
- Distinctive: line 128
Keep the subject line under 72 characters
- Distinctive: line 129
Do not start with "This commit..." or "I changed..."
- Distinctive: line 145
Keep descriptions self-contained.
- Distinctive: line 151
If a PR requires significant context, add inline comments on your own diff to guide the reviewer through complex sections.
≈ “Common” is an estimate: at least 1 in 5 of the 25,680 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
swagger-typescript-api generates TypeScript API clients (Fetch or Axios) from OpenAPI 2.0/3.0 specifications. It works as both a CLI tool (sta generate / swagger-typescript-api generate) and a library (generateApi()). The package outputs dual ESM/CJS formats.
Common Commands
bun install --frozen-lockfile # Install dependencies
bun run build # Build with tsdown (dist/index.mjs, dist/index.cjs, dist/cli.mjs, dist/cli.cjs)
bun run test # Run all tests (vitest, 30s timeout)
bun run test -- tests/simple.test.ts # Run a specific test file
bun run test -- tests/spec/axios/basic.test.ts # Run a single spec test
bun run test -- -t "axios" # Run tests matching a name pattern
bun run test -- --update # Update snapshots
bun run lint # Lint with biome check
bun run format # Format with biome format --write
bun run format:check # Check formattingArchitecture
Code Generation Pipeline (CodeGenProcess.start)
- Template resolution —
TemplatesWorkerloads templates fromtemplates/base/,templates/default/(ortemplates/modular/), and optional custom templates. Priority: custom > base > original. - Schema fetching —
SwaggerSchemaResolverloads specs from file/URL/inline, supports JSON and YAML. - Swagger 2→3 conversion — Swagger 2.0 specs are converted to OpenAPI 3.0 via
swagger2openapi. - Component registration —
SchemaComponentsMapregisters all#/components/schemas/*entries with discriminators and enums sorted first. - Schema parsing —
SchemaParserFabriccreates type-specific parsers (MonoSchemaParsersubclasses insrc/schema-parser/base-schema-parsers/andcomplex-schema-parsers/). Each parser handles one type: enum, object, array, primitive, discriminator, oneOf, anyOf, allOf, not. - Route parsing —
SchemaRoutes(src/schema-routes/schema-routes.ts) walks all paths/methods to createParsedRouteobjects with request/response types, parameters, and module grouping. - Template rendering — Eta engine renders
.ejstemplates. Templates useincludeFile()with path prefixes (@base/,@default/,@modular/,@custom/). - Formatting —
CodeFormatterremoves unused imports via TypeScript LanguageService, then formats with Biome. - Optional JS translation —
JavascriptTranslatorcompiles TS output to JS +.d.tsusing the TypeScript compiler API.
Key Entry Points
index.ts(root) — CLI entry point using cittysrc/index.ts— Library entry, exportsgenerateApi(),generateTemplates(), constantssrc/code-gen-process.ts— Main orchestrator classsrc/configuration.ts—CodeGenConfigwith all options andTscode generation constructstypes/index.ts— All public TypeScript type definitions
Extension Points
- 13 lifecycle hooks —
onInit,onCreateComponent,onPreParseSchema,onParseSchema,onCreateRoute,onPrepareConfig,onFormatTypeName,onFormatRouteName,onCreateRouteName,onCreateRequestParams,onPreBuildRoutePath,onBuildRoutePath,onInsertPathParam - Custom schema parsers — Override via
config.schemaParserswithMonoSchemaParsersubclasses - Custom templates — User-provided templates override by matching filename
- Code generation constructs —
codeGenConstructsoption overrides TS primitives (ArrayType,UnionType,IntersectionType,RecordType, etc.) - Patchable instances —
PATCHABLE_INSTANCESinCodeGenProcessallows cross-instance injection
Template System
Templates live in templates/ with three tiers:
base/— Shared templates (data-contracts, http-client, route-docs, jsdoc)default/— Single-file output mode (api.ejs, procedure-call.ejs, route-types.ejs)modular/— Multi-file output mode (--modularflag, generates separate files per route module)
Templates receive it.config, it.modelTypes, it.routes, it.utils as context variables.
Test Structure
tests/simple.test.ts— Snapshot tests running all fixture schemas (v2.0 + v3.0) with basic optionstests/extended.test.ts— Same schemas with all extraction options enabledtests/spec/{feature}/basic.test.ts— 44 feature-specific tests, each with its own schema.json and snapshot- Tests call
generateApi(), read output files, and compare against vitest snapshots
Technical Details
- Package manager: Bun
- Module system: ESM (
"type": "module") - Build: tsdown (esbuild-based, outputs ESM + CJS with
.d.ts) - Node requirement: >=20
- Linting/Formatting: Biome (not ESLint/Prettier)
- Config file support:
swagger-typescript-api.config.{ts,js,json}via c12 - CI: Tests across Node 20, 22, 24, 25; format check → build → test
Style Guide
Formatting
Biome handles all formatting. Do not manually adjust formatting — run bun run format and accept the result. Key settings (via .editorconfig): 2-space indentation, LF line endings, UTF-8 encoding.
Imports
- Use
import typefor type-only imports. Keep type imports separate from value imports. - Use namespace imports (
import * as) for Node.js built-in modules. - Use named imports for specific utilities from libraries.
- All relative imports must include the
.jsextension (ESM requirement, even for.tssource files). - Order: Node builtins first, then external packages, then internal modules. Biome enforces this.
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { compact, merge } from "es-toolkit";
import type { GenerateApiConfiguration } from "../types/index.js";
import { CodeFormatter } from "./code-formatter.js";Utilities
- Use
es-toolkit(andes-toolkit/compat) instead of lodash. ThecreateLodashCompat()function exists only for backwards compatibility in templates — do not use it in source code. - Use
consolafor all logging (consola.info,consola.debug,consola.warn,consola.success). Do not useconsole.log.
Comments
- Avoid comments that restate the type signature or function name. A comment like
/** Returns the schema */ongetSchema()adds no value. - Use comments to explain why, not what. If the code is doing something non-obvious or working around a known issue, explain the reasoning.
- When documentation seems redundant with the type signature, it is still acceptable in broadly-used public API surfaces.
Defensive Practices
- Prefer
unknownoverany. Useanyonly when interfacing with untyped external APIs whereunknownwould require excessive casting. - Avoid
@ts-ignore— use@ts-expect-errorwith the specific error code instead, so the suppression breaks when the underlying issue is fixed. - Avoid catch-all pattern matches. Prefer exhaustive handling to enable compiler warnings when new variants are added.
- Use labeled arguments (object parameters) for functions with multiple parameters of the same type to prevent argument transposition.
- Annotate the types of ignored return values to catch signature changes at compile time.
Commit Messages
Do not use Conventional Commits format (e.g., feat:, fix:, chore:).
- Use imperative mood: "Add feature" not "Added feature" or "Adds feature"
- Focus on what changed, not implementation details
- Keep the subject line under 72 characters
- Do not start with "This commit..." or "I changed..."
Good: Add retry logic for failed API calls
Bad: feat: add retry logic
Pull Requests
PR titles follow the same rules as commit messages (no Conventional Commits, imperative mood).
PR descriptions should be detailed enough that a reader can understand the change without external context. Include:
- Problem: Define the issue clearly. Describe symptoms (errors, crashes, performance degradation) that justify the change.
- Solution: Explain the approach taken and why it was chosen over alternatives.
- Verification: How to test the change. Include specific steps or evidence (screenshots, metrics).
- Performance claims: Back up with concrete numbers (before/after benchmarks).
Keep descriptions self-contained. When linking to issues or discussions, summarize the relevant points rather than relying on the reader to follow links.
Reduce reviewer cognitive load
- Break large changes into smaller, focused PRs that each address a single concern.
- Structure commits to tell a story: each commit should be a logical, reviewable unit.
- If a PR requires significant context, add inline comments on your own diff to guide the reviewer through complex sections.
Trending
Less talk lately.about the whole repository
Who's talking about acacode/swagger-typescript-api
- usebruno/bruno“[Feature] Generating Type definitions for APIs to be used by the frontend Typescript app”GitHub · Mar 22, 2024 · 5 reactions
- mswjs/msw“MSW + Logrocket + Axios do not work together”GitHub · Sep 21, 2022 · 4 reactions
- oapi-codegen/oapi-codegen“Required inheritance and generated objects when using allOf”GitHub · Feb 23, 2022 · 3 reactions
- chainguard-forks/minio-console“Bump swagger-typescript-api from 13.2.3 to 13.12.2 in /web-app”GitHub · Jul 31, 2026 · 2 reactions
- biomejs/biome“🐛 Incorrect handling of leading slash patterns in `.gitignore` files in `2.0.0-beta.1`”GitHub · Mar 24, 2025 · 2 reactions
The biggest 5 of 50 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 50
Talked about on GitHub (50 times).
On GitHub · 50
- Mar 22, 2024[Feature] Generating Type definitions for APIs to be used by the frontend Typescript app — usebruno/bruno5 reactions · 2 comments
- Sep 21, 2022MSW + Logrocket + Axios do not work together — mswjs/msw4 reactions · 6 comments
- Feb 23, 2022Required inheritance and generated objects when using allOf — oapi-codegen/oapi-codegen3 reactions · 3 comments
- Jul 31, 2026Bump swagger-typescript-api from 13.2.3 to 13.12.2 in /web-app — chainguard-forks/minio-console2 reactions · 1 comment
- Mar 24, 2025🐛 Incorrect handling of leading slash patterns in `.gitignore` files in `2.0.0-beta.1` — biomejs/biome2 reactions · 5 comments
45 more on GitHub
- Apr 7, 2023[OpenAPI] The OpenAPI specification produced by 2.7/3.0 differs from 2.6 — api-platform/core2 reactions · 3 comments
- Jun 8, 2022Error: Cannot find module 'axios' — grandsilence/swagger-typescript-api-nextgen2 reactions · 2 comments
- Jul 29, 2026chore(deps-dev): bump swagger-typescript-api from 13.9.3 to 13.12.2 in /sdks/node — wandb/weave1 reaction · 4 comments
- Jul 27, 2026Bump the web-minor-and-patch group in /web with 7 updates — dimasma0305/rsctf1 reaction · 1 comment
- Mar 2, 2026Generate with other tools than openapi-generate — entur/openapi-validator-cli1 reaction · 1 comment
- Nov 27, 2024Using the clone method after fetching in the request method in TonApiClient causes a memory leak — tonkeeper/tonapi-js1 reaction · 4 comments
- Nov 13, 2024chore(deps): update dependency swagger-typescript-api to v13.0.23 — Belphemur/AddictedProxy1 reaction · 2 comments
- Aug 13, 2024chore(deps): update dependency swagger-typescript-api to v13.0.20 — Belphemur/AddictedProxy1 reaction · 2 comments
- Aug 11, 2024chore(deps): update dependency swagger-typescript-api to v13.0.19 — Belphemur/AddictedProxy1 reaction · 1 comment
- Aug 2, 2024chore(deps): update dependency swagger-typescript-api to v13.0.16 — Belphemur/AddictedProxy1 reaction · 2 comments
- Aug 1, 2024chore(deps): update dependency swagger-typescript-api to v13.0.15 — Belphemur/AddictedProxy1 reaction · 2 comments
- Jul 28, 2024chore(deps): update dependency swagger-typescript-api to v13.0.14 — Belphemur/AddictedProxy1 reaction · 2 comments
- Jul 15, 2024chore(deps): update dependency swagger-typescript-api to v13.0.13 — Belphemur/AddictedProxy1 reaction · 2 comments
- Jul 1, 2024chore(deps): update dependency swagger-typescript-api to v13.0.12 — Belphemur/AddictedProxy1 reaction · 2 comments
- Jun 29, 2024chore(deps): update dependency swagger-typescript-api to v13.0.11 — Belphemur/AddictedProxy1 reaction · 2 comments
- Jun 27, 2024chore(deps): update dependency swagger-typescript-api to v13.0.10 — Belphemur/AddictedProxy1 reaction · 2 comments
- Jun 19, 2024chore(deps): update dependency swagger-typescript-api to v13.0.7 — Belphemur/AddictedProxy1 reaction · 2 comments
- Jun 15, 2024chore(deps): update dependency swagger-typescript-api to v13.0.6 — Belphemur/AddictedProxy1 reaction · 2 comments
- Jun 2, 2024chore(deps): update dependency swagger-typescript-api to v13.0.5 — Belphemur/AddictedProxy1 reaction · 1 comment
- Oct 19, 2026chore(deps-dev): bump swagger-typescript-api from 13.0.23 to 13.12.2 in /frontend — nonamed19/LibrAIry_Autonomous-mobile-robot0 reactions · 1 comment
- Sep 18, 2026Bump the npm_and_yarn group across 1 directory with 14 updates — VapiAI/client-sdk-web0 reactions
- Aug 26, 2026Update dependency swagger-typescript-api to v13.12.2 [SECURITY] — oasisprotocol/rose-app0 reactions
- Aug 26, 2026chore(deps-dev): bump the development-dependencies group across 1 directory with 6 updates — ihiteshmodi/self_hosted_2anki0 reactions
- Aug 5, 2026Bump the npm_and_yarn group across 1 directory with 14 updates — Lukas-Riedel/Travel-Portal0 reactions
- Jul 31, 2026Bump swagger-typescript-api from 13.2.8 to 13.12.2 — Pier-Two/staking-ts0 reactions · 1 comment
- Jul 31, 2026chore(deps-dev): bump swagger-typescript-api from 13.1.3 to 13.12.2 in /packages/nocodb-sdk-v2 — Moeabdelaziz007/nocodb0 reactions
- Jul 31, 2026Bump swagger-typescript-api from 13.2.7 to 13.12.2 — Pier-Two/cardano-staking-api-scripts0 reactions
- Jul 31, 2026Bump swagger-typescript-api from 13.1.1 to 13.12.2 — Incomplete-Infinity/eve-companion0 reactions
- Jul 31, 2026Bump swagger-typescript-api from 13.2.16 to 13.12.2 in /src/PackManServer/ClientApp — mohammad-hosein-shahpouri/packman0 reactions
- Jul 31, 2026chore(deps:frontend): bump swagger-typescript-api from 13.6.5 to 13.12.2 in /frontend — tensorchord/watchu-gateway0 reactions
- Jul 31, 2026build(deps-dev): bump swagger-typescript-api from 13.2.7 to 13.12.2 — navikt/bidrag-ui-common0 reactions · 1 comment
- Jul 31, 2026chore(deps): Bump swagger-typescript-api from 13.2.15 to 13.12.2 — Sidnioulz/figmarine0 reactions · 1 comment
- Jul 31, 2026chore(deps-dev): bump swagger-typescript-api from 13.1.3 to 13.12.2 in /packages/nocodb-sdk-v2 — RichelynScott/nocodb0 reactions
- Jul 31, 2026chore(deps-dev): bump swagger-typescript-api from 13.6.5 to 13.12.2 — tsedio/tsed-cli0 reactions
- Jul 31, 2026build(deps-dev): bump swagger-typescript-api from 13.2.2 to 13.12.2 — Pier-Two/bitcoin-staking-api-scripts0 reactions
- Jul 31, 2026chore(deps-dev): bump swagger-typescript-api from 13.6.5 to 13.12.2 in /packages/cli-generate-http-client — tsedio/tsed-cli0 reactions
- Jul 31, 2026build(deps-dev): bump swagger-typescript-api from 13.6.7 to 13.12.2 in /web-app — georgmangold/console0 reactions
- Jul 31, 2026Bump the npm_and_yarn group across 1 directory with 2 updates — cicero-im/yousign-client0 reactions
- Jul 30, 2026chore(deps-dev): bump swagger-typescript-api from 13.0.22 to 13.12.2 in /src/GZCTF/ClientApp — Lil-Ran/GZCTF0 reactions · 2 comments
- Jul 30, 2026chore(deps-dev): Bump swagger-typescript-api from 13.2.18 to 13.12.2 — ainsleydev/website0 reactions · 1 comment
- Jul 30, 2026swagger-typescript-api: security issues <= 13.12.1 — NixOS/nixpkgs0 reactions
- Jul 16, 2026Bump swagger-typescript-api from 13.12.4 to 13.12.5 — juanutuy/azuracast0 reactions
- May 8, 2026chore(deps-frontend): bump swagger-typescript-api from 13.7.2 to 13.9.0 in /frontend — pyqdeck/pyqdeck-core0 reactions · 1 comment
- Mar 1, 2026Node - Bump swagger-typescript-api from 13.2.16 to 13.2.18 in /Frontend — dylanlangston/langston-wedding.com0 reactions
- Feb 9, 2026Bump swagger-typescript-api from 13.0.23 to 13.2.17 — reqpkg/changenow-io-sdk0 reactions
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

