Skip to content

feat: Add OpenAPI spec validation action and configure Spring profiles #1

feat: Add OpenAPI spec validation action and configure Spring profiles

feat: Add OpenAPI spec validation action and configure Spring profiles #1

name: Validate OpenAPI Spec and Generated Client Code
on:
pull_request:
branches: [main]
types: [opened, reopened, edited, synchronize]
jobs:
validate-openapi:
name: Validate OpenAPI Spec
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- name: Run Gradle to generate OpenAPI docs
working-directory: ./server/application-server
run: ./gradlew generateOpenApiDocs
- name: Check for OpenAPI spec differences
id: check_openapi
run: |
if git diff --exit-code ./server/application-server/openapi.yml; then
echo "OpenAPI spec is up-to-date."
else
echo "OpenAPI specs in openapi.yml differ from the generated version."
exit 1
- name: Post comment about OpenAPI validation failure
if: failure()
uses: marocchino/sticky-pull-request-comment@v2
with:
header: openapi-validation-yml
message: |
🚨 **OpenAPI Validation Failed** 🚨
The OpenAPI specs in `openapi.yml` differ from the generated version.
Please update the OpenAPI specs by running:
```bash
cd ./server/application-server
./gradlew generateOpenApiDocs
```
Commit and push the updated file.
- name: Remove sticky comment on OpenAPI validation success
if: success()
uses: marocchino/sticky-pull-request-comment@v2
with:
header: openapi-validation-yml
delete: true
validate-client-code:
name: Validate Client Code
runs-on: ubuntu-latest
needs: validate-openapi
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install OpenAPI Generator CLI
run: npm install -g @openapitools/openapi-generator-cli
- name: Generate client code
run: |
npx openapi-generator-cli generate \
-i ./server/application-server/openapi.yaml \
-g typescript-angular \
-o ./client/src/app/core/modules/openapi \
--additional-properties fileNaming=kebab-case,withInterfaces=true --generate-alias-as-model
- name: Check for client code differences
id: check_client_code
run: |
if git diff --exit-code ./client/src/app/core/modules/openapi; then
echo "Client code is up-to-date."
else
echo "Client code in /client/src/app/core/modules/openapi is not up-to-date."
exit 1
- name: Post comment about client code validation failure
if: failure()
uses: marocchino/sticky-pull-request-comment@v2
with:
header: client-code-validation
message: |
🚨 **Client Code Validation Failed** 🚨
The client code in `/client/src/app/core/modules/openapi` is not up-to-date.
Please regenerate the client code by running:
```bash
npm install -g @openapitools/openapi-generator-cli
cd ./server/application-server
npx openapi-generator-cli generate -i ./server/application-server/openapi.yaml -g typescript-angular -o ../../client/src/app/core/modules/openapi --additional-properties fileNaming=kebab-case,withInterfaces=true --generate-alias-as-model
```
Commit and push the updated files.
- name: Remove sticky comment on client code validation success
if: success()
uses: marocchino/sticky-pull-request-comment@v2
with:
header: client-code-validation
delete: true