Skip to content

feat: [UPBE-590] swagger creation - report generation #664

feat: [UPBE-590] swagger creation - report generation

feat: [UPBE-590] swagger creation - report generation #664

name: Validate modified OpenAPI YAML/TPL files
on:
pull_request:
paths:
- 'src/idpay/apim/api/**'
permissions:
contents: read
jobs:
validate-openapi:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: '20'
- name: Install Spectral CLI and rulesets
run: |
npm install -g @stoplight/spectral-cli
npm install @stoplight/spectral-owasp-ruleset
- name: Get list of modified OpenAPI files
id: get_modified_files
run: |
echo "πŸ“‚ Fetching modified OpenAPI files in this PR..."
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"${{ github.api_url }}/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" \
| jq -r '.[].filename' \
| grep -E '^src/idpay/apim/api/.*openapi.*\.(yml|yaml|yml.tpl|yaml.tpl)$' || true
- name: Validate OpenAPI files with Spectral
run: |
files=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"${{ github.api_url }}/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" \
| jq -r '.[].filename' \
| grep -E '^src/idpay/apim/api/.*openapi.*\.(yml|yaml|yml.tpl|yaml.tpl)$' || true)
if [ -z "$files" ]; then
echo "βœ… No OpenAPI files were modified in this PR."
exit 0
fi
echo "πŸ” OpenAPI files to validate:"
echo "$files"
failed=0
for file in $files; do
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "πŸ”Ž Validating $file"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
spectral lint -r .spectral.yaml --verbose "$file" || {
echo "❌ Spectral validation failed for $file"
failed=1
}
done
if [ $failed -eq 1 ]; then
echo ""
echo "❌ Validation failed for one or more OpenAPI files."
exit 1
else
echo ""
echo "βœ… All modified OpenAPI files passed validation."
fi