Skip to content

Commit cfd697b

Browse files
shaygunclaude
andcommitted
Generate only the API operations the CLI calls.
The committed client held the whole backend API, including admin, billing and webhook surface and every backend proto comment. Now make generate-api-client keeps only the operations listed in scripts/openapi-allowlist.txt, the schemas they reach, and no free text. scripts/openapi-leak-check.sh runs after generation and in CI. It fails on unlisted or uncalled operations, leftover descriptions, admin and billing names, private IPs, internal hostnames and emails. Extra private patterns can come from OPENAPI_LEAK_EXTRA_PATTERNS_FILE. Regenerated from the backend main Swagger (910ec00c) with oapi-codegen v2.8.0. The generated files drop from 3.35 MB to 215 KB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c5833c8 commit cfd697b

9 files changed

Lines changed: 3666 additions & 85080 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ jobs:
3030
- name: Download modules
3131
run: go mod download
3232

33+
- name: Check generated API client for internal details
34+
run: ./scripts/openapi-leak-check.sh
35+
3336
- name: Vet
3437
run: go vet ./...
3538

‎CONTRIBUTING.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ make vuln
3030

3131
Do not edit generated files under `internal/api/generated/` by hand.
3232

33+
## Generated API client
34+
35+
The client in `internal/api/generated/` contains only the backend operations
36+
the CLI calls. They are listed in `scripts/openapi-allowlist.txt`. To call a
37+
new operation, add its operationId there and regenerate from the backend
38+
Swagger file:
39+
40+
```bash
41+
make generate-api-client SWAGGER_SPEC=/path/to/proto.swagger.json
42+
```
43+
44+
`scripts/openapi-allowlist.py` drops every other operation, the schemas only
45+
they use, and all descriptions. `make leak-check` (also run in CI) fails if the
46+
client contains an operation that is not on the allow-list or not called by
47+
the CLI, or admin, billing, or internal infrastructure details. Maintainers can
48+
add private patterns with `OPENAPI_LEAK_EXTRA_PATTERNS_FILE=/path/to/file`.
49+
3350
## Code style
3451

3552
- Go, with packages under `internal/`

‎Makefile‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build install test clean fmt vet lint vuln help
1+
.PHONY: build install test clean fmt vet lint vuln help generate-api-client leak-check
22

33
# Build variables
44
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
@@ -78,6 +78,9 @@ lint: ## Run golangci-lint
7878
@which golangci-lint > /dev/null || (echo "golangci-lint not installed. Install: https://golangci-lint.run/welcome/install/" && exit 1)
7979
golangci-lint run --timeout=5m
8080

81+
leak-check: ## Check the generated API client for internal details and unlisted operations
82+
./scripts/openapi-leak-check.sh
83+
8184
vuln: ## Run govulncheck
8285
@which govulncheck > /dev/null || go install golang.org/x/vuln/cmd/govulncheck@latest
8386
govulncheck ./...
@@ -99,6 +102,8 @@ tidy: ## Tidy go.mod
99102
# oapi-codegen variables (maintainers: set SWAGGER_SPEC to a Swagger 2.0 JSON file)
100103
SWAGGER_SPEC ?= proto.swagger.json
101104
OPENAPI3_SPEC = internal/api/generated/openapi3.yaml
105+
OPENAPI3_FULL = $(BUILD_DIR)/openapi3.full.yaml
106+
OPENAPI_ALLOWLIST = scripts/openapi-allowlist.txt
102107
GENERATED_DIR = internal/api/generated
103108
OAPI_CODEGEN = oapi-codegen
104109

@@ -109,9 +114,12 @@ generate-api-client: ## Generate API client from OpenAPI spec using oapi-codegen
109114
exit 1; \
110115
fi
111116
@which $(OAPI_CODEGEN) > /dev/null || (echo "oapi-codegen not installed. Install via: go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest" && exit 1)
112-
@mkdir -p $(GENERATED_DIR)
117+
@mkdir -p $(GENERATED_DIR) $(BUILD_DIR)
113118
@echo "Converting Swagger 2.0 to OpenAPI 3.0..."
114-
@npx -y swagger2openapi $(SWAGGER_SPEC) -o $(OPENAPI3_SPEC) || (echo "Error converting Swagger 2.0 to OpenAPI 3.0. Install swagger2openapi: npm install -g swagger2openapi" && exit 1)
119+
@npx -y swagger2openapi $(SWAGGER_SPEC) -o $(OPENAPI3_FULL) || (echo "Error converting Swagger 2.0 to OpenAPI 3.0. Install swagger2openapi: npm install -g swagger2openapi" && exit 1)
120+
@echo "Keeping only the operations in $(OPENAPI_ALLOWLIST)..."
121+
@python3 scripts/openapi-allowlist.py $(OPENAPI_ALLOWLIST) $(OPENAPI3_FULL) $(OPENAPI3_SPEC)
122+
@rm -f $(OPENAPI3_FULL)
115123
@echo "Generating types..."
116124
@$(OAPI_CODEGEN) \
117125
-generate types \
@@ -124,6 +132,7 @@ generate-api-client: ## Generate API client from OpenAPI spec using oapi-codegen
124132
-package api \
125133
-o $(GENERATED_DIR)/client.gen.go \
126134
$(OPENAPI3_SPEC)
135+
@./scripts/openapi-leak-check.sh
127136
@echo "✓ API client generated successfully in $(GENERATED_DIR)"
128137
@echo "Run 'make tidy' to update go.mod with new dependencies"
129138

‎internal/api/generated/client.gen.go‎

Lines changed: 2392 additions & 57723 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)