How AI is applied across API Evangelist and APIs.io. Read my AI disclosure →
API Evangelist API Evangelist
Discovery
Learnings
Guidance
Toolbox
Alignment
API Evangelist LLC

Should I generate my OpenAPI from code, or write it by hand?

architecture Design & Architecture Updated August 12, 2026

Short answer

Either is fine as long as the result is accurate, reviewed, and version-controlled. Generated specs drift toward describing whatever the code happens to do, rather than what you promised.

The pragmatic answer: generate it if that is what your team will actually maintain, hand-author it if you can, and in both cases treat the output as an artifact that gets reviewed, linted and committed rather than as a build side effect.

The specific risk with generation is subtle. A generated document describes what the code does. A designed document describes what you promised. Those diverge in the places that matter most — a field you meant to be optional but the framework marks required, an internal endpoint that got annotated and published by accident, an error response nobody documented because the framework does not know about it. Generation makes the spec always current and never intentional.

The specific risk with hand-authoring is equally simple: it goes stale the moment someone ships a change without updating it.

Both risks have the same mitigation, which is why the argument matters less than people think. Lint the document in CI, run contract tests that compare the live API to the document, and fail the build when they disagree. Once the pipeline enforces agreement, how the file got written stops being interesting.

Go deeper in the guidance

This answer is distilled from the API Evangelist guidance catalog — the long-form treatment of each topic, with its own citations back into sixteen years of writing.

Read the original writing

The posts on apievangelist.com this answer is built on.