AI agent skill
Teach your coding agent swagger-typescript-api-es
The repository ships an agent skill: a folder of instructions that Claude Code and other coding agents load when you ask them to generate or use an API client. With it, the agent knows the CLI flags, the config file, every option and the usual pitfalls, instead of guessing from the original swagger-typescript-api.
npx skills add hunghg255/swagger-typescript-api-esWhat is an agent skill?
A skill is a folder with a SKILL.md file: a short front matter (a name and a description of when to use it) followed by instructions in Markdown, plus optional reference files. Coding agents such as Claude Code load skills from .claude/skills/ in your project or ~/.claude/skills/ in your home folder.
Skills are loaded progressively, so an installed skill costs almost nothing until it is needed:
- 1
Discovery
At startup the agent only reads the name and description of each installed skill.
- 2
Activation
When your request matches the description, the agent reads SKILL.md: the workflow and rules.
- 3
Details on demand
Reference files (the full options list, patterns, …) are opened only when the task needs them.
What it covers
Setup
Installing the package, Node.js and ESM requirements, the first generation.
CLI and config file
Flags, swagger-typescript-api.config.ts, arrays of configs and precedence.
Options
Every generator option: input, output, client, types, extraction, naming.
Hooks
Renaming types and routes, changing parsed schemas and route data.
Templates
Copying the built-in Eta templates and overriding parts of the output.
The generated client
Creating the client, auth, errors, modular output and shared HttpClients.
Gotchas
The mistakes agents (and people) make, with the right fix for each.
The same ground as the human docs, written for an agent.
Read the docs
Install
With the skills CLI
Installs the skill of this repository with npx, nothing to add to your dependencies:
Manually
Copy the skills/swagger-typescript-api-es folder into a skills folder. In the project, the skill is shared with everyone who clones it; in your home folder, it is available in all your projects.
Start a new agent session afterwards: skills are discovered when the session starts. Update the skill the same way when a new version of the library is released.
Example prompts
No special syntax: ask for what you want and the agent loads the skill when the request is about generating or using the client.
Set up swagger-typescript-api-es in this project: generate an axios client from http://localhost:3000/api-json into src/api and add a gen-api script.
Our spec is ./openapi.yaml. Generate a modular fetch client where every module shares one HttpClient.
Send a bearer token with every request of the generated client and refresh it when it expires.
Rename every generated type so that it ends with Dto, and keep the enums as union types.
Methods return the whole response; make them resolve with the data directly and update the callers.
Wrap the generated pets endpoints in React Query hooks, with request cancellation.
What's inside
The files of skills/swagger-typescript-api-es, read when this site was built.
Preview SKILL.md
swagger-typescript-api-es
ESM + TypeScript rewrite of swagger-typescript-api.
Reads a Swagger 2.0 / OpenAPI 3.x schema (URL, local JSON/YAML file or in-memory object) and writes a
typed client: data contracts + an HttpClient (fetch or axios) + an Api class with one method per operation.
Install
Requires Node.js >= 20. ESM only (import, no require).
Quick start
Project setup: swagger-typescript-api.config.ts (or .js / .mjs / .cjs) in the directory you
run the CLI from. It may export one config or an array (each entry is generated in turn).
Programmatic:
Using the generated client (fetch):
Key gotchas
- CLI flags:
-u/--u,-o/--o,-n/--n,-t/--t, then kebab-case or camelCase (--union-enums=--unionEnums). Every flag except--extract-enumsneeds a value:--modular true(bare--modularfails with "value is missing"). Unknown flags are errors. - Precedence: config file <
--custom-config <file>(js/ts/json, one object) < CLI flags. With an array config, flags are applied to every entry. Errors print❌ SWAGGER-TYPESCRIPT-API error: ...and exit with code 1.silent: truehides logs but still prints errors. - Schema source:
spec>input(if the file exists) >url.urlwithouthttp(s)://is read as a local path. Thespecobject you pass is never modified. outputis a directory, never a file (namesets the file).output: falsewrites nothing and only returns the files.cleanOutput: trueempties the directory first.- Download (undici): respects
HTTP_PROXY/HTTPS_PROXY/NO_PROXY;disableProxyconnects directly;disableStrictSSLskips TLS checks;requestOptions.timeoutdefaults to 60 s (0= off);requestOptions.dispatcherfor a custom undici dispatcher. node-fetchagentis not supported.authorizationTokenis sent verbatim asAuthorization(includeBearer). - Generated signatures:
(pathParams..., query, data, params: RequestParams = {}), with required arguments moved before optional ones (e.g.updatePet(petId, data?, params)). The body is optional unlessrequestBody.required: true; withextractRequestParamsthe params object is optional when there are no path params and all query params are optional. Path params are wrapped inencodeURIComponent. - Modules come from the first path segment (
/pets/{id}->api.pets.getPet), not tags, unlessmoduleNameFirstTag: trueormoduleNameIndexis set. Routes likeGET /are methods onApi(modular:Common.ts). - Fetch client throws on non-2xx (the
HttpResponse, with.error) unlessdisableThrowOnError.unwrapResponseData: truemakes methods resolve with the body instead of the response. - A schema named
Errorgeneratesexport interface Error: import it asimport type { Error as ApiError }to avoid shadowing the global. - Output is formatted with oxfmt: built-in defaults <
.oxfmtrc.jsonin cwd <oxfmtOptrions(that misspelling is the real option name). sortRoutersis deprecated (usesortRoutes).toJS: trueemits.js+.d.ts.
References
references/options.md: everyIOptionskey with defaults, CLI flag mapping, hooks with signatures, exported types,generateApireturn value.references/patterns.md: config recipes (axios, local file, multiple APIs, large schemas, hooks, in-memory generation, custom templates, proxies/auth, CI).references/usage.md: using the generated client (fetch, axios,singleHttpClient, modular), auth, cancellation, error handling, file upload.
Docs: the repository README and the docs site with an online playground (the docs/ Next.js app in
the repo) that generates clients from a pasted spec or URL.