buildOpenApiDocument builds it from a live Payload instance, and the downconverters are exported alongside it. Everything comes from the main entry point (see Exports).
Signature
The returned document already honors
options.openapiVersion: '3.0' and '3.1' are downconverted before the promise resolves, so you only call toOpenApi30 / toOpenApi31 yourself when you need an extra version of a 3.2 document.
Where options comes from
buildOpenApiDocument takes resolved options — the internal shape with every default filled in — not the raw object you pass to openapi(). You never construct it by hand. The plugin resolves your options once at config build time and stashes the result on config.custom under the package name; read it from there:
openapi:generate CLI does internally, and it means your script always builds with the same options the runtime endpoint uses — one source of truth.
ResolvedOptions is an internal type and is not exported. Keep the config.custom value opaque and pass it straight
through to buildOpenApiDocument — its parameter type checks the shape for you.Example script
scripts/build-spec.ts
Downconverters
The plugin always builds 3.2 and downconverts from there — the same passes run when you set
openapiVersion.
See also
- Generate command — the no-code path to a spec file
- Exports — the full public API surface
- OpenAPI version — how the 3.2-first build works