Introduction
@apical-ts/craft effortlessly turn your OpenAPI specifications into fully-typed Zod v4 schemas ready for runtime (client or server) validation and TypeScript development.
Why another Typescript OpenAPI generator?β
With @apical-ts/craft, you get some unique features that set it apart from other generators that implements runtime validation:
- π§ͺ Self-contained reusable route definitions β Zod schemas are generated for independent use. Bring your own client or server generator!
- π― Operation-based architecture β Each API operation is a standalone, fully-typed function. Avoid huge bundles and enjoy tree-shaking benefits
- π¦ Discriminated unions β Polymorphic schemas are handled with precise union types. You cannot access properties that are not guaranteed to exist, preventing runtime errors
- π Multiple content types β Supports JSON, XML, form data, and more
- π OpenAPI compatibility β Works with OpenAPI 2.0, 3.0.x, and 3.1.x specs
- π Resilient to edge cases β Handles multiple success codes (e.g.,
200,201) and wildcard status codes (e.g.,2XX,4XX) - π Writeonly and readonly properties β Respects OpenAPI's
readOnlyandwriteOnlyschema properties for accurate client and server typings - π§ Custom formats β Supports custom formats for strings with user-defined validation schemas
- π Circular reference support β Handles circular schema references gracefully without overflows
We all like the developer experience of tRPC or oRPC, but not always we're in control of the backend.
OpenAPI specifications provide a powerful way to define your API contracts, and with @apical-ts/craft, you can easily generate TypeScript code that strictly adheres to those contracts, all while enjoying a seamless developer experience and instant feedback on your API's correctness in your code editor.
Many existing generators lack flexibility and strong type safety. Most do not support multiple success responses or multiple content types, and their typings are often too looseβmaking it easy to accidentally access undefined properties. With stricter guardrails, @apical-ts/craft helps developers and coding agents catch mistakes early, leading to more robust and reliable implementations.
Despite @apical-ts/craft's can generate a fully functional client, it is designed to be flexible and modular. You can use the generated routes in your own custom client or server implementations without being locked into a specific framework or architecture.
Curious why you should choose this generator over others? See our comparison with alternative libraries for more details or check our comprehensive feature list for more information.
Quick Startβ
Get started with @apical-ts/craft in just a few commands:
# Generate schemas and client from an OpenAPI specification
npx @apical-ts/craft generate \
--client --server \
-i https://petstore.swagger.io/v2/swagger.json \
-o generated
cd generated
npm install
npm run build
This will create:
schemas/- Zod v4 schemas and TypeScript typesroutes/- For request and response validationclient/- Individual operation functions for each API endpointserver/- Typed handler wrappers, agnostic to your server framework
The generated code requires zod as a runtime dependency for schema validation.
Make sure to install it in your project.
Project Status & Versioningβ
@apical-ts/craft is under active development. In accordance with the
Semantic Versioning specification, the project will begin
strict semantic versioning starting from version 1.0.0. Until then, breaking
changes may occur in minor releases. To avoid unexpected breaking changes, it is
recommended to pin a specific version when using the CLI or as a dependency.
For example, when using npx:
npx @apical-ts/craft@0.3.1 generate ...
Replace 0.3.1 with the desired version. This ensures consistent behavior even
as the project evolves.
Live Demoβ
Explore the live demo to see @apical-ts/craft in action:
Next Stepsβ
- Learn how to use the CLI tool
- Dive into client generation to build type-safe API clients
- Check out our comprehensive feature documentation for a complete overview