Skip to content

Feature/46 product nl api #42

Feature/46 product nl api

Feature/46 product nl api #42

Workflow file for this run

# Run quality control on the (generated) Open API specification.
#
# The OAS must:
# * not be outdated w/r to the code from which it is generated
# * not have any linting errors
# * be valid input to generate a Postman collection
# * be valid input to generate SDKs in commonly used languages/frameworks
#
# When dealing with multiple versions, you can adapt this workflow to run a matrix and
# pass arguments down that way, and/or use a parent workflow to call this workflow for
# each matrix item. See https://docs.github.com/en/actions/sharing-automations/reusing-workflows
name: OpenAPI specification checks
on:
push:
branches:
- main
- stable/*
pull_request:
workflow_dispatch:
env:
DJANGO_SETTINGS_MODULE: open_producten.conf.ci
jobs:
generate:
name: Generate the API specification from code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up backend environment
uses: maykinmedia/[email protected]
with:
python-version: '3.11'
optimize-postgres: 'no'
setup-node: 'no'
# apt-packages: 'gettext postgresql-client' # the default
# npm-ci-flags: '--legacy-peer-deps' -> preferably use a .npmrc file
- name: Generate the API specification
run: ./bin/generate_api_schema.sh
- name: Store generated API specification for later use
uses: actions/upload-artifact@v4
with:
name: open_producten-oas
path: src/openapi.yaml
retention-days: 1
check-up-to-date:
name: Check for unexepected OAS changes
runs-on: ubuntu-latest
needs:
- generate
steps:
- uses: actions/checkout@v4
- name: Download generated OAS
uses: actions/download-artifact@v4
with:
name: open_producten-oas
- name: Check for OAS changes
run: |
diff openapi.yaml src/openapi.yaml
- name: Write failure markdown
if: ${{ failure() }}
run: |
echo 'Run the following command locally and commit the changes' >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo './bin/generate_api_schema.sh' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
lint:
name: Validate OAS
runs-on: ubuntu-latest
needs:
- check-up-to-date # no point in linting something that's not up to date
steps:
- name: Download generated OAS
uses: actions/download-artifact@v4
with:
name: open_producten-oas
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install spectral
run: npm install -g @stoplight/spectral@5
- name: Run linter
run: spectral lint openapi.yaml
postman-collection:
name: Generate Postman collection
runs-on: ubuntu-latest
needs:
- check-up-to-date # no point in linting something that's not up to date
steps:
- name: Download generated OAS
uses: actions/download-artifact@v4
with:
name: open_producten-oas
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm install -g openapi-to-postmanv2
- name: Create tests folder
run: mkdir -p ./tests/postman
- name: Generate Postman collection
run: |
openapi2postmanv2 \
-s openapi.yaml \
-o ./tests/postman/collection.json \
--pretty
sdks:
name: Generate SDKs from API schema
runs-on: ubuntu-latest
needs:
- check-up-to-date # no point in linting something that's not up to date
steps:
- name: Download generated OAS
uses: actions/download-artifact@v4
with:
name: open_producten-oas
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm install -g @openapitools/openapi-generator-cli
- name: Validate schema
run: |
openapi-generator-cli \
validate -i openapi.yaml
- name: Generate Java client
run: |
openapi-generator-cli \
generate \
-i openapi.yaml \
--global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \
-o ./sdks/java \
-g java \
--additional-properties=dateLibrary=java8,java8=true,optionalProjectFile=false,optionalAssemblyInfo=false
- name: Generate .NET client
run: |
openapi-generator-cli \
generate \
-i openapi.yaml \
--global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \
-o ./sdks/net \
-g csharp \
--additional-properties=optionalProjectFile=false,optionalAssemblyInfo=false
- name: Generate Python client
run: |
openapi-generator-cli \
generate \
-i openapi.yaml \
--global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \
-o ./sdks/python \
-g python \
--additional-properties=optionalProjectFile=false,optionalAssemblyInfo=false+