dev-tools 5 min read

Gleece - Code-First OpenAPI v3 Generation for Go

Gleece transpiles Go annotated routes into OpenAPI v3 specs, validation, and auth middleware — supporting Gin, Echo, Chi, Gorilla Mux, and Fiber from a single source of truth.

By
Share: X in
Gleece - Go API Framework

TL;DR

TL;DR: Gleece is a Go transpiler that reads route annotations and generates OpenAPI v3 specs, input validators, and auth middleware for your choice of Gin, Echo, Chi, Gorilla Mux, or Fiber — zero runtime overhead.

Source and Accuracy Notes

⚠️ This section is MANDATORY. All links must be verified from actual source, not guessed.

What Is Gleece?

Gleece is a design-first, code-focused API framework for Go developers. You annotate your route handlers with structured comments, run the Gleece CLI, and it generates battle-tested route files for your chosen HTTP framework — along with a live OpenAPI v3.0/v3.1 specification and input validation layer.

The README frames it as “TypeScript’s TSOA for Go.” Where TSOA brings code-first OpenAPI to Node/Express, Gleece does the same for Go’s router ecosystem.

Core features (from README):

  • Automatic OpenAPI v3.0 and v3.1 specification generation from code annotations
  • Built-in input validation enforced at the route level
  • Security-first authorization flows baked into generated routes
  • Five supported routers: Gin, Echo, Gorilla Mux, Chi, Fiber
  • Design/build time only — generated routes are plain Go code, no runtime magic
  • VSCode extension with annotation highlighting and IntelliSense

Setup Workflow

Step 1: Install the runtime and CLI

go get github.com/gopher-fleece/runtime
go get github.com/gopher-fleece/gleece/v2
go install github.com/gopher-fleece/gleece/v2

gleece is now available as a global CLI. The runtime package is the only runtime dependency.

Step 2: Annotate your routes

Gleece reads annotated Go route handlers. A minimal annotated controller looks like this:

package controller

// @Summary Get user by ID
// @Description Returns a single user record
// @Tags users
// @Accept json
// @Produce json
// @Param id path int true "User ID"
// @Success 200 {object} User
// @Failure 400 {object} Error
// @Router /users/{id} [get]
func GetUser(id int) (*User, error) {
    // your logic
}

Step 3: Generate routes

gleece generate -p ./controllers -o ./routes

Gleece writes Go source files for your chosen router. Register them in your main.go:

package main

import (
    "your-app/routes"
    "github.com/gin-gonic/gin"
)

func main() {
    r := gin.Default()
    routes.RegisterRoutes(r)
    r.Run()
}

Step 4: Get the OpenAPI spec for free

After generation, Gleece also emits an openapi.json (or .yaml) in your output directory — ready to feed into Swagger UI, Redoc, or any API gateway that accepts OpenAPI.

Supported Frameworks

Gin, Echo, Gorilla Mux, Chi, and Fiber are all first-class citizens. The README confirms all five are explicitly supported with integration documentation.

Deeper Analysis

Why Gleece exists: The Go ecosystem has no native equivalent to TSOA, NestJS decorators, or Ruby’s apipie-rails. Writing OpenAPI specs by hand is error-prone and drifts from implementation over time. Gleece closes that gap with a build step, keeping spec and code in sync mechanically rather than manually.

Architecture: Gleece is almost exclusively a build-time transpiler. It reads your annotated Go files and emits more Go. The generated code has no Gleece runtime dependency beyond the lightweight runtime package. This means no performance penalty and no vendor lock-in — the output is just your code.

OpenAPI coverage: Supports both OpenAPI 3.0.0 and 3.1.0, which covers the full JSON Schema dialect. The README notes this explicitly via badges.

VSCode extension: An official extension provides annotation syntax highlighting and autocomplete, reducing friction when writing route metadata.

Practical Evaluation Checklist

  • [ ] Installs with three go get/go install commands
  • [ ] CLI gleece generate runs without additional config
  • [ ] Generated routes compile cleanly with target framework
  • [ ] OpenAPI spec validates against 3.0 and 3.1 specs
  • [ ] Validation errors surface with clear messages
  • [ ] VSCode extension installs from Marketplace (haim-kastner.gleece-extension)
  • [ ] Works with existing router middlewares (no conflict)

Security Notes

Gleece generates authorization enforcement into route files. For security-sensitive routes, the annotation layer lets you declare permissions declaratively alongside the route — making security audits a code review task rather than a runtime investigation. Report vulnerabilities via SECURITY.md.

FAQ

Q: Does Gleece add runtime overhead? A: No — it is a build-time transpiler. The generated Go files are plain code compiled into your binary. There is no runtime reflection or proxy layer.

Q: Which Go router should I use with Gleece? A: Any of the five supported routers (Gin, Echo, Gorilla Mux, Chi, Fiber) work identically with Gleece’s output. Gin is the most popular in the Go ecosystem; Echo is known for minimal allocation. Pick based on your team’s familiarity.

Q: How does validation work? A: Gleece generates validation logic at the route level from your annotations. Input shapes are validated before your handler function is called, matching the OpenAPI spec.

Q: Is this production-ready? A: The project has 82 stars and an active GitHub Actions build pipeline. As a two-person passion project (per README), evaluate it against your risk tolerance for smaller libraries.

Conclusion

Gleece brings the code-first OpenAPI workflow that TypeScript developers get from TSOA to Go. If you are building APIs in Go and want OpenAPI specs, validation, and auth that stay in sync with your code without manual maintenance, Gleece is worth adding to your build pipeline. The five-router support covers most of the Go web ecosystem, and the build-time-only nature means no runtime surprises.