-
Notifications
You must be signed in to change notification settings - Fork 0
62 lines (50 loc) · 1.72 KB
/
ci.yml
File metadata and controls
62 lines (50 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
validate-specs:
name: Validate Specs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate all specs against Swagger Validator
run: |
set -e
FAILED=0
PASSED=0
VALIDATOR_URL="https://validator.swagger.io/validator/debug"
SPECS=$(find specs -name "*.json" | sort)
if [ -z "$SPECS" ]; then
echo "Error: no spec files found under specs/"
exit 1
fi
while IFS= read -r spec_file; do
echo "Validating: $spec_file"
response=$(curl -s --fail-with-body --max-time 30 -X POST \
-H "Content-Type: application/json" \
--data @"$spec_file" \
"$VALIDATOR_URL") || {
echo " FAILED (HTTP/network error)"
FAILED=$((FAILED + 1))
continue
}
errors=$(echo "$response" | jq '[.schemaValidationMessages[] | select(.level == "error")] | length' 2>/dev/null || echo "0")
if [ "$errors" -gt "0" ]; then
echo " FAILED ($errors error(s)):"
echo "$response" | jq -r '.schemaValidationMessages[] | select(.level == "error") | " - \(.message)"'
FAILED=$((FAILED + 1))
else
echo " PASSED"
PASSED=$((PASSED + 1))
fi
done <<< "$SPECS"
echo ""
echo "Results: $PASSED passed, $FAILED failed"
if [ "$FAILED" -ne "0" ]; then
echo "One or more specs failed validation."
exit 1
fi
echo "All specs passed validation."