Skip to content

Commit

Permalink
Save OpenAPI definition as json, generate client and run tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Hannemann committed Jan 17, 2024
1 parent a8fefc3 commit a027496
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/openapi/python-generator-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packageName: "scicat_openapi_client"
packageUrl: "python.package.url"
49 changes: 49 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,52 @@ jobs:
cp functionalAccounts.json.test functionalAccounts.json
docker-compose up --build -d
npm run test:api
generate_and_test_openapi_client:
name: Generate an test OpenAPI Client libraries
needs: [install-and-cache]
runs-on: ubuntu-latest

steps:
# Checkout your code
- name: Checkout
uses: actions/checkout@v4

# Generate your OpenAPI document (if you don't write it manually)
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: Restore node_modules
id: cached-node-modules
uses: actions/cache@v3
with:
path: node_modules
key: node-modules-${{ hashFiles('package-lock.json') }}-${{ env.NODE_VERSION }}

# Todo: May need reworking in order to not block
- name: Start Backend for later tests and generate openapi.json
run: npm run start

# Use the action to generate a client package
# This uses the default path for the openapi document and thus assumes there is an openapi.json in the current workspace.
# https://github.com/openapi-generators/openapitools-generator-action
# https://openapi-generator.tech/docs/generators/
- name: Generate Python Client
uses: openapi-generators/openapitools-generator-action@v1
with:
generator: python-nextgen
openapi-file: openapi.json
config-file: .github/openapi/python-generator-config.yml

# Run the test the generated client
- name: Run tests with the client
run: |
cd openapi/python
echo "Run some tests"
# Upload code to its own repository
- name: Git Push to its client libraries repository
run: |
./git_push.sh
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ functionalAccounts.json
# Configs
.env

# OpenAPI
openapi
openapi.json

# Logs
logs
*.log
Expand Down
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { AppModule } from "./app.module";
import { Logger, ValidationPipe } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import * as fs from "fs";

async function bootstrap() {
const app = await NestFactory.create(AppModule, {
Expand All @@ -24,6 +25,8 @@ async function bootstrap() {
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(app, config);
fs.writeFileSync("./openapi.json", JSON.stringify(document, null, 2));

const swaggerOptions: SwaggerCustomOptions = {
swaggerOptions: {
docExpansion: "none",
Expand Down

0 comments on commit a027496

Please sign in to comment.