-
-
Notifications
You must be signed in to change notification settings - Fork 56
feat: first-class openapi SDK generation for backend-frontend communication #231 #438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
65f266c
feat: implement auto-generated TypeScript API client from OpenAPI spec
pankajydv07 3b1a9fb
chore(release): v0.1.0-alpha.31 [skip ci]
github-actions[bot] 622e3f7
chore(release): update version.txt to v0.1.0-alpha.31
github-actions[bot] 258ab4e
feat: implement auto-generated TypeScript API client for issue #231
pankajydv07 89a1cf1
Merge branch 'master' of https://github.com/pankajydv07/nixopus
pankajydv07 e603367
Revert auto-generated/versioning files and remove example usage from β¦
pankajydv07 d74c008
Revert auto-generated/versioning files and remove example usage from β¦
pankajydv07 1455b37
Fix GitHub workflow push failures on pull requests with proper event β¦
pankajydv07 1421244
Added cleanup step before checking for changes
pankajydv07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
name: Auto-Generate API Types | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'api/**' | ||
branches: [ master, develop ] | ||
pull_request: | ||
paths: | ||
- 'api/**' | ||
|
||
jobs: | ||
generate-api-types: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.21' | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '18' | ||
cache: 'npm' | ||
cache-dependency-path: view/package-lock.json | ||
|
||
- name: Install Go dependencies | ||
run: | | ||
cd api | ||
go mod download | ||
|
||
- name: Build API server | ||
run: | | ||
cd api | ||
go build -o nixopus-api | ||
|
||
- name: Start API server in background | ||
run: | | ||
cd api | ||
./nixopus-api & | ||
SERVER_PID=$! | ||
echo "SERVER_PID=$SERVER_PID" >> $GITHUB_ENV | ||
|
||
# Wait for server to start | ||
for i in {1..30}; do | ||
if curl -f http://localhost:8080/api/v1/health > /dev/null 2>&1; then | ||
echo "Server is running" | ||
break | ||
fi | ||
echo "Waiting for server to start... ($i/30)" | ||
sleep 2 | ||
done | ||
|
||
- name: Generate OpenAPI spec | ||
run: | | ||
curl http://localhost:8080/api/openapi.json > api/doc/openapi.json | ||
|
||
- name: Install frontend dependencies | ||
run: | | ||
cd view | ||
npm ci --legacy-peer-deps | ||
|
||
- name: Generate TypeScript API client | ||
run: | | ||
cd view | ||
npm run generate:api | ||
|
||
- name: Stop API server | ||
run: | | ||
if [ ! -z "$SERVER_PID" ]; then | ||
kill $SERVER_PID || true | ||
fi | ||
|
||
- name: Clean up build artifacts | ||
run: | | ||
rm -f api/nixopus-api | ||
|
||
- name: Check for changes | ||
id: verify-changed-files | ||
run: | | ||
if [ -n "$(git status --porcelain)" ]; then | ||
echo "changed=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "changed=false" >> $GITHUB_OUTPUT | ||
fi | ||
|
||
- name: Commit generated types | ||
if: steps.verify-changed-files.outputs.changed == 'true' | ||
run: | | ||
git config --local user.email "action@github.com" | ||
git config --local user.name "GitHub Action" | ||
git add view/src/generated/ api/doc/openapi.json | ||
git commit -m "chore: update generated API types and OpenAPI spec [skip ci]" | ||
|
||
- name: Push changes | ||
if: github.event_name == 'push' && steps.verify-changed-files.outputs.changed == 'true' | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: ${{ github.ref }} | ||
|
||
- name: Comment on PR | ||
if: github.event_name == 'pull_request' && steps.verify-changed-files.outputs.changed == 'true' | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: 'π€ API types have been automatically updated based on OpenAPI spec changes.' | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.