Generate code

Generate from the contract, keep your handlers

A client and a server written by hand repeat what the contract already says, and drift from it. Generate both from the contract, in the libraries your language already uses, and keep your handlers when you regenerate.

Generate a client and a serverInstall API Genie

A contract change, regenerated

The generator writes an npm package; your handlers are in app.ts, outside it. Add a required field to the contract and regenerate: only the contract and the package change, and the compiler points at the handler that has to follow.

$ apigenie-generator server express openapi.yaml \
    -o server --package-name shipping-server
$ ls
app.ts  db.ts  node_modules  openapi.yaml  package-lock.json  package.json  server  tsconfig.json
$ # Shipment gains a required field, carrier; regenerate
$ apigenie-generator server express openapi.yaml \
    -o server --package-name shipping-server
$ git diff --stat
 openapi.yaml        | 4 +++-
 server/src/types.ts | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)
$ npx tsc --noEmit
app.ts(6,3): error TS2741: Property 'carrier' is missing in type '{ id: string; status: string; }' but required in type 'Shipment'.

What it covers

  • HTTP clientsTypeScript, Java, Go, Python, C# and Elixir.
  • HTTP serversSpring, ASP.NET Core, Express, FastAPI, Go, Phoenix, oRPC, and MCP servers (experimental).
  • Event-driven codeKafka, WebSocket, RabbitMQ and MQTT clients and applications from AsyncAPI.
  • GraphQL and gRPCElixir only: Absinthe servers, and elixir-grpc clients and servers.
  • Schemas and dataZod schemas from JSON Schemas (experimental), and example data for a schema.
  • OverlaysGenerator settings in an overlay, out of the API description.

The tool that does it

Step by step

Generate a client and a server: Generate a typed client and a server from one OpenAPI document, keep your code out of the generated files, and regenerate in CI.

Your handlers stay in your files

The generator writes its package and nothing outside it. Generate into the repository, and let CI check that the generated code still matches the contract.

Other use cases