Skip to content

Commit 5e8423b

Browse files
committed
feat: add list hero api endpoints and auto generate openapi spec
1 parent 3d086e6 commit 5e8423b

7 files changed

Lines changed: 1990 additions & 109 deletions

File tree

.githooks/pre-commit

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,16 @@ cargo clippy --all-targets --all-features -- -D warnings
2929
echo "pre-commit: running unit tests..."
3030
cargo test --lib --bins --quiet
3131

32+
echo "pre-commit: checking openapi.json freshness..."
33+
tmp_spec=$(mktemp)
34+
trap 'rm -f "$tmp_spec"' EXIT
35+
cargo run --quiet --bin export_openapi -- "$tmp_spec"
36+
if ! diff -q openapi.json "$tmp_spec" >/dev/null 2>&1; then
37+
echo "pre-commit: openapi.json is stale relative to the API code." >&2
38+
echo " regenerate with: cargo run --bin export_openapi openapi.json" >&2
39+
echo " then stage the result and re-commit." >&2
40+
diff -u openapi.json "$tmp_spec" | head -40 >&2 || true
41+
exit 1
42+
fi
43+
3244
echo "pre-commit: ok"

.github/workflows/rust.yml

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,49 @@ name: Rust
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches: ["main"]
66
pull_request:
7-
branches: [ "main" ]
7+
branches: ["main"]
88

99
env:
1010
CARGO_TERM_COLOR: always
11+
RUSTFLAGS: -D warnings
1112

1213
jobs:
13-
build:
14-
14+
check:
1515
runs-on: ubuntu-latest
16-
1716
steps:
18-
- uses: actions/checkout@v4
19-
- name: Build
20-
run: cargo build --verbose
21-
- name: Run tests
22-
run: cargo test --verbose
17+
- uses: actions/checkout@v4
18+
19+
- name: Restore cargo cache
20+
uses: actions/cache@v4
21+
with:
22+
path: |
23+
~/.cargo/registry
24+
~/.cargo/git
25+
target
26+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
27+
28+
- name: Format
29+
run: cargo fmt --all -- --check
30+
31+
- name: Clippy
32+
run: cargo clippy --all-targets --all-features -- -D warnings
33+
34+
- name: Build
35+
run: cargo build --verbose
36+
37+
- name: Unit tests
38+
run: cargo test --lib --bins --verbose
39+
40+
- name: OpenAPI spec is up to date
41+
# The committed openapi.json must match what the code generates.
42+
# If this fails, run `cargo run --bin export_openapi openapi.json`
43+
# locally, commit the result, and push.
44+
run: |
45+
cargo run --quiet --bin export_openapi -- /tmp/generated-openapi.json
46+
if ! diff -q openapi.json /tmp/generated-openapi.json >/dev/null; then
47+
echo "openapi.json is stale relative to the API code." >&2
48+
diff -u openapi.json /tmp/generated-openapi.json >&2 || true
49+
exit 1
50+
fi

CLAUDE.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Read these for their respective domains:
4646

4747
Two hooks live in `.githooks/`, wired up by one `git config core.hooksPath .githooks` per clone:
4848

49-
- **`pre-commit`** — scans staged changes for secrets via `gitleaks`, then runs `cargo fmt --check`, `cargo clippy -- -D warnings`, and `cargo test --lib --bins`. Integration tests in `tests/` are deliberately excluded — they need Postgres and run in CI.
49+
- **`pre-commit`** — scans staged changes for secrets via `gitleaks`, then runs `cargo fmt --check`, `cargo clippy -- -D warnings`, `cargo test --lib --bins`, and an OpenAPI drift check (regenerates `openapi.json` to a tempfile and diffs against the committed copy). Integration tests in `tests/` are deliberately excluded — they need Postgres and run in CI.
5050
- **`commit-msg`** — validates the commit subject line against `.claude/rules/commits.md` (Conventional Commits 1.0). Pure bash, no commitlint dependency.
5151

5252
One-time setup per clone:
@@ -76,8 +76,11 @@ sqlx migrate run
7676
# Audit dependencies
7777
cargo audit
7878

79-
# Generate OpenAPI spec to stdout
80-
cargo run --bin export_openapi > openapi.json
79+
# Regenerate the committed OpenAPI spec (deterministic LF, no BOM,
80+
# regardless of shell). Run this after any API change; the pre-commit
81+
# hook and CI both fail if openapi.json drifts from what the code
82+
# generates.
83+
cargo run --bin export_openapi openapi.json
8184
```
8285

8386
## Definition of done
@@ -86,7 +89,7 @@ A change is done when:
8689

8790
- Code compiles without warnings (treat warnings as errors locally and in CI)
8891
- Tests pass, including negative and variant cases for the changed code
89-
- New endpoints have utoipa annotations and appear in `openapi.json`
92+
- New endpoints have utoipa annotations, `openapi.json` is regenerated, and the regenerated file is staged in the same commit as the code change
9093
- New SQL queries are compile-time checked by sqlx and the `.sqlx` cache is committed
9194
- Migration files are append-only if in `production` phase, freely editable in `pre-launch`
9295
- cargo-audit reports no new advisories

0 commit comments

Comments
 (0)