diff --git a/.github/openapi/python-generator-config.yml b/.github/openapi/python-generator-config.yml new file mode 100644 index 000000000..7fea71536 --- /dev/null +++ b/.github/openapi/python-generator-config.yml @@ -0,0 +1,2 @@ +packageName: "scicat_openapi_client" +packageUrl: "python.package.url" \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 99ebaee3c..368c8c06e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/.gitignore b/.gitignore index 4dcbba451..e8f5945c6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,10 @@ functionalAccounts.json # Configs .env +# OpenAPI +openapi +openapi.json + # Logs logs *.log diff --git a/src/main.ts b/src/main.ts index 7c0fd9443..e89681176 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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, { @@ -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",