|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Go source code scanner that parses Go packages and produces [Swagger 2.0](https://swagger.io/specification/v2/) |
| 8 | +(OpenAPI 2.0) specifications. It reads specially formatted comments (annotations) in Go source files |
| 9 | +and extracts API metadata — routes, parameters, responses, schemas, and more — to build a complete |
| 10 | +`spec.Swagger` document. Supports Go modules (go1.11+). |
| 11 | + |
| 12 | +See [docs/MAINTAINERS.md](../docs/MAINTAINERS.md) for CI/CD, release process, and repo structure details. |
| 13 | + |
| 14 | +### Package layout (single package) |
| 15 | + |
| 16 | +| File | Contents | |
| 17 | +|------|----------| |
| 18 | +| `application.go` | `Options`, `Run` entry point, `appScanner` orchestration | |
| 19 | +| `parser.go` | `sectionedParser` — comment block parsing engine (title, description, annotations) | |
| 20 | +| `parser_helpers.go` | Helpers for tag/package filtering, value extraction | |
| 21 | +| `meta.go` | Swagger info block parsing (title, version, license, contact, etc.) | |
| 22 | +| `operations.go` | Operation (route handler) annotation parsing | |
| 23 | +| `parameters.go` | Parameter annotation parsing | |
| 24 | +| `responses.go` | Response annotation parsing | |
| 25 | +| `routes.go` | Route/path discovery and matching | |
| 26 | +| `route_params.go` | Route parameter extraction | |
| 27 | +| `schema.go` | Go type → Swagger schema conversion | |
| 28 | +| `enum.go` | Enum value extraction from Go constants | |
| 29 | +| `spec.go` | Spec-level helpers | |
| 30 | +| `regexprs.go` | Shared regular expressions for annotation parsing | |
| 31 | +| `assertions.go` | Test assertion helpers | |
| 32 | + |
| 33 | +### Key API |
| 34 | + |
| 35 | +- `Run(*Options) (*spec.Swagger, error)` — the main entry point: scan Go packages and produce a Swagger spec |
| 36 | +- `Options` — configuration: packages to scan, build tags, base swagger spec to overlay |
| 37 | + |
| 38 | +### Dependencies |
| 39 | + |
| 40 | +- `github.com/go-openapi/loads` — loading base Swagger specs |
| 41 | +- `github.com/go-openapi/spec` — Swagger 2.0 spec types |
| 42 | +- `github.com/go-openapi/swag` — string/JSON utilities |
| 43 | +- `golang.org/x/tools` — Go package loading (`packages.Load`) |
| 44 | +- `github.com/go-openapi/testify/v2` — test-only assertions |
| 45 | + |
| 46 | +### Notable design decisions |
| 47 | + |
| 48 | +- Uses `golang.org/x/tools/go/packages` for module-aware package loading. |
| 49 | +- Comment annotations follow the go-swagger convention (`swagger:route`, `swagger:operation`, |
| 50 | + `swagger:parameters`, `swagger:response`, `swagger:model`, etc.). |
| 51 | +- The scanner works on the AST level — it does not execute or compile the scanned code. |
0 commit comments