Skip to content
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

Add github action to generate single API spec #43

Merged
merged 12 commits into from
Feb 27, 2024
59 changes: 59 additions & 0 deletions .github/workflows/generate-single-openapi-spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: generate-single-openapi-spec
run-name: Build and publish single-file OpenAPI specs
on:
push:
branches:
- main
pull_request:
jobs:
build-single-spec:
name: Build single-file OpenAPI specifications
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 -yqq \
gettext-base
- name: Validate multi-file OpenAPI specification
run: |
$OPENAPI_GENERATOR_COMMAND validate -i openapi.yaml
- name: Refresh single-file OpenAPI specifications
run: |
./generator/script/generate.sh \
generator/configuration/openapi.yaml \
generator/configuration/openapi-yaml.yaml
- name: Store generated artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ github.workflow }}-${{ github.run_id }}-${{ github.run_number }}
path: generated/artifacts
commit-single-spec:
name: Commit and push single-file OpenAPI specifications
runs-on: ubuntu-latest
needs: build-single-spec
if: ${{ github.event.pull_request.merged && github.repository == 'onfido/onfido-openapi-spec' }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: artifacts-${{ github.workflow }}-${{ github.run_id }}-${{ github.run_number }}
path: generated/artifacts
- name: Commit and push single-file OpenAPI specifications
run: |
git --version
if [ -z "$(git status --porcelain=v1 generated/artifacts)" ];
then
echo "no change detected"
else
git config user.name "GitHub Actions Bot"
git config user.email "<>"
git status generated/artifacts
git commit -m "Single file specifications refresh" generated/artifacts
git push
fi
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*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Onfido OpenAPI specification (beta)

:warning: Our OpenAPI specification is currently in beta and we welcome any feedback. You can contact us via the issues tab or [email](mailto:openapi-feedback@onfido.com), but we don't yet officially support this specification. :warning:
:warning: Our OpenAPI specification is currently in beta and we welcome any feedback. You can contact us via the issues tab or [support portal](https://public.support.onfido.com), but we don't yet officially support this specification. :warning:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider that the spec is out of beta since we have all the reports ?

Copy link
Contributor Author

@dvacca-onfido dvacca-onfido Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should wait a little bit longer, to have at least one (generated) client library sufficiently tested to be definition maps quite well the actual API.


This specification supports the latest version of the Onfido API.

Expand Down
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: openapi.yaml
gitUserId: onfido
generatorName: ${GENERATOR}
templateDir: generator/templates/${GENERATOR}
outputDir: generated/artifacts/${GENERATOR}
useOneOfDiscriminatorLookup: true
disallowAdditionalPropertiesIfNotPresent: false
Empty file.
Empty file.
38 changes: 38 additions & 0 deletions generator/script/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/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`}
GENERATED_CONFIG_FILES=""

OPENAPI_GENERATOR_COMMAND=${OPENAPI_GENERATOR_COMMAND:-\
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
GENERATED_CONFIG_FILE=generated/configuration/${GENERATOR}.yaml

( cat generator/configuration/common.yaml && echo &&
cat generator/configuration/${GENERATOR}.yaml ) | \
GENERATOR=${GENERATOR} envsubst >| \
${GENERATED_CONFIG_FILE}

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

GENERATED_CONFIG_FILES="${GENERATED_CONFIG_FILES} ${GENERATED_CONFIG_FILE}"
fi
done

${OPENAPI_GENERATOR_COMMAND} batch --clean ${GENERATED_CONFIG_FILES}
1 change: 1 addition & 0 deletions generator/templates/openapi-yaml/.openapi-generator-ignore
1 change: 1 addition & 0 deletions generator/templates/openapi/.openapi-generator-ignore
2 changes: 1 addition & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ info:
version: 3.6.0
contact:
name: Onfido
email: engineering@onfido.com
url: https://public.support.onfido.com
license:
name: MIT
servers:
Expand Down
104 changes: 104 additions & 0 deletions schemas/workflow_runs/definitions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
workflow_run_shared:
type: object
properties:
applicant_id:
type: string
description: The unique identifier for the Applicant.
workflow_id:
type: string
description: The unique identifier for the Workflow.
tags:
type: array
maxItems: 30
description: Tags or labels assigned to the workflow run.
uniqueItems: true
items:
type: string
minLength: 1
maxLength: 128
link:
type: object
description: Object for the configuration of the Workflow Run link.
properties:
url:
type: string
description: Link to access the Workflow Run without the need to integrate with Onfido's SDKs.
completed_redirect_url:
type: string
description: When the interactive section of the Workflow Run has completed successfully, the user will be redirected to this URL instead of seeing the default Onfido 'thank you' page.
expired_redirect_url:
type: string
description: When the link has expired, the user will be immediately redirected to this URL instead of seeing the default Onfido error message.
expires_at:
type: string
format: date-time
description: Date and time when the link will expire.
language:
type: string
enum:
- en_US
- de_DE
- es_ES
- fr_FR
- it_IT
- pt_PT
- nl_NL
description: The code for the language when the workflow run is acessed using the link.
created_at:
type: string
format: date-time
description: The date and time when the Workflow Run was created.
updated_at:
type: string
format: date-time
description: The date and time when the Workflow Run was last updated.

workflow_run_request:
type: object
properties:
custom_data:
type: object
additionalProperties: true
description: Object with Custom Input Data to be used in the Workflow Run.

workflow_run_response:
type: object
properties:
id:
type: string
description: The unique identifier for the Workflow Run.
workflow_version_id:
type: integer
description: The identifier for the Workflow version.
dashboard_url:
type: string
description: The URL for viewing the Workflow Run results on your Onfido Dashboard.
status:
type: string
enum:
- awaiting_input
- processing
- abandoned
- error
- approved
- review
- declined
description: The status of the Workflow Run.
output:
type: object
description: Output object contains all of the properties configured on the Workflow version.
reasons:
type: array
description: The reasons the Workflow Run outcome was reached. Configurable when creating the Workflow version.
items:
type: string
error:
type: object
description: Error object. Only set when the Workflow Run status is 'error'.
properties:
type:
type: string
description: The type of error.
message:
type: string
description: A textual description of the error.
6 changes: 6 additions & 0 deletions schemas/workflow_runs/workflow_run_builder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
required:
- workflow_id
- applicant_id
allOf:
- $ref: definitions.yaml#/workflow_run_shared
- $ref: definitions.yaml#/workflow_run_request