Go source code scanner that parses Go packages and produces Swagger 2.0
(OpenAPI 2.0) specifications. It reads specially formatted comments (annotations) in Go source files
and extracts API metadata — routes, parameters, responses, schemas, and more — to build a complete
spec.Swagger document. Supports Go modules (go1.11+).
Single module: github.com/go-openapi/codescan.
| File | Contents |
|---|---|
application.go |
Options, Run entry point, appScanner orchestration |
parser.go |
sectionedParser — comment block parsing engine |
schema.go |
Go type → Swagger schema conversion |
operations.go |
Operation annotation parsing |
parameters.go |
Parameter annotation parsing |
responses.go |
Response annotation parsing |
routes.go |
Route/path discovery and matching |
meta.go |
Swagger info block parsing |
Run(*Options) (*spec.Swagger, error)— scan Go packages and produce a Swagger specOptions— configuration: packages to scan, build tags, base swagger spec
github.com/go-openapi/loads— loading base Swagger specsgithub.com/go-openapi/spec— Swagger 2.0 spec typesgithub.com/go-openapi/swag— string/JSON utilitiesgolang.org/x/tools— Go package loadinggithub.com/go-openapi/testify/v2— test-only assertions (zero-dep fork ofstretchr/testify)
go test ./...Coding conventions are found beneath .github/copilot
- All
.gofiles must have SPDX license headers (Apache-2.0). - Commits require DCO sign-off (
git commit -s). - Linting:
golangci-lint run— config in.golangci.yml(posture:default: allwith explicit disables). - Every
//nolintdirective must have an inline comment explaining why. - Tests:
go test ./.... CI runs on{ubuntu, macos, windows} x {stable, oldstable}with-race. - Test framework:
github.com/go-openapi/testify/v2(notstretchr/testify;testifylintdoes not work).
See .github/copilot/ (symlinked to .claude/rules/) for detailed rules on Go conventions, linting, testing, and contributions.