Now supporting OpenAPI 3.1

Generate OpenAPI specs
from Go structs & tags.

open-swaggo derives docs from your Go struct values and standard struct tags (json, validate, example) at runtime via reflection — no codegen, no committed spec files, every major framework supported.

main.go
// Document the endpoint alongside the handler
var ListUsersDoc = openswag.Endpoint{
    Method:    "GET",
    Path:      "/users",
    Summary:   "List all users",
    Tags:      []string{"Users"},
    Responses: map[int]openswag.Response{...},
}
4GitHub Stars
·
MITLicense
·
0Forks
Features

Everything you need to ship great API docs

Built for Go developers who value simplicity, performance, and correctness.

LIVE DEMO

From Go structs to OpenAPI in seconds

Declare openswag.Endpoint values with struct tags on the left, get a complete spec on the right.

01
INPUTGo struct values & tags
02
OUTPUTLive OpenAPI 3.x spec
handler.go
// Handler — net/http standard
func CreateUser(w http.ResponseWriter, r *http.Request) {
var req CreateUserRequest
json.NewDecoder(r.Body).Decode(&req)
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(UserResponse{...})
}
// OpenAPI documentation for the handler
var CreateUserDoc = openswag.Endpoint{
Method: "POST",
Path: "/users",
Summary: "Create a new user",
Tags: []string{"Users"},
Responses: map[int]openswag.Response{...},
}
Go · 12 lines · UTF-8main
reflect
API Reference⚡ Live
POST/users
Create a new user
Adds a new user account to the system.
REQUEST BODYapplication/json
email: string · required
name: string · required
RESPONSES
201Created · UserResponse
400Bad Request · Error
openapi.json · live · UTF-8OpenAPI 3.x
HOW IT WORKS

Three steps to production-ready docs

1

Define

Build openswag.Endpoint values from your Go request and response structs — no annotations, no codegen.

2

Mount

Attach the docs handler to your router with one call — Gin, Echo, Fiber, Chi, or net/http.

3

Serve

Start your app — Scalar UI and the live OpenAPI JSON are served straight from /docs.

QUICK INSTALL

Up and running in 30 seconds

Three runtime steps. No CLI to install, no codegen, no generated spec files checked into your repo.

1
Install the libraryopen-swag-go is a library — use go get, not go install.
terminal
# Add open-swag-go to your module
$ go get github.com/gopackx/open-swag-go@latest
2
Define your endpoints in codePlain Go structs and openswag.Endpoint values — no annotations, no codegen.
main.go
package main

import (
    "net/http"

    openswag "github.com/gopackx/open-swag-go"
)

type CreateUserRequest struct {
    Name  string `json:"name"  example:"John Doe"`
    Email string `json:"email" example:"john@example.com"`
}

type UserResponse struct {
    ID    string `json:"id"`
    Name  string `json:"name"`
    Email string `json:"email"`
}

func main() {
    docs := openswag.New(openswag.Config{
        Info: openswag.Info{
            Title:   "My API",
            Version: "1.0.0",
        },
    })

    docs.Add(openswag.Endpoint{
        Method:  "POST",
        Path:    "/users",
        Summary: "Create a user",
        Tags:    []string{"Users"},
        RequestBody: &openswag.RequestBody{
            Required: true,
            Schema:   CreateUserRequest{},
        },
        Responses: map[int]openswag.Response{
            201: {Description: "Created", Schema: UserResponse{}},
        },
    })

    mux := http.NewServeMux()
    docs.Mount(mux, "/docs")

    http.ListenAndServe(":8080", mux)
}
3
Run and view your docsScalar UI is rendered live from the in-memory spec — no files written, no build step.
terminal
$ go run main.go

# Scalar UI, rendered from the live spec
→ http://localhost:8080/docs/
# Raw OpenAPI 3.x JSON
→ http://localhost:8080/docs/openapi.json
SUPPORTED FRAMEWORKS
Gin
Echo
Fiber
Chi
net/http
FAQ

Frequently Asked Questions