Skip to content

validate swagger.json #7

validate swagger.json

validate swagger.json #7

name: Swagger Validation
on:
pull_request:
branches:
- main
jobs:
ensure-up-to-date:
name: Ensure Up-to-date
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Install swag (Swagger generator)
- name: Install Swag
run: |
go install github.com/swaggo/swag/cmd/swag@latest
shell: bash
# Step 3: Verify swag installation
- name: Verify Swag Installation
run: |
if ! command -v swag &> /dev/null; then
echo "Swag is not installed. Please ensure Go is properly configured and Swag is installed."
exit 1
fi
shell: bash
# Step 4: Generate the swagger.json
- name: Generate Swagger file
run: |
make generate-swagger
shell: bash
# Step 5: Compare the newly generated swagger.json with the committed swagger.json
- name: Check for Swagger differences
run: |
git diff --exit-code pkg/swagger/swagger.json
shell: bash
# Step 6: Fail the build if Swagger doesn't match
- name: Fail if Swagger has differences
if: failure()
run: |
echo "Swagger is outdated. Please regenerate it with 'make generate-swagger' and commit the changes."
exit 1