BeaverSpec π¦«
A modern OpenAPI code generator for Go
BeaverSpec generates production-ready Go server and client code from OpenAPI 3.x specifications β no JVM required, no YAML-hell, just a single Go binary.

Why BeaverSpec?
- No JVM β single Go binary, install in one command
- Go-idiomatic output β structs, interfaces,
error returns, context.Context
- Four frameworks β
net/http, Chi, Echo, Gin β switch with one flag
- Template customization β override any template with your own
text/template file
- Remote specs β point at a URL, no need to download specs manually
- Selective generation β models only, server only, or everything
Status
Phase 1: β
Complete β Core architecture, OpenAPI parsing, Go models generation
Phase 2: β
Complete β Server/client generation, framework support, security, validation, config system, integration polish
Features
- β
Complete OpenAPI 3.x parsing (local files and remote URLs)
- β
Go models with JSON tags and
Validate() methods
- β
allOf (struct embedding), oneOf/anyOf (discriminator, union types), enums, maps, arrays
- β
HTTP client with typed methods per endpoint
- β
Server handler interface + mock implementations
- β
Four framework targets:
net-http, chi, echo, gin
- β
Request/response validation with typed error models
- β
Content negotiation (multiple
produces/consumes types)
- β
Security scheme extraction (Bearer, API Key, Basic, OAuth2)
- β
Middleware generation (logging, CORS, rate limiter β stdlib only)
- β
Graceful shutdown example
main.go per framework
- β
External
$ref resolution (local files and URLs)
- β
Template customization and override system
- β
beaver.yaml config file with full schema support
Quick Start
# Install
go install github.com/imerljak/beaverspec/cmd/beaver@latest
# Generate from a local spec
beaver -spec openapi.yaml -output ./generated -module github.com/example/myapi
# Generate from a remote spec
beaver -spec https://petstore3.swagger.io/api/v3/openapi.json \
-output ./generated -module github.com/example/petstore
# Choose a framework
beaver -spec openapi.yaml -output ./generated -module github.com/example/myapi -framework chi
# Preview without writing files
beaver -spec openapi.yaml -output ./generated -module github.com/example/myapi -dry-run
Generated Files
For a spec with endpoints and schemas, beaver generates up to 9 files:
generated/
βββ models/
β βββ models.go # Typed structs, json tags, Validate() methods
β βββ models_test.go # Auto-generated validation tests
βββ client/
β βββ client.go # Typed HTTP client
βββ server/
β βββ interface.go # Handler interface β implement this
β βββ mocks.go # Mock implementations for quick start
β βββ handlers.go # HTTP adapter (routes to interface)
β βββ routes.go # Route registration per tag group
β βββ middleware.go # Logging, CORS, rate limiter (stdlib)
βββ cmd/server/
βββ main.go # Runnable example entrypoint (edit freely)
Config File
Create beaver.yaml next to your spec to avoid repeating flags:
spec: ./openapi.yaml
output: ./generated
module: github.com/example/myapi
framework: chi
generate:
models: true
client: true
server: true
exclude:
tags: [internal]
types:
overrides:
- format: uuid
go: "github.com/google/uuid".UUID
Then just run beaver with no flags.
CLI Reference
| Flag |
Default |
Description |
-spec |
β |
OpenAPI spec path or URL (required) |
-output |
. |
Output directory |
-module |
github.com/example/project |
Go module path |
-framework |
net-http |
Server framework: net-http, chi, echo, gin |
-config |
auto |
Config file path (auto-discovers beaver.yaml next to spec) |
-package |
models |
Package name for generated models |
-generator |
go |
Generator to use |
-dry-run |
false |
Print files that would be generated, don't write |
-debug |
false |
Enable debug logging |
-version |
β |
Print version and exit |
Project Structure
beaverspec/
βββ cmd/beaver/ # CLI entry point
βββ pkg/
β βββ core/ # Core types and interfaces
β βββ parser/ # OpenAPI parsing and normalization
β βββ config/ # Config file loading and merging
β βββ codegen/ # Validation codegen helpers
β βββ template/ # Template engine
βββ generators/
β βββ golang/ # Go generator + templates
β βββ templates/ # Per-framework Go templates
βββ examples/ # Example OpenAPI specs
Documentation
Development
go build -o beaver ./cmd/beaver
go test ./...
go run ./cmd/beaver -spec examples/petstore.yaml -output /tmp/gen -module github.com/example/petstore -dry-run
License
MIT License β see LICENSE for details.
Acknowledgments
Beavers are nature's engineers, known for building robust, well-structured dams. π¦«