You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+
## Overview
6
+
7
+
`openapi-client-generator` is a Go code generator that turns an OpenAPI 3.1 (or 3.0) spec into a complete, idiomatic Go HTTP client package with zero external runtime dependencies.
8
+
9
+
The main branch is `canary`. Releases are managed by release-please (conventional-commit driven).
10
+
11
+
## Pipeline
12
+
13
+
A spec flows through three stages, one per `internal/` package:
14
+
15
+
1.**parse** (`internal/parser`) — load and validate the spec with libopenapi, resolve `$ref`s.
16
+
2.**analyze** (`internal/analyzer`) — lower the spec into the intermediate representation (`internal/ir`): operations, params, types, pagination. This is where naming, disambiguation, and pagination detection happen.
17
+
3.**generate** (`internal/generator`) — render the IR through `text/template` files (`internal/templates/*.tmpl`, embedded via `embed.go`) and post-process each file with `goimports` (`WriteFiles`).
18
+
19
+
Supporting packages: `internal/naming` (OpenAPI identifier → Go identifier), `cmd/` (the Cobra CLI).
20
+
21
+
The generated code is the product. It must always compile — the e2e tests in `internal/generator` generate clients from specs and run `go build`/`go test` on the output.
22
+
23
+
## Commands
24
+
25
+
```bash
26
+
go build ./... # build
27
+
go test ./... # run all tests (incl. generate-and-compile e2e tests)
28
+
go test ./internal/generator/ # one package
29
+
gofmt -l .# list unformatted files
30
+
go vet ./...
31
+
32
+
# Run the generator
33
+
go run . generate --spec testdata/petstore.yaml --out ./gen/petstore
34
+
```
35
+
36
+
Template changes don't need a build step — templates are `go:embed`ed and read at generate time.
37
+
38
+
## Code Standards
39
+
40
+
### Commits
41
+
Conventional commits; PR titles become changelog entries.
-`!` for breaking changes (`feat!:`); scope for context (`fix(generator):`).
44
+
- For `fix` titles, describe the **broken behavior** the user saw, not the code action. For `feat`, don't start with "add" — the title is the new capability.
45
+
46
+
### Comments
47
+
Default to writing no comments. Only add one when the WHY is non-obvious: a hidden constraint, a subtle invariant, a workaround for a specific bug, behavior that would surprise a reader. If removing the comment wouldn't confuse a future reader, don't write it. Specifically avoid:
48
+
- WHAT comments. Names and code already say what — `// hasRequiredQueryParams returns whether there are required query params` above a function of that name is noise.
49
+
- Conventions that hold across the package (e.g. "wire names use OrigName" is true everywhere, so don't repeat it on each helper).
50
+
- References to current task / fix / callers (`// so foo_test.go can exercise this`, `// matching how auth cookies are built`, `// added for the X flow`) — they rot. Such context belongs in the PR description.
51
+
- Multi-paragraph docstrings. One short line max — if you need more, the function is doing too much.
52
+
- Decorative section headers (`// ===== Helpers =====`). Use blank lines or split files.
53
+
54
+
Note: a generated client's exported types/methods are SDK documentation for its consumers, so a concise doc comment there is appropriate. Unexported template helpers (`addQueryParam`, etc.) are internal — apply the rules above.
55
+
56
+
### DRY
57
+
When the same logic appears in multiple places, extract a shared helper. Before writing new code, check whether an existing helper already does it. When adding encoding/naming/forwarding that mirrors existing code, reuse it rather than duplicating.
58
+
59
+
### Go
60
+
- Don't `panic`; return errors.
61
+
- Use `errors.Is`/`errors.As` for error checks, not equality, so wrapped errors match.
62
+
- Use `time.Time` for timestamps; let the JSON marshaler format them.
63
+
- File names: lowercase, no separators (`funcmap.go`) or underscores (`api_key.go`) — no camelCase or hyphens. Test files end `_test.go`.
64
+
- Package directories under `internal/`: lowercase, no separators.
65
+
- All code must pass `gofmt` and `go vet`.
66
+
67
+
### Testing
68
+
-**Test real code.** Tests import and call the actual functions under test — never reimplement the logic being tested. For the generator, the strongest tests generate a client from a spec and then compile/run it (`internal/generator/e2e_test.go`), so a broken template fails the test rather than a restated assertion.
69
+
- Prefer `t.Context()` over `context.Background()` in tests.
70
+
- When changing a template, add or extend an e2e test that compiles the affected operation shape.
0 commit comments