Arsfy's Blog

Semantic-Driven OpenAPI Generator for Go

Recently, I built a semantic-aware OpenAPI generator that extracts API definitions directly from Go code using the AST and type system.

Repository: https://github.com/arsfy/gswr

Background

Honestly, I’ve always felt that the Go ecosystem has been missing a tool in this space. In most cases, developers are forced to choose between:

Both approaches introduce friction:

Even in the post-AI era—where AI can help automate documentation—this mainly reduces the time cost, rather than solving the underlying workflow problem.


Why I Built This Tool

This project was designed to handle complex real-world scenarios automatically, including:

1. Route Discovery

Supports nested Group(...) recursion and cross-file router chaining:

v1 := e.Group("v1")
UserRoute(v1.Group("user"))

func UserRoute(e *echo.Group) {
    e.GET("/list")
}

2. Complex Data Structures

Correctly analyzes constants, nested types, channels, external aliases, and more:

c := "ok"
v := <-ch

return c.JSON(200, types.Response{
    Code: c,
    Data: gin.H{
        "number": utils.GetRandomNumber(),
        "v": v,
    }
})

3. Input / Output Type Inference

Infers request and response types—even when wrapped or abstracted:

name := c.FormValue("name")
age := resp.GetInt(c, "age", 0)

return resp.Success("ok")

Current Status

More capabilities are described in the README. However:

#Golang #Tools