Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lx9FNLG2CqeBbVGGd9bFsP
43 lines
1.8 KiB
Bash
Executable File
43 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# OpenAPI compatibility check (M3): fails when the current spec is not backwards
|
|
# compatible with the one at the last m*/v* tag: removed route or method, removed
|
|
# response field, changed field type, new required request param/field, removed
|
|
# enum value. Tags that predate openapi.json pass with a note.
|
|
#
|
|
# scripts/openapi-check.sh spec from `nmon openapi`, else ./openapi.json
|
|
# OPENAPI_NEW=file.json scripts/openapi-check.sh compare this file instead
|
|
# OPENAPI_BASE_TAG=m2 ... compare against this tag instead of the latest
|
|
# Needs: go, git.
|
|
set -uo pipefail
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
cd "$ROOT"
|
|
TMP="$(mktemp -d)"
|
|
trap 'rm -rf "$TMP"' EXIT
|
|
|
|
NEW="${OPENAPI_NEW:-}"
|
|
if [ -z "$NEW" ]; then
|
|
if go run ./cmd/nmon openapi >"$TMP/new.json" 2>"$TMP/gen.err" && [ -s "$TMP/new.json" ]; then
|
|
NEW="$TMP/new.json"
|
|
elif [ -f openapi.json ]; then
|
|
echo "note: 'nmon openapi' unavailable; using openapi.json"
|
|
NEW=openapi.json
|
|
else
|
|
echo "FAIL: no openapi spec (nmon openapi failed and openapi.json is missing)"; cat "$TMP/gen.err"; exit 1
|
|
fi
|
|
fi
|
|
|
|
# Latest m*/v* tag by version order (m2 < m10 < v1.0.0 is not assumed; the newest by tag date wins).
|
|
TAG="${OPENAPI_BASE_TAG:-$(git tag --list 'm*' 'v*' --sort=-creatordate 2>/dev/null | head -n 1)}"
|
|
if [ -z "$TAG" ]; then
|
|
echo "openapi-check: PASS (no m*/v* tag to compare against)"; exit 0
|
|
fi
|
|
if ! git show "$TAG:openapi.json" >"$TMP/old.json" 2>/dev/null; then
|
|
echo "openapi-check: PASS (note: $TAG has no openapi.json yet, nothing to compare against)"; exit 0
|
|
fi
|
|
|
|
if go run ./internal/openapidiff/cmd/openapidiff "$TMP/old.json" "$NEW"; then
|
|
echo "openapi-check: PASS (compatible with $TAG)"
|
|
else
|
|
echo "openapi-check: FAIL (incompatible with $TAG)"; exit 1
|
|
fi
|