mrkeyoor.com_
Tue 01 Sept 17:39 UTC
Dev Toolsevaluationupdated 30 Aug 2026

oapi-codegen review

oapi-codegen turns an OpenAPI 3.0 or 3.1 document into Go types, API clients, and server interfaces. It removes repetitive request parsing and response wiring while leaving business logic in code your team owns.

+5 / 2dstars / 7d
Verdict

Our oapi-codegen run installed 56 packages and passed its build plus all 6 test targets in 40 seconds, making it the cleanest trial in this group. Use it for a Go codebase that owns its OpenAPI contract and will review committed generated diffs. Test tricky unions, strict responses, authentication, and dependency upgrades on your actual specification before treating generation as a mechanical formality.

We ran it

Lab card: what happened when we ran oapi-codegenScreenshot of oapi-codegen (github.com/oapi-codegen/oapi-codegen)
Install✓ · 31s56 packages
Build✓ · 33s
Tests✓ · 7s6 passed · 0 failed of 6 (go test)
Repo1113 files~146,578 lines of source · 5.9 MB · 7 CI workflows

Answers from our run

Does oapi-codegen build from source?

Dependencies installed in 31 seconds (56 packages), and the build succeeded in 33 seconds. We cloned commit 2679cec into a clean Debian container with 3 CPUs and no project-specific setup.

Do oapi-codegen's tests pass?

Yes: 6 of 6 passed when we ran the project's own test command (go test). Some failures need services or credentials a bare container does not have.

Who should not use oapi-codegen?

Projects still on Swagger or OpenAPI 2.0: the README says to convert those specifications before using the generator.

What are the alternatives to oapi-codegen?

ogen, go-swagger, OpenAPI Generator. Our oapi-codegen run installed 56 packages and passed its build plus all 6 test targets in 40 seconds, making it the cleanest trial in this group.

Setup5/531-second install; build and all 6 test targets passed
Docs5/5Long README covers servers, clients, schemas, security, and upgrades
Community4/58,547 stars with current pushes and issue discussion
Maturity4/5v2.8.0 is active; documented edge cases can break output

Discussed on

  1. hnLessons learned from `oapi-codegen`'s time in the GitHub Secure Open Source Fund21 points
  2. hnOpenAPI Client and Server Code Generator for Golang3 points

Who it’s for

Go teams treating an OpenAPI document as the contract for clients or servers.
API owners using net/http, Chi, Echo, Fiber, Gin, gorilla/mux, or Iris.
Teams willing to commit generated code and review its diff when the spec or generator changes.
Developers who want YAML configuration, go:generate integration, and import mapping for split specifications.

Who it’s NOT for

Projects still on Swagger or OpenAPI 2.0: the README says to convert those specifications before using the generator.
Teams expecting generated authentication to secure a server by itself: the README says server output provides no security validation without the separate validation middleware and an AuthenticationFunc.
Strict-server users whose response schema lowers to any: open issue 2525 shows a small valid schema generating Go code that does not compile.
Organizations requiring generated output with no helper dependency: issue 2342 asks for a self-contained mode because current output can depend on the runtime package.
Users importing most of the pkg tree or overriding templates and expecting stable upgrades: the README calls those surfaces unstable.

Setup reality

Our sandbox installed 56 Go packages in 31 seconds. The build succeeded in 33 seconds, and all 6 test targets passed in 7 seconds.

The measured commit built in a Go 1.24 Bookworm image, while the current README says Go 1.25 or newer is required to build and install the latest code. Normal use needs an OpenAPI document, a version-pinned YAML config, and a generation step in local development or CI.

Generated servers still need handler implementations, request validation middleware, authentication code, and any chosen router. Version 2.8.0 also requires generated code to use oapi-codegen/runtime v1.6.0 or newer for several new features.

It generates Go boundaries, while you keep the handlers

oapi-codegen reads OpenAPI 3.0 and 3.1 specifications and writes Go models, clients, or server boilerplate. The ordinary server interface receives an HTTP request plus parsed parameters. Strict mode goes further by generating request and response objects, typed status variants, and marshaling around a smaller business-logic method. The generated layer is deliberately verbose enough to inspect instead of hiding the contract behind a large runtime framework.

Server targets cover 9 documented choices: Chi, Echo, Echo v5, Fiber, Fiber v3, Gin, gorilla/mux, Iris, and the standard library's net/http. Generated code currently needs Go 1.24 or 1.25 depending on the chosen server. Client generation supports request editors and typed response parsing, while model-only generation is available when transport code belongs elsewhere.

The 40-second checked run was genuinely clean

Our sandbox installed 56 Go packages in 31 seconds, built commit 2679cec in 33 seconds, and passed all 6 reported test targets in 7 seconds. The repository contained 1,113 files, about 146,578 lines of source, and occupied 5.9 MB at checkout. It had 7 CI workflow files, no root Dockerfile, and no tests directory.

Those measurements came from a 3-CPU, 8 GB unprivileged Debian container with no secrets. The image supplied Go 1.24, and the measured commit completed successfully there. The current development README now says Go 1.25 or newer is required to build and install oapi-codegen. Teams pinning v2.8.0 or a newer commit should follow that documented toolchain floor rather than generalizing our commit-specific result.

What happened when we ran it

Our run finished install, build, and tests without an error. Installation took 31 seconds, the build took 33 seconds, and the tests took 7 seconds. Go reported 6 passed and 0 failed out of 6. Among these 4 repositories, this was the only run that both completed its test step and reported no failure.

A passing generator suite does not prove that every private specification produces correct code. The README describes edge cases around unions, imported references, additional properties, security, custom templates, and generated dependency versions. The useful next test is to run the pinned binary on your own largest specification, compile the result, compare the generated diff, and exercise request validation at the server boundary.

OpenAPI 3.1 support still meets Go's type limits

Version 2.8.0 added initial OpenAPI 3.1 support, including webhooks, nullability expressed through a type array, and enums built from oneOf plus const. A 3.1 union such as string, number, or boolean cannot be represented directly in Go, so the generator emits any. The README also says allOf duplicate fields are resolved by letting the last schema win rather than merging every property definition.

That mapping can become a compile failure in strict mode. Open issue 2525 demonstrates a response schema that lowers to any, after which the generator declares a method on an interface-backed type that Go rejects. Issue 2107 asks for allOf property merging because the current last-definition behavior loses inherited details in a JSON Merge Patch use case. Specifications using either shape deserve dedicated fixture tests before an upgrade.

Generated security needs your authentication function

An OpenAPI security scheme does not make the generated server secure on its own. The README states that server-side output has no security validation out of the box. Teams must add the appropriate request-validation middleware and provide an AuthenticationFunc that handles the named scheme and required scopes. Client code can use supplied security providers, but credentials still come from application configuration.

Strict server generation also omits incoming-request validation unless middleware is added. When strict output imports response or request-body components from another generated package, that destination must itself enable strict-server generation or the referenced envelope type will be missing. These constraints are documented, which is good, yet they belong in the starter template because forgetting either can leave a server uncompilable or insufficiently checked.

Pin the generator, schema, and runtime together

The project recommends managing oapi-codegen as a Go tool and invoking it through go:generate with a YAML configuration file. It also recommends pinning the JSON schema used by editor tooling to the generator version. Version 2.8.0 requires oapi-codegen/runtime v1.6.0 or newer for duration handling, escaped path parameters, and typed response headers. Updating only one piece can break generated code.

The maintainers recommend committing generated files. That makes a generator or specification change visible in code review and lets downstream users build a package without running the generator. CI should regenerate and fail when the committed output drifts. The README discourages applying a project's full linter policy to generated files, since the output aims for idiomatic Go but does not promise compliance with every lint rule.

Stable configuration surrounds intentionally unstable extension points

The command line and YAML configuration are classed as stable, and compatibility flags may preserve older generated behavior after a correctness fix. The promise is narrower for code generation than for a hand-written library. Template overrides can drift with their input context, and most imports under pkg are considered unstable apart from Generate and its related Configuration surface.

Release v2.8.0 illustrates the tradeoff. It requires Go 1.25 for the generator, updates the runtime floor, and changes trailing-slash routing in net/http output so a declared path no longer behaves as a subtree catch-all. The project had 8,547 stars and 318 combined issues and pull requests when fetched, with the last push on August 28, 2026. Active maintenance is clear, and so is the need to review regenerated code.

oapi-codegen is an easy recommendation for Go teams that want contract-first code without adopting a full application framework. Our clean 40 seconds of build and testing lower the cost of trying it. The deciding evidence should come from your own spec corpus, especially strict responses, allOf combinations, multi-type 3.1 unions, authentication, and external references.

Alternatives

ProjectWhat it isPick it when
ogenA Go-first OpenAPI generator for clients and servers with validation in generated code.pick this instead when stronger generated validation and a more opinionated Go-only approach fit the project.
go-swaggerA Go implementation of Swagger 2.0 tooling for generation and specification work.pick this instead when the source contract remains Swagger 2.0 and conversion is undesirable.
OpenAPI Generator gh↗A multi-language generator covering many client, server, and documentation targets.pick this instead when one specification must produce SDKs in several languages beyond Go.

What people are saying

  1. [github-trending] oapi-codegen/oapi-codegen

Sources

  1. oapi-codegen README
  2. oapi-codegen v2.8.0 release
  3. Strict any response compile issue 2525
  4. allOf property merging issue 2107
  5. Self-contained output request 2342

More dev tools reviews

workmux · v2rayNG · SecLists · hashcat · eslint · fastfetch · the whole board →