Skip to content

Commit

Permalink
Generate Java API Client for Intelligence Service's OpenAPI Specifica…
Browse files Browse the repository at this point in the history
…tions (#106)

Co-authored-by: Felix T.J. Dietrich <[email protected]>
Co-authored-by: Felix T.J. Dietrich <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Nov 4, 2024
1 parent 8206fa9 commit 32dfb6d
Show file tree
Hide file tree
Showing 30 changed files with 2,484 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
types: [opened, synchronize, labeled, reopened]
paths:
- 'server/application-server/**'
- '.github/workflows/generate-api-client.yml'
- '.github/workflows/generate-application-server-client.yml'
push:
paths:
- 'server/application-server/openapi.yaml'
Expand All @@ -15,7 +15,7 @@ on:

jobs:
generate-api-client:
name: Verify API Specs and Client (add autocommit-openapi label to PR to auto-commit changes)
name: Verify API Specs and Client of the Application Server (add autocommit-openapi label to PR to auto-commit changes)
runs-on: ubuntu-latest

steps:
Expand All @@ -40,8 +40,8 @@ jobs:
- name: Install dependencies
run: npm install

- name: Generate API client
run: npm run generate:api
- name: Generate API client for the application server
run: npm run generate:api:application-server

- name: Check for changes in the API
id: check_changes
Expand Down
100 changes: 100 additions & 0 deletions .github/workflows/generate-intelligence-service-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: OpenAPI

on:
pull_request:
types: [opened, synchronize, labeled, reopened]
paths:
- 'server/application-server/**'
- '.github/workflows/generate-intelligence-service-client.yml'
push:
paths:
- 'server/intelligence-service/openapi.yaml'
- 'server/application-server/src/main/java/de/tum/in/www1/hephaestus/intelligenceservice/**'
branches: [develop]
workflow_dispatch:

jobs:
generate-api-client:
name: Verify API Specs and Client of the Intelligence Service (add autocommit-openapi label to PR to auto-commit changes)
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
persist-credentials: false
fetch-depth: 0

- name: Set up Python 3.12
uses: actions/setup-python@v2
with:
python-version: 3.12

- name: Install dependencies
run: npm install

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
virtualenvs-path: .venv
installer-parallel: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install Python dependencies
working-directory: server/intelligence-service
run: poetry install --no-interaction --no-root

- name: Generate API client for the application server
working-directory: server/intelligence-service
run: poetry run npm run generate:api:intelligence-service

- name: Check for changes in the API
id: check_changes
run: |
echo "Checking for changes in the API client directory..."
git add .
if git diff --cached --quiet; then
echo "No changes detected in the API client directory."
echo "NO_CHANGES_DETECTED=true" >> $GITHUB_ENV
else
echo "Changes detected in the API client directory."
echo "NO_CHANGES_DETECTED=false" >> $GITHUB_ENV
exit 1
fi
- name: Commit files
if: ${{ always() && contains(github.event.pull_request.labels.*.name, 'autocommit-openapi') }}
run: |
echo "Committing and pushing changes..."
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git commit -a -m "chore: update API specs and client"
- name: Push changes
if: ${{ always() && contains(github.event.pull_request.labels.*.name, 'autocommit-openapi') }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GH_PAT }}
branch: ${{ github.event.pull_request.head.ref }}

- name: Remove autocommit-openapi label
if: ${{ always() && contains(github.event.pull_request.labels.*.name, 'autocommit-openapi') }}
run: |
echo "Removing the autocommit-openapi label..."
curl --silent --fail-with-body -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/autocommit-openapi
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,7 @@ node_modules/

application-local.yml

server/application-server/postgres-data/
server/application-server/postgres-data/

# Java-Client creation temporary
tmp
153 changes: 149 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@
"webapp/*"
],
"scripts": {
"generate:api:clean": "rimraf webapp/src/app/core/modules/openapi",
"generate:api:application-server:clean": "rimraf webapp/src/app/core/modules/openapi",
"generate:api:intelligence-service:clean": "rimraf server/application-server/src/main/java/de/tum/in/www1/hephaestus/intelligenceservice",
"generate:api:clean": "npm run generate:api:intelligence-service:clean && npm run generate:api:application-server:clean",

"generate:api:application-server-specs": "cd server/application-server && mvn verify -DskipTests=true -Dapp.profiles=specs",
"generate:api:intelligence-service-specs": "python -m server.intelligence-service.app.generate_openapi_yaml",
"generate:api:specs": "npm run generate:api:application-server-specs && npm run generate:api:intelligence-service-specs",

"generate:api:application-server-client": "npx openapi-generator-cli generate -i server/application-server/openapi.yaml -g typescript-angular -o webapp/src/app/core/modules/openapi --additional-properties fileNaming=kebab-case,withInterfaces=true --generate-alias-as-model",
"generate:api": "npm run generate:api:application-server-specs && npm run generate:api:clean && npm run generate:api:application-server-client"
"generate:api:intelligence-service-client": "npx openapi-generator-cli generate -i server/intelligence-service/openapi.yaml -g java --library resttemplate --api-package de.tum.in.www1.hephaestus.intelligenceservice.api --model-package de.tum.in.www1.hephaestus.intelligenceservice.model --invoker-package de.tum.in.www1.hephaestus.intelligenceservice --additional-properties useJakartaEe=true,performBeanValidation=true,generateClientAsBean=true,hideGenerationTimestamp=true --package-name de.tum.in.www1.hephaestus.intelligenceservice -o tmp/java-client && shx cp -r tmp/java-client/src/main/java/de/tum/in/www1/hephaestus/intelligenceservice server/application-server/src/main/java/de/tum/in/www1/hephaestus && rimraf tmp",
"generate:api:clients": "npm run generate:api:intelligence-service-client && npm run generate:api:application-server-client",

"generate:api:application-server": "npm run generate:api:application-server-specs && npm run generate:api:application-server:clean && npm run generate:api:application-server-client",
"generate:api:intelligence-service": "npm run generate:api:intelligence-service:clean && npm run generate:api:intelligence-service-specs && npm run generate:api:intelligence-service-client",
"generate:api": "npm run generate:api:intelligence-service && npm run generate:api:application-server"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "2.13.5",
"rimraf": "6.0.1"
"rimraf": "6.0.1",
"shx": "0.3.4"
}
}
Loading

0 comments on commit 32dfb6d

Please sign in to comment.