Introducing a new way to review your PRs.

Read the announcement

oapi-codegen / oapi-codegen

Generate Go client and server boilerplate from OpenAPI 3 specifications

View on GitHub

20 documents · Updated Nov 23, 2026

overview

Knowledge Base updated: 2026-11-22

oapi-codegen knowledge base

Orientation

oapi-codegen turns OpenAPI specifications into Go models, clients, and server integrations. Its command-line entry point loads input and configuration, then delegates to the code-generation pipeline.

Core generation behavior lives in pkg/codegen: it resolves references, gathers schemas and operations, applies filtering and configuration, and renders Go through shared and framework-specific templates.

Generated-output behavior is controlled by configuration, OpenAPI extensions, templates, and import/type mappings. Example applications under examples/ demonstrate generated clients and servers across supported frameworks.

Architecture

flowchart TD
  CLI[cmd/oapi-codegen] --> Load[Input loading]
  CLI --> Config[Generator configuration]
  Load --> Refs[Reference resolution]
  Refs --> Pipeline[pkg/codegen pipeline]
  Config --> Pipeline
  Pipeline --> Validate[Filtering and validation]
  Pipeline --> Schemas[Schema and model generation]
  Pipeline --> Operations[Operation and client generation]
  Pipeline --> Servers[Server interface generation]
  Schemas --> Templates[Template rendering]
  Operations --> Templates
  Servers --> Frameworks[Framework server templates]
  Frameworks --> Templates
  Templates --> Output[Generated Go source]
  Examples[examples/] --> Output

Glossary

  • Strict server: generated server API form that uses typed request and response contracts.
  • Import mapping: configuration that maps referenced OpenAPI documents to Go import paths.
  • Additional properties: OpenAPI object fields not explicitly declared in a schema, represented through generated support code.
  • Overlay: an OpenAPI Overlay document that updates or removes elements from a source specification.
  • Vendor extension: an OpenAPI x-... field recognized by oapi-codegen to alter generated output.

Invariants

  • Generated code is driven by the configured generation switches and output settings; configuration behavior is defined in pkg/…/configuration.go.
  • Paths and operations are transformed into generated request, response, and client forms by pkg/…/operations.go.
  • Schema output must preserve the generator's schema-to-Go mapping rules, implemented and tested in pkg/…/schema.go and pkg/…/schema_test.go.
  • Rendered output is composed through shared helper logic and templates, centered on pkg/…/template_helpers.go and pkg/codegen/templates/**.
  • Framework examples exercise generated integration output under examples/**, including Fiber and Fiber v3 generated APIs.

Routing table