chore(api): leave the OpenAPI description to gotenberg.dev

This commit is contained in:
Julien Neuhart
2026-11-18 18:04:31 +01:00
parent fe01219b0d
commit d987094a21
5 changed files with 6 additions and 5606 deletions

View File

@@ -63,4 +63,4 @@ headers {
3. For file uploads, use `@file(...)` with a suitable test file. 3. For file uploads, use `@file(...)` with a suitable test file.
4. Verify the URL path matches the route's `Path` field exactly. 4. Verify the URL path matches the route's `Path` field exactly.
5. For new module folders, keep the naming consistent (e.g., `PDF/Pages/`). 5. For new module folders, keep the naming consistent (e.g., `PDF/Pages/`).
6. Regenerate `openapi.yaml` too: see [OpenAPI description](../CONTRIBUTING.md#openapi-description). 6. Update the OpenAPI description too: see [OpenAPI description](../CONTRIBUTING.md#openapi-description).

View File

@@ -19,7 +19,7 @@ For non-trivial changes, open an issue or a draft PR first. Describe what needs
One thing per PR. Keep features, bug fixes, and refactoring in separate PRs. One thing per PR. Keep features, bug fixes, and refactoring in separate PRs.
When adding a feature or route, write the Gherkin scenario before the Go code, and plan to update the Bruno collection (`.bruno/`) and the OpenAPI description (`openapi.yaml`) if a route changes. When adding a feature or route, write the Gherkin scenario before the Go code, and plan to update the Bruno collection (`.bruno/`) and the OpenAPI description if a route changes.
## Project layout ## Project layout
@@ -32,7 +32,6 @@ test/integration/ -> Gherkin feature files + Go test infrastructure.
test/corpus/ -> Release QA corpus: realistic documents, one feature file per engine. test/corpus/ -> Release QA corpus: realistic documents, one feature file per engine.
build/ -> Dockerfile, fonts, Chromium config. build/ -> Dockerfile, fonts, Chromium config.
.bruno/ -> Bruno API collection (mirrors every route). .bruno/ -> Bruno API collection (mirrors every route).
openapi.yaml -> OpenAPI description, generated from gotenberg.dev's reference data.
``` ```
Key interfaces live in `pkg/gotenberg/`: `Module`, `Provisioner`, `Validator`, `Debuggable`. Every module implements `Descriptor()` and self-registers via `init()`. Key interfaces live in `pkg/gotenberg/`: `Module`, `Provisioner`, `Validator`, `Debuggable`. Every module implements `Descriptor()` and self-registers via `init()`.
@@ -162,15 +161,13 @@ The release QA corpus is a separate suite, `make test-corpus`, that runs realist
## OpenAPI description ## OpenAPI description
`openapi.yaml` describes every route in OpenAPI 3.1, with the names and descriptions of [gotenberg.dev](https://gotenberg.dev). Don't edit it by hand: [gotenberg.dev](https://github.com/gotenberg/gotenberg.dev) generates it from its reference data (`src/data/routes.json`, `src/data/stages.json`), so the spec and the docs say the same thing. [gotenberg.dev](https://github.com/gotenberg/gotenberg.dev) serves the OpenAPI description of every route at [gotenberg.dev/openapi.yaml](https://gotenberg.dev/openapi.yaml). It generates it from its reference data (`src/data/routes.json`, `src/data/stages.json`), so the spec and the docs say the same thing.
When a route, a form field, a header or a status changes: When a route, a form field, a header or a status changes:
1. Update the reference data in gotenberg.dev, next to this checkout. 1. Update the reference data in gotenberg.dev, next to this checkout.
2. Run `npm run sync:openapi` there. It writes `openapi.yaml` here and the copy the site serves. 2. Run `npm run sync:openapi` there to regenerate `static/openapi.yaml`.
3. Run `npm run check:api` there: it checks the data against this checkout, and both copies against the data. 3. Run `npm run check:api` there: it checks the data against this checkout, and the spec against the data.
`TestOpenAPIListsEveryRoute` (`pkg/standard`) fails when a route the modules register is missing from `openapi.yaml`, or the other way round.
## Pull requests ## Pull requests

2
go.mod
View File

@@ -33,7 +33,6 @@ require (
go.opentelemetry.io/otel/sdk/log v1.47.0 go.opentelemetry.io/otel/sdk/log v1.47.0
go.opentelemetry.io/otel/sdk/metric v1.47.0 go.opentelemetry.io/otel/sdk/metric v1.47.0
go.opentelemetry.io/otel/trace v1.47.0 go.opentelemetry.io/otel/trace v1.47.0
go.yaml.in/yaml/v3 v3.0.6
golang.org/x/net v0.62.0 golang.org/x/net v0.62.0
golang.org/x/sync v0.25.0 golang.org/x/sync v0.25.0
golang.org/x/term v0.48.0 golang.org/x/term v0.48.0
@@ -144,6 +143,7 @@ require (
go.opentelemetry.io/otel/log v1.47.0 // indirect go.opentelemetry.io/otel/log v1.47.0 // indirect
go.opentelemetry.io/proto/otlp v1.11.1 // indirect go.opentelemetry.io/proto/otlp v1.11.1 // indirect
go.uber.org/multierr v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect
go.yaml.in/yaml/v3 v3.0.6 // indirect
go4.org v0.0.0-20261028031214-ed6929a230fe // indirect go4.org v0.0.0-20261028031214-ed6929a230fe // indirect
golang.org/x/crypto v0.59.0 // indirect golang.org/x/crypto v0.59.0 // indirect
golang.org/x/oauth2 v0.38.0 // indirect golang.org/x/oauth2 v0.38.0 // indirect

File diff suppressed because it is too large Load Diff

View File

@@ -1,82 +0,0 @@
package standard
import (
"os"
"slices"
"strings"
"testing"
"go.yaml.in/yaml/v3"
"github.com/gotenberg/gotenberg/v9/pkg/gotenberg"
"github.com/gotenberg/gotenberg/v9/pkg/modules/api"
)
// builtinRoutes are the routes the api module serves itself, outside any
// [api.Router]: the root, the health check, the version and the debug route.
var builtinRoutes = []string{"GET /", "GET /health", "HEAD /health", "GET /version", "GET /debug"}
// TestOpenAPIListsEveryRoute checks that openapi.yaml, which gotenberg.dev
// generates from its reference data (npm run sync:openapi), describes every
// route the standard modules register, and no other. A route that answers a
// Gotenberg 8 path with where it went, such as /forms/pdfengines/*, is left
// out: it describes no operation.
func TestOpenAPIListsEveryRoute(t *testing.T) {
data, err := os.ReadFile("../../openapi.yaml")
if err != nil {
t.Fatalf("read openapi.yaml: %v", err)
}
var spec struct {
OpenAPI string `yaml:"openapi"`
Paths map[string]map[string]any `yaml:"paths"`
}
err = yaml.Unmarshal(data, &spec)
if err != nil {
t.Fatalf("parse openapi.yaml: %v", err)
}
if spec.OpenAPI != "3.1.0" {
t.Errorf("openapi = %q, want 3.1.0", spec.OpenAPI)
}
var described []string
for path, operations := range spec.Paths {
for method := range operations {
described = append(described, strings.ToUpper(method)+" "+path)
}
}
registered := slices.Clone(builtinRoutes)
for _, descriptor := range gotenberg.GetModuleDescriptors() {
router, ok := descriptor.New().(api.Router)
if !ok {
continue
}
routes, err := router.Routes()
if err != nil {
t.Fatalf("routes of module %q: %v", descriptor.ID, err)
}
for _, route := range routes {
if strings.HasSuffix(route.Path, "/*") {
continue
}
registered = append(registered, route.Method+" "+route.Path)
}
}
slices.Sort(described)
slices.Sort(registered)
for _, route := range registered {
if !slices.Contains(described, route) {
t.Errorf("%s is missing from openapi.yaml: add it to gotenberg.dev's reference data, then run npm run sync:openapi", route)
}
}
for _, route := range described {
if !slices.Contains(registered, route) {
t.Errorf("%s is in openapi.yaml, but no module registers it", route)
}
}
}