#!/bin/sh # Keep the committed OpenAPI spec in sync with the API router: regenerate it # and abort the push when the regenerated file would change, so the spec can # never go stale. Only runs when API source files changed, to avoid slowing # down pushes that don't touch the API. Compare against both the working tree # and the index so the check passes only after the file is actually committed. # Determine which commits are being pushed: read from stdin (format: ) # For initial push or when remote is behind, check all reachable commits. while read -r local_ref local_sha remote_ref remote_sha; do if [ "$remote_sha" = "0000000000000000000000000000000000000000" ]; then # New branch: check all commits reachable from HEAD RANGE="$(git rev-list --max-parents=0 HEAD)..HEAD" else # Existing branch: check commits between remote and local RANGE="$remote_sha..$local_sha" fi done if git diff --name-only "$RANGE" -- src/server/api/ | grep -q .; then pnpm gen:openapi if [ -n "$(git status --porcelain -- src/server/api/openapi.generated.json)" ]; then echo "✖ src/server/api/openapi.generated.json is out of date." echo " Run: pnpm gen:openapi && git add src/server/api/openapi.generated.json && git commit" exit 1 fi fi