oapi-codegenBattle-tested: This generator is continuously tested against 2,000+ real-world OpenAPI specs, successfully generating and compiling over 20 million lines of Go code. Handles complex specs with circular references, deep nesting, and union types.
Using oapi-codegen allows you to reduce the boilerplate required to create or integrate with
services based on OpenAPI 3.x, and instead focus on writing your business logic, and working
on the real value-add for your organization.
oneOf, anyOf, allOf, and if/then/else with intelligent type merging, runtime.Either[A, B] for two-element unions, and runtime.Conditional[T, E] for conditional schemasmap[string]interface{} or custom typesValidate() methods on generated typesWithResponse clients - Opt-in <Op>WithResponse siblings that return a typed envelope with per-status bodies, typed headers, and the raw *http.Response - useful for operations that legitimately return multiple 2xx statuses or need typed access to response headerserror interface automatically$ref resolution - Split specs across multiple files with relative $ref references (auto-detected from spec path, or set base-path in config)# Install
go install github.com/doordash-oss/oapi-codegen-dd/v3/cmd/oapi-codegen@latest
# Generate code from the Petstore example
oapi-codegen https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.yaml > petstore.go
The examples directory contains useful examples of how to use oapi-codegen.
This project is a fork of oapi-codegen v2, fully reworked to address limitations in the original.
Tested against 2,137 real-world OpenAPI 3.0 specs:
| Version | Passed | Failed | Pass Rate |
|---|---|---|---|
| v3 | 2,137 | 0 | 100% |
| v2 | 1,159 | 978 | 54.2% |
| Category | v2 | v3 |
|---|---|---|
| OpenAPI Support | 3.0 only | 3.0, 3.1, 3.2 |
| Parser | kin-openapi |
libopenapi |
| Circular References | Limited | Full support |
| Union Types (oneOf/anyOf) | Basic | Full with optimizations |
| Name Conflicts | Manual fix required | Automatic resolution |
| Validation | None | Validate() methods |
| Server Scaffold | Interface only, manual boilerplate | Full typed solution (service, middleware, main.go) |
| Webhooks | Not supported | Full type generation with filtering |
| Filtering | Tags, operation IDs | + Paths, webhooks, extensions, schema properties |
| Overlays | Single | Multiple, applied in order |
| Output | Single file | Single or multiple files |
| Templates | Monolithic | Composable with {{define}} blocks |
| Programmatic API | Limited | Full (ParseContext, TypeTracker) |
| Server Frameworks | 7 (Chi, Echo, Fiber, Gin, Gorilla, Iris, std-http) | 13 (+ Beego, go-zero, Kratos, GoFrame, Hertz, fasthttp) |
| MCP Server | None | Full (AI assistant integration) |
If you're migrating from v2, please refer to the migration guide.
This project is licensed under the Apache License 2.0.
See LICENSE.txt for details.
See NOTICE.txt for third-party components and attributions.
Contributions to this project require agreeing to the DoorDash Contributor License Agreement.
See CONTRIBUTOR_LICENSE_AGREEMENT.txt.
$ claude mcp add oapi-codegen-dd \
-- python -m otcore.mcp_server <graph>