Schema
Validate payloads and infer exact runtime-safe types.
import { UserSchema } from "./generated/schemas/User.js";const result = UserSchema.safeParse(apiResponse);if (result.success) {console.log(result.data.email);}
@apical-ts/craft generates Zod v4 schemas, route metadata, typed clients, and server wrappers from one OpenAPI document.
Use the generated contract directly or compose it with Hono, MSW, and React Query. By providing mathematical precision to your types, you also give Coding Agents the exact primitives they need to write safer code for you.
npx @apical-ts/craft generate \-i https://petstore.swagger.io/v2/swagger.json \-o ./generated \--client --server
Generate reusable schemas, route metadata, client operations, and server wrappers as small strong typed building blocks for your stack and agents.
Validate payloads and infer exact runtime-safe types.
import { UserSchema } from "./generated/schemas/User.js";const result = UserSchema.safeParse(apiResponse);if (result.success) {console.log(result.data.email);}
Access methods, paths, and maps for custom adapters and tooling.
import { getPetByIdRoute } from "./generated/routes/getPetById.js";const route = getPetByIdRoute();console.log({method: route.method,path: route.path,responseMap: route.responseMap,requestMap: route.requestMap,});
Call operations with discriminated unions. Zero bloat, only import what you use.
import { findPetsByStatus } from "./generated/client/findPetsByStatus.js";// Import just the operations you need// without pulling in a huge client bundle.const response = await findPetsByStatus({query: { status: "available" },});// Strict typing over status code and content type// using discriminated unions guides agents toward safe codeif (response.status === "200") {// Zod v4 parsed payloadconsole.log(response.parsed.data[0].name);}
Implement typed handlers with automatic runtime validation.
import type { getPetByIdHandler } from "./generated/server/getPetById.js";const handler: getPetByIdHandler = async (params) => {if (!params.isValid) return { status: "400" };const petId = params.value.path.petId;const pet = mockPets.find((candidate) => candidate.id === petId);if (!pet) return { status: "404" };return {status: "200",contentType: "application/json",data: pet,};};
Ready-to-use patterns
The integrations are meant to be inspectable starters. Copy the pattern you need, adapt it to your stack, and keep the generated contract as the stable base.
Derive framework routes from generated metadata and leverage automatic request validation.
View exampleType-safe Mocking. Use the same contract for production and your test suites with zero mismatch.
View exampleWrap operation functions in hooks without giving up tree-shaking or precise response typing.
View example