Developer and Text Tools

How to Generate an API Client from an OpenAPI Description

What an OpenAPI document contains, how it maps to typed models and client methods in TypeScript, Python and Go, and how to keep generated code tidy.

Saizul Amin
Saizul Amin2 Nov 2026 · 3 min read
How to Generate an API Client from an OpenAPI Description

How to Generate an API Client from an OpenAPI Description

An OpenAPI document is a machine-readable contract for an HTTP API: every path, every parameter, every request and response body, and how to authenticate. If an API you use publishes one, you can generate a typed client instead of writing request code and models by hand. This guide explains how that mapping works and how to keep the result useful, with the free OpenAPI client code generator.

What is in an OpenAPI document

The paths section lists endpoints and their HTTP methods. Each operation has an operationId, parameters in the path, query string or headers, an optional request body and responses by status code. The components.schemas section defines reusable data models with JSON Schema: properties, types, required fields, enums and formats. securitySchemes describes bearer tokens, API keys or basic authentication. Swagger 2.0, the older version, keeps the same ideas under different names.

From schemas to models

Each schema becomes a type. An object with properties becomes a TypeScript interface, a Python TypedDict or a Go struct. Required properties are plain fields; optional ones become optional fields, NotRequired entries or pointers with omitempty. Enums become string unions or constants, arrays become lists, and maps of free keys become records or dictionaries. Inline objects nested inside other schemas deserve their own names too, otherwise you end up with anonymous types that are hard to reuse.

From operations to methods

Every operation becomes a method named after its operationId. Path parameters are required arguments, a request body is the next argument, and query and header parameters are grouped into an options object or a parameters struct. The return type is the schema of the success response. A good client also turns error status codes into a clear error type that keeps the status and the response body.

Authentication

Generated clients should accept credentials once, when the client is created, and attach them to every request: an Authorization header for bearer tokens, a named header or query parameter for API keys, or basic credentials. Keep secrets in environment variables, never in generated code.

Naming quality starts in the spec

The generated code is only as readable as the document. Clear operationIds like listBooks and getBook give clear method names; missing ones force the generator to invent names from paths. Named schemas give better types than inline objects. If you own the API, improving the description improves every client at once.

Dependencies and size

Many generators produce large SDKs with their own runtime libraries. For many projects one readable file per language is enough: the built-in fetch for TypeScript, requests for Python and the standard library for Go. Small output is easy to review, debug and adapt.

Keep it maintainable

Decide early whether generated code is regenerated or edited. If you regenerate on every API change, never edit the files by hand; wrap them instead. If you generate once as a starting point, treat the files as your own code from then on and track API changes in reviews. Committing the OpenAPI document next to the client makes changes visible in diffs.

Test with real calls

Generated types reflect the description, not the server. Make a few real calls in a test environment and compare responses with the types, especially nullable fields and enums, which are often described inaccurately.

Limits

Some OpenAPI features have no clean equivalent in every language: polymorphic oneOf with discriminators, XML bodies, cookies, callbacks and webhooks usually need hand-written code. External references must be bundled into a single document before generating. A generated client describes the API at one moment in time and must be updated when the API changes.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages