Skip to content

Commit 3eb26f6

Browse files
authored
feat: Update generated client (#133)
* feat: Update generated client * chore: Crete ai instructions * chore: Update go to 1.25
1 parent 7a87045 commit 3eb26f6

7 files changed

Lines changed: 111 additions & 6 deletions

File tree

.github/copilot-instructions.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Strava API Client - AI Coding Agent Instructions
2+
3+
This is a **generated Go client wrapper** around the Strava API v3, built using code generation from OpenAPI specs and containerized tooling.
4+
5+
## Architecture Overview
6+
7+
### Generated Client + Wrapper Pattern
8+
- **Generated code**: `internal/gen/strava-api-go/` contains swagger-generated client (DO NOT EDIT)
9+
- **Wrapper layer**: `client/*.go` provides user-friendly interfaces over generated code
10+
- **Pattern**: Each API group (Activities, Athletes, Clubs, etc.) has:
11+
- Interface in wrapper (e.g., `ActivitiesAPI`)
12+
- Implementation struct (e.g., `activitiesService`)
13+
- Constructor function (e.g., `newActivitiesApiService()`)
14+
15+
### Code Generation Workflow
16+
```bash
17+
# Update API spec
18+
make update-swagger-spec # Downloads latest from Strava
19+
20+
# Regenerate client
21+
make codegen # Runs: gen → sync-vendor → format-code → vet
22+
```
23+
24+
Key files:
25+
- `internal/generate.go` - Contains `//go:generate` directive for swagger codegen
26+
- `docs/swagger.json` - Strava API specification (source of truth)
27+
- Generated client uses go-openapi runtime with Bearer token auth
28+
29+
## Development Workflow
30+
31+
### Docker-Based Tooling
32+
All linting/formatting/testing uses containerized tools via `ghcr.io/obalunenko/go-tools`:
33+
```bash
34+
# Primary commands (use these, not direct go commands)
35+
make lint-full # Full linting suite
36+
make fmt # Format code
37+
make imports # Fix import sorting
38+
make vet # Static analysis
39+
40+
# Docker compose wraps all tools
41+
docker compose -f deployments/docker-compose/go-tools-docker-compose.yml up --exit-code-from lint-full lint-full
42+
```
43+
44+
### Testing Pattern
45+
- Tests in `examples/client_example_test.go` serve as integration tests and usage documentation
46+
- Tests require `STRAVA_ACCESS_TOKEN` environment variable
47+
- Helper functions: `getToken(t)` for auth, `printJSON(t, v)` for debug output
48+
- Uses `github.com/obalunenko/getenv` for environment variable handling
49+
50+
## Code Patterns & Conventions
51+
52+
### Wrapper Interface Design
53+
```go
54+
// Each API group follows this pattern:
55+
type ActivitiesAPI interface {
56+
// Method with context first, required params, then options
57+
GetActivityById(ctx context.Context, id int64, opts ...GetActivityByIdOpts) (models.DetailedActivity, error)
58+
}
59+
60+
// Options structs for optional parameters
61+
type GetActivityByIdOpts struct {
62+
IncludeAllEfforts *bool `json:"include_all_efforts,omitempty"`
63+
}
64+
```
65+
66+
### Error Handling
67+
- Custom errors in `client/errors.go` (e.g., `ErrTooManyOptions`)
68+
- Generated client errors passed through from go-openapi
69+
- No error wrapping - direct return of underlying errors
70+
71+
### Dependencies & Integration
72+
- **Auth**: Bearer token via `httptransport.BearerToken(token)`
73+
- **Generated models**: Use `internal/gen/strava-api-go/models.*` types directly
74+
- **Time handling**: `strfmt.DateTime` for API compatibility
75+
- **Testing**: `github.com/stretchr/testify` with `require.*` assertions
76+
77+
## File Organization
78+
79+
```
80+
client/ # User-facing wrapper interfaces
81+
├── client.go # Main APIClient struct and constructor
82+
├── activities.go # Activities API wrapper
83+
├── athletes.go # Athletes API wrapper
84+
└── errors.go # Custom error types
85+
86+
internal/gen/ # Generated code (DO NOT EDIT)
87+
examples/ # Integration tests & usage documentation
88+
scripts/ # Build and development scripts
89+
deployments/ # Docker compose configurations
90+
```
91+
92+
## Key Constraints
93+
94+
1. **Never edit generated code** in `internal/gen/` - regenerate via `make codegen`
95+
2. **Use containerized tools** - don't run go tools directly, use Make targets
96+
3. **Follow wrapper pattern** - new APIs need interface + implementation + constructor
97+
4. **Context-first parameters** in all API methods
98+
5. **Options structs** for optional parameters instead of many function parameters
99+
100+
## Common Tasks
101+
102+
- **Add new API method**: Implement in relevant `client/*.go` file following existing patterns
103+
- **Update API spec**: Run `make update-swagger-spec` then `make codegen`
104+
- **Debug API calls**: Add test in `examples/` with `printJSON()` helper
105+
- **Fix formatting**: Run `make format-code` (includes fmt + imports)

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
matrix:
3535
language: [ 'go' ]
3636
os: [ 'ubuntu-24.04' ]
37-
go-version: [1.24.x]
37+
go-version: [1.25.x]
3838
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
3939
# Learn more about CodeQL language support at https://git.io/codeql-language-support
4040

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
max-parallel: 3
4343
matrix:
4444
os: [ 'ubuntu-24.04' ]
45-
go-version: [1.24.x]
45+
go-version: [1.25.x]
4646
runs-on: ${{ matrix.os }}
4747
name: Build
4848
steps:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ COMPOSE_TOOLS_CMD_BASE=docker compose -f $(COMPOSE_TOOLS_FILE)
1313
COMPOSE_TOOLS_CMD_UP=$(COMPOSE_TOOLS_CMD_BASE) up --exit-code-from
1414
COMPOSE_TOOLS_CMD_PULL=$(COMPOSE_TOOLS_CMD_BASE) build
1515

16-
GOVERSION:=1.24
16+
GOVERSION:=1.25
1717

1818
TARGET_MAX_CHAR_NUM=20
1919

docs/swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@
15281528
},
15291529
"/clubs/{id}": {
15301530
"get": {
1531-
"description": "Returns a given club using its identifier.",
1531+
"description": "Returns a given a club using its identifier.",
15321532
"tags": [
15331533
"Clubs"
15341534
],

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/obalunenko/strava-api
22

3-
go 1.24.0
3+
go 1.25
44

55
require (
66
github.com/go-openapi/errors v0.22.2

internal/gen/strava-api-go/client/clubs/clubs_client.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)