mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-12-06 16:22:15 +00:00
feat(api): add an OpenAPI description of every route
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Bruno API Collection
|
||||
|
||||
[Bruno](https://www.usebruno.com/) collection mirroring every Gotenberg route. Update the collection when adding or modifying a route.
|
||||
[Bruno](https://www.usebruno.com/) collection mirroring every Gotenberg route. Update the collection, and the OpenAPI description, when adding or modifying a route.
|
||||
|
||||
## Structure
|
||||
|
||||
@@ -63,3 +63,4 @@ headers {
|
||||
3. For file uploads, use `@file(...)` with a suitable test file.
|
||||
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/`).
|
||||
6. Regenerate `openapi.yaml` too: see [OpenAPI description](../CONTRIBUTING.md#openapi-description).
|
||||
|
||||
@@ -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.
|
||||
|
||||
When adding a feature or route, write the Gherkin scenario before the Go code, and plan to update the Bruno collection (`.bruno/`) 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 (`openapi.yaml`) if a route changes.
|
||||
|
||||
## Project layout
|
||||
|
||||
@@ -32,6 +32,7 @@ test/integration/ -> Gherkin feature files + Go test infrastructure.
|
||||
test/corpus/ -> Release QA corpus: realistic documents, one feature file per engine.
|
||||
build/ -> Dockerfile, fonts, Chromium config.
|
||||
.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()`.
|
||||
@@ -159,6 +160,18 @@ Gherkin (BDD) via Godog with `testcontainers-go` for Docker orchestration. Featu
|
||||
|
||||
The release QA corpus is a separate suite, `make test-corpus`, that runs realistic documents with recorded facts; see `test/corpus/README.md`.
|
||||
|
||||
## 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.
|
||||
|
||||
When a route, a form field, a header or a status changes:
|
||||
|
||||
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.
|
||||
3. Run `npm run check:api` there: it checks the data against this checkout, and both copies 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
|
||||
|
||||
### Commits
|
||||
@@ -179,7 +192,7 @@ Before opening the PR, confirm:
|
||||
- [ ] `make fmt && make lint && make prettify && make lint-prettier` pass with zero warnings.
|
||||
- [ ] `make test-unit` passes.
|
||||
- [ ] Relevant `make test-integration TAGS=...` passes.
|
||||
- [ ] Bruno collection updated if routes were added or modified.
|
||||
- [ ] Bruno collection and OpenAPI description updated if routes, form fields or headers were added or modified. See [OpenAPI description](#openapi-description).
|
||||
|
||||
## Further reading
|
||||
|
||||
|
||||
2
go.mod
2
go.mod
@@ -33,6 +33,7 @@ require (
|
||||
go.opentelemetry.io/otel/sdk/log v1.47.0
|
||||
go.opentelemetry.io/otel/sdk/metric 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/sync v0.25.0
|
||||
golang.org/x/term v0.48.0
|
||||
@@ -143,7 +144,6 @@ require (
|
||||
go.opentelemetry.io/otel/log v1.47.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.11.1 // 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
|
||||
golang.org/x/crypto v0.59.0 // indirect
|
||||
golang.org/x/oauth2 v0.38.0 // indirect
|
||||
|
||||
5515
openapi.yaml
Normal file
5515
openapi.yaml
Normal file
File diff suppressed because it is too large
Load Diff
82
pkg/standard/openapi_test.go
Normal file
82
pkg/standard/openapi_test.go
Normal file
@@ -0,0 +1,82 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user