-
Notifications
You must be signed in to change notification settings - Fork 1
169 lines (139 loc) · 5.19 KB
/
validate-openapi.yml
File metadata and controls
169 lines (139 loc) · 5.19 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: 🔍 Validate OpenAPI Specification
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
paths:
- 'leadmagic-openapi-3.1.yaml'
- 'leadmagic-openapi-3.1.json'
- 'test-api.js'
jobs:
validate-spec:
name: Validate OpenAPI Specification
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
- name: 🔧 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: 📦 Install Swagger CLI
run: npm install -g @apidevtools/swagger-cli
- name: ✅ Validate YAML specification
run: swagger-cli validate leadmagic-openapi-3.1.yaml
- name: ✅ Validate JSON specification
run: swagger-cli validate leadmagic-openapi-3.1.json
- name: 🔄 Check YAML/JSON sync
run: |
# Simple validation that both files are valid and roughly the same size
yaml_size=$(wc -c < leadmagic-openapi-3.1.yaml)
json_size=$(wc -c < leadmagic-openapi-3.1.json)
echo "📊 YAML size: $yaml_size bytes"
echo "📊 JSON size: $json_size bytes"
# JSON should be larger than YAML (more verbose format)
if [ "$json_size" -gt "$yaml_size" ]; then
echo "✅ File sizes are reasonable - JSON larger than YAML as expected"
else
echo "⚠️ Unexpected file size ratio - manual sync check recommended"
fi
- name: 📋 Validate test script syntax
run: node -c test-api.js
- name: 🧪 Run dry test (without API key)
run: |
# Test that the script properly handles missing API key
output=$(node test-api.js 2>&1 || true)
if echo "$output" | grep -q "LEADMAGIC_API_KEY environment variable is required"; then
echo "✅ Test script properly requires API key"
else
echo "❌ Test script should require API key"
exit 1
fi
lint-spec:
name: Lint OpenAPI with Spectral
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
- name: 🔧 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: 📦 Install Spectral
run: npm install -g @stoplight/spectral-cli
- name: 🔍 Lint OpenAPI specification
run: spectral lint leadmagic-openapi-3.1.yaml
check-examples:
name: Validate Examples Format
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
- name: 🔧 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: ✅ Check for OpenAPI 3.1 examples format
run: |
# Check that we're using 'examples' (OpenAPI 3.1) not 'example' (OpenAPI 3.0)
if grep -r '"example":\|example:' leadmagic-openapi-3.1.yaml leadmagic-openapi-3.1.json; then
echo "❌ Found deprecated 'example' fields. Use 'examples' for OpenAPI 3.1"
exit 1
else
echo "✅ All examples use OpenAPI 3.1 format"
fi
- name: 📊 Count examples
run: |
yaml_examples=$(grep -c "examples:" leadmagic-openapi-3.1.yaml || echo "0")
json_examples=$(grep -c '"examples":' leadmagic-openapi-3.1.json || echo "0")
echo "📊 YAML examples: $yaml_examples"
echo "📊 JSON examples: $json_examples"
echo "✅ Example count validation complete"
documentation-check:
name: Documentation Quality Check
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
- name: 📚 Check README completeness
run: |
required_sections=(
"Authentication"
"Base URL"
"Credit Consumption"
"Testing & Validation"
"Use Case Examples"
)
for section in "${required_sections[@]}"; do
if grep -q "$section" README.md; then
echo "✅ Found section: $section"
else
echo "❌ Missing section: $section"
exit 1
fi
done
- name: 🔗 Check for hardcoded credentials
run: |
# Check for common API key patterns in critical files
if grep -r "sk-[a-zA-Z0-9]\{48\}\|api_key.*=.*[a-zA-Z0-9]\{10,\}" test-api.js leadmagic-openapi-3.1.yaml leadmagic-openapi-3.1.json; then
echo "❌ Found potential hardcoded credentials in specification or test files"
exit 1
else
echo "✅ No hardcoded credentials found in critical files"
fi
- name: 📏 Check file sizes
run: |
yaml_size=$(stat -c%s leadmagic-openapi-3.1.yaml)
json_size=$(stat -c%s leadmagic-openapi-3.1.json)
readme_size=$(stat -c%s README.md)
echo "📊 File sizes:"
echo " YAML: $yaml_size bytes"
echo " JSON: $json_size bytes"
echo " README: $readme_size bytes"
# Ensure files aren't empty
if [ "$yaml_size" -lt 1000 ] || [ "$json_size" -lt 1000 ] || [ "$readme_size" -lt 1000 ]; then
echo "❌ One or more files appear to be too small"
exit 1
fi
echo "✅ All files have reasonable sizes"