Skip to content

Commit

Permalink
Add github action to generate single API spec
Browse files Browse the repository at this point in the history
  • Loading branch information
dvacca-onfido committed Feb 26, 2024
1 parent fa7e846 commit 3d14db7
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 1 deletion.
24 changes: 24 additions & 0 deletions .github/workflows/generate-single-openapi-spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: generate-single-openapi-spec
run-name: Build and publish single-file Onfido OpenAPI specs
on:
push:
branches:
- main
pull_request:
jobs:
build-single-files:
runs-on: ubuntu-latest
container:
image: openapitools/openapi-generator-cli:v7.3.0
env:
OPENAPI_GENERATOR_COMMAND: docker-entrypoint.sh
steps:
- uses: actions/checkout@v4
- name: Install pre-requisites
run: |
apt-get update
apt-get install gettext-base
- name: Build single-file Onfido OpenAPI defintions
run: |
sh -s ./generator/script/generate.sh \
generator/configuration/openapi*.yaml
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
generated/**/.openapi-generator*
generated/configuration
generated/artifacts/*/.openapi-generator*
7 changes: 7 additions & 0 deletions generator/configuration/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
inputSpec: /local/openapi.yaml
gitUserId: onfido
generatorName: ${GENERATOR}
templateDir: /local/generator/templates/${GENERATOR}
outputDir: generated/artifacts/${GENERATOR}
useOneOfDiscriminatorLookup: true
disallowAdditionalPropertiesIfNotPresent: false
Empty file.
Empty file.
32 changes: 32 additions & 0 deletions generator/script/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

# Don't carry on when any command fails
set -e

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
BASEDIR=${SCRIPT_DIR}/../..

CONFIG_FILES=${*:-`ls generator/configuration/*.yaml`}

OPENAPI_GENERATOR_COMMAND=${OPENAPI_GENERATOR:-docker run \
--rm -v "$(pwd):/local" -w /local \
openapitools/openapi-generator-cli:v7.3.0}

cd ${BASEDIR}
rm -rf generated; mkdir -p generated/configuration

for CONFIG_FILE in $CONFIG_FILES
do
GENERATOR=$(basename $CONFIG_FILE .yaml)

if [ "${GENERATOR}" != "common" ]; then
( cat generator/configuration/common.yaml && echo &&
cat generator/configuration/${GENERATOR}.yaml ) | \
API_VERSION=1.6.0 GENERATOR=${GENERATOR} envsubst >| \
generated/configuration/${GENERATOR}.yaml

echo "Configuration for generator ${GENERATOR} built."
fi
done

${OPENAPI_GENERATOR_COMMAND} batch --clean --root-dir /local generated/configuration/*.yaml

0 comments on commit 3d14db7

Please sign in to comment.