apitester-generator
Generate a Postman-compatible API collection JSON from Gin controller source code via AST parsing.
Note: This is an early MVP built for a specific project structure. To properly use this generator, your repo should follow the base project layout described in base-be-golang. The tool currently expects controllers under internal/adapter/controller/ or internal/controller/ and DTOs under internal/dto/, internal/core/usecase/, or shared/payload/.
Installation
go install github.com/rdhmuhammad/apitester-generator/cmd/apigen@latest
Usage
Add the go:generate directive at the top of your Gin controller file:
//go:generate apigen
Run go generate from the controller's directory:
go generate ./...
The tool reads GOFILE to identify which file to parse and walks up the directory tree to find go.mod as the project root.
Optional: env.apitest
Create an env.apitest file at your project root to customize the collection:
name=My API
base_url=http://localhost:8080/api/v1
Defaults: name = Phisiobook API, base_url = http://localhost:8999/api/v1
Output
The generated collection is written to:
{project_root}/resource/apidocs/collection.json
Features
- Auto-detects route groups, HTTP methods, paths, and handler names
- Extracts request body examples from DTO structs (
internal/dto, internal/core/usecase, shared/payload)
- Supports
example struct tags for custom sample values
- Supports
query params on GET requests
- Preserves existing collection items between runs (merge-friendly)
Consume the Collection
The generated collection.json can be imported into any Postman-compatible client.
For a GUI API tester that reads this format directly, see: apitester