Skip to content

Commit 6059e77

Browse files
[CAT-1069] Create configuration for onfido-python library generation (#64)
* Preliminary changes to allow delivery generated code with multiple libraries * Add Python (sync) client library configuration
1 parent 663fd27 commit 6059e77

39 files changed

+1332
-52
lines changed

.github/workflows/update-specs-and-client-libraries.yaml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ on:
3636
required: true
3737
default: false
3838
type: boolean
39+
update-onfido-python:
40+
description: "Update onfido-python?"
41+
required: true
42+
default: false
43+
type: boolean
3944
jobs:
4045
validate_input_specs:
4146
name: Validate multi file specification
@@ -51,6 +56,7 @@ jobs:
5156
java_version: ${{ steps.generator.outputs.java_version }}
5257
typescript_axios_version: ${{ steps.generator.outputs.typescript_axios_version }}
5358
php_version: ${{ steps.generator.outputs.php_version }}
59+
python_version: ${{ steps.generator.outputs.python_version }}
5460
container:
5561
image: openapitools/openapi-generator-cli:v7.4.0
5662
env:
@@ -64,7 +70,8 @@ jobs:
6470
apt-get install -yqq \
6571
gettext-base \
6672
git \
67-
jq
73+
jq \
74+
pipx
6875
- name: Validate multi-file OpenAPI specification
6976
run: |
7077
$OPENAPI_GENERATOR_COMMAND validate -i openapi.yaml
@@ -78,7 +85,7 @@ jobs:
7885
name: artifacts-${{ github.workflow }}-${{ github.run_id }}-${{ github.run_number }}
7986
path: |
8087
generated/artifacts
81-
generators/*/exclusions.txt
88+
generators/**/exclusions.txt
8289
update_specs:
8390
name: Update and commit single-file OpenAPI specifications
8491
runs-on: ubuntu-latest
@@ -112,7 +119,7 @@ jobs:
112119
strategy:
113120
matrix:
114121
include:
115-
- generator: java
122+
- generator: java/okhttp-gson
116123
git_repo_id: onfido-java
117124
preCommit: |
118125
mvn -B package --file pom.xml clean
@@ -127,9 +134,16 @@ jobs:
127134
- generator: php
128135
git_repo_id: onfido-php
129136
preCommit: |
130-
composer install
137+
composer update --lock
131138
version: ${{ needs.generate_specs_and_libraries.outputs.php_version }}
132139
update: ${{ inputs.update-onfido-php }}
140+
- generator: python/urllib3
141+
git_repo_id: onfido-python
142+
preCommit: |
143+
pipx install poetry==1.8
144+
poetry lock
145+
version: ${{ needs.generate_specs_and_libraries.outputs.python_version }}
146+
update: ${{ inputs.update-onfido-python }}
133147
if: github.event_name == 'workflow_dispatch'
134148
steps:
135149
- uses: actions/checkout@v4
@@ -143,7 +157,8 @@ jobs:
143157
- name: Integrate generated code (${{ matrix.version }})
144158
if: ${{ matrix.update }}
145159
run: |
146-
rsync -r --delete-after --exclude='/.git*' --exclude='CHANGELOG*' \
160+
rsync -r --delete-after --exclude='/.git*' --exclude='/CHANGELOG*' \
161+
--exclude='/.openapi-generator-ignore' \
147162
--exclude-from=generators/${{ matrix.generator }}/exclusions.txt \
148163
generated/artifacts/${{ matrix.generator }}/ .
149164
- name: Run pre-commit script

generators/common/config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
inputSpec: openapi.yaml
22
gitUserId: onfido
3-
generatorName: ${GENERATOR}
3+
generatorName: ${GENERATOR_NAME}
4+
library: "${GENERATOR_LIBRARY}"
45
templateDir: generators/${GENERATOR}/templates
56
outputDir: generated/artifacts/${GENERATOR}
67
disallowAdditionalPropertiesIfNotPresent: false

generators/common/templates/.openapi-generator-ignore

Whitespace-only changes.

generators/java/config.yaml renamed to generators/java/okhttp-gson/config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ groupId: com.onfido
55
invokerPackage: com.onfido
66
apiPackage: com.onfido.api
77
modelPackage: com.onfido.model
8-
library: okhttp-gson
98
httpUserAgent: onfido-java/${CLIENT_LIBRARY_VERSION}
109
artifactDescription: Official Java API client library for the Onfido API
1110
artifactUrl: https://documentation.onfido.com
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../common/templates/LICENSE.mustache

generators/java/templates/README.mustache renamed to generators/java/okhttp-gson/templates/README.mustache

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ The official Java library for integrating with the Onfido API.
44

55
Documentation can be found at <{{ documentationUrl }}>.
66

7-
This library is only for use on the backend, as it uses Onfido API tokens which must be kept secret.
7+
This library is only for use on the backend, as it uses Onfido API tokens which must be kept secret. If you do need to collect applicant data in the frontend of your application, we recommend that you use the Onfido SDKs: [iOS](https://github.com/onfido/onfido-ios-sdk), [Android](https://github.com/onfido/onfido-android-sdk), [Web](https://github.com/onfido/onfido-sdk-ui), and [React Native](https://github.com/onfido/react-native-sdk).
88

99
This version uses Onfido API {{ apiVersion }}. Refer to our [API versioning guide](https://developers.onfido.com/guide/api-versioning-policy#client-libraries) for details of which client library versions use which versions of the API.
1010

11-
## Requirements
11+
## Installation & Usage
12+
13+
### Requirements
1214

1315
Building the API client library requires:
1416

@@ -20,7 +22,7 @@ Building the API client library requires:
2022
3. Maven/Gradle
2123
{{/jersey2}}
2224

23-
## Installation
25+
### Installation
2426

2527
To install the API client library to your local Maven repository, simply execute:
2628

@@ -36,7 +38,7 @@ mvn clean deploy
3638

3739
Refer to the [OSSRH Guide](http://central.sonatype.org/pages/ossrh-guide.html) for more information.
3840

39-
### Maven users
41+
#### Maven users
4042

4143
Add this dependency to your project's POM:
4244

@@ -49,7 +51,7 @@ Add this dependency to your project's POM:
4951
</dependency>
5052
```
5153

52-
## Gradle users
54+
#### Gradle users
5355

5456
Add this dependency to your project's build file:
5557

@@ -64,7 +66,7 @@ Add this dependency to your project's build file:
6466
}
6567
```
6668

67-
### Others
69+
#### Others
6870

6971
At first generate the JAR by executing:
7072

@@ -86,6 +88,7 @@ Import the `DefaultApi` object, this is the main object used for interfacing wit
8688
```java
8789
import com.onfido.api.DefaultApi;
8890
import com.onfido.ApiException;
91+
import com.onfido.OnfidoInvalidSignatureError;
8992
```
9093

9194
Instantiate and configure an `Onfido` instance with your API token, and region if necessary:
@@ -100,7 +103,7 @@ DefaultApi onfido = new DefaultApi(Configuration.getDefaultApiClient()
100103

101104
NB: by default, timeout values are set to 30 seconds.
102105

103-
## Making a call to the API
106+
### Making a call to the API
104107

105108
Most of the request bodies can be created using a builder pattern, this would look something like:
106109

@@ -121,14 +124,6 @@ try {
121124
122125
// ...
123126
124-
// Webhook verification
125-
WebhookEventVerifier verifier = new WebhookEventVerifier("_ABC123abc...3ABC123_");
126-
127-
String signature = "a0...760e";
128-
129-
WebhookEvent event = verifier.readPayload(rawEvent, signature);
130-
131-
const event = verifier.readPayload("{\"payload\":{\"r...3\"}}}", signature);
132127
} catch (ApiException e) {
133128
// An error response was received from the Onfido API, extra info is available.
134129
System.out.println(e.getMessage());
@@ -139,7 +134,24 @@ try {
139134
}
140135
```
141136

142-
## Recommendation
137+
### Webhook event verification
138+
139+
Webhook events payload needs to be verified before it can be accessed. Library allows to easily decode the payload and verify its signature before returning it as an object for user convenience:
140+
141+
```java
142+
try {
143+
WebhookEventVerifier verifier = new WebhookEventVerifier("_ABC123abc...3ABC123_");
144+
145+
String signature = "a0...760e";
146+
147+
WebhookEvent event = verifier.readPayload("{\"payload\":{\"r...3\"}}}", signature);
148+
} catch( OnfidoInvalidSignatureError e ) {
149+
// Invalid webhook signature
150+
}
151+
```
152+
153+
154+
### Recommendation
143155

144156
It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues.
145157

generators/java/templates/.openapi-generator-ignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

generators/java/templates/LICENSE.mustache

Lines changed: 0 additions & 1 deletion
This file was deleted.

generators/openapi-yaml/config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
files:
2+
README.mustache:
3+
destinationFilename: README.md

generators/openapi-yaml/templates/.openapi-generator-ignore

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Onfido OpenAPI YAML specification
2+
3+
The official OpenAPI YAML specification of Onfido API.
4+
5+
Documentation can be found at <{{ documentationUrl }}>.
6+
7+
This version is based on Onfido API {{ apiVersion }}.

generators/openapi/config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
files:
2+
README.mustache:
3+
destinationFilename: README.md

generators/openapi/templates/.openapi-generator-ignore

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Onfido OpenAPI JSON specification
2+
3+
The official OpenAPI JSON specification of Onfido API.
4+
5+
Documentation can be found at <{{ documentationUrl }}>.
6+
7+
This version is based on Onfido API {{ apiVersion }}.

generators/php/exclusions.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/test/
22
/docs/
3-
/git_push.sh
3+
/vendor/
4+
/composer.lock
5+
/git_push.sh
6+
/.travis.yml

generators/php/templates/.openapi-generator-ignore

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Onfido PHP Library
2+
3+
The official PHP library for integrating with the Onfido API.
4+
5+
Documentation can be found at <{{ documentationUrl }}>.
6+
7+
This version uses Onfido API {{ apiVersion }}. Refer to our [API versioning guide](https://developers.onfido.com/guide/api-versioning-policy#client-libraries) for details of which client library versions use which versions of the API.
8+
9+
## Installation & Usage
10+
11+
### Requirements
12+
13+
PHP 7.4 and later.
14+
Should also work with PHP 8.0.
15+
16+
### Installation
17+
18+
#### Composer
19+
20+
To install the bindings via [Composer](https://getcomposer.org/), add the following to `composer.json`:
21+
22+
```json
23+
{
24+
"repositories": [
25+
{
26+
"type": "vcs",
27+
"url": "https://{{gitHost}}/{{gitUserId}}/{{gitRepoId}}.git"
28+
}
29+
],
30+
"require": {
31+
"{{gitUserId}}/{{gitRepoId}}": "*@dev"
32+
}
33+
}
34+
```
35+
36+
Then run `composer install`
37+
38+
#### Manual Installation
39+
40+
Download the files and include `autoload.php`:
41+
42+
```php
43+
<?php
44+
require_once('/path/to/{{packageName}}/vendor/autoload.php');
45+
```
46+
47+
## Getting Started
48+
49+
Please follow the [installation procedure](#installation--usage) and then run the following:
50+
51+
```php
52+
<?php
53+
require_once(__DIR__ . '/vendor/autoload.php');
54+
55+
$configuration = {{invokerPackage}}\Configuration::getDefaultConfiguration();
56+
$configuration->setApiToken($_ENV['ONFIDO_API_TOKEN']);
57+
$configuration->setRegion({{invokerPackage}}\Region::EU); // Supports `EU`, `US` and `CA`
58+
59+
$onfidoApi = new {{invokerPackage}}\Api\DefaultApi(
60+
new \GuzzleHttp\Client([
61+
'timeout' => 30,
62+
'connect_timeout' => 30,
63+
'read_timeout' => 30
64+
]), $configuration);
65+
66+
```
67+
68+
### Making a call to the API
69+
70+
```php
71+
try {
72+
$applicant = $onfidoApi->createApplicant(
73+
new {{invokerPackage}}\Model\ApplicantBuilder(
74+
[
75+
'first_name' => 'First',
76+
'last_name' => 'Last'
77+
])
78+
);
79+
80+
// To access the information use the getter for the desired property on the object, for example:
81+
$applicant->getFirstName();
82+
83+
// ...
84+
85+
} catch ({{invokerPackage}}\ApiException $ex) {
86+
// Handle API exception
87+
echo 'Caught exception: ', $ex->getMessage(), "\n";
88+
}
89+
```
90+
91+
### Webhook event verification
92+
93+
Webhook events payload needs to be verified before it can be accessed. Library allows to easily decode the payload and verify its signature before returning it as an object for user convenience:
94+
95+
```php
96+
try {
97+
$verifier = new Onfido\WebhookEventVerifier('_ABC123abc...3ABC123_');
98+
99+
$signature = 'a0...760e';
100+
101+
$event = $verifier->readPayload('{"payload":{"r...3"}}', $signature);
102+
} catch ({{invokerPackage}}\OnfidoInvalidSignatureError $ex) {
103+
// Invalid webhook signature
104+
}
105+
```
106+
107+
## Contributing
108+
109+
This library is automatically generated using [OpenAPI Generator](https://openapi-generator.tech) - version: {{generatorVersion}};
110+
therefore all the contributions, except tests files, should target [Onfido OpenAPI specification repository](https://github.com/onfido/onfido-openapi-spec/tree/master) instead of this repository.
111+
112+
For contributions to the tests instead, please follow the steps below:
113+
114+
1. [Fork](<https://github.com/{{ gitUserId }}/{{ gitRepoId }}/fork>) repository
115+
2. Create your feature branch (`git checkout -b my-new-feature`)
116+
3. Make your changes
117+
4. Commit your changes (`git commit -am 'Add some feature'`)
118+
5. Push to the branch (`git push origin my-new-feature`)
119+
6. Create a new Pull Request
120+
121+
## More documentation
122+
123+
More documentation and code examples can be found at <{{ documentationUrl }}>.
124+
125+
## Support
126+
127+
Should you encounter any technical issues during integration, please contact Onfido's Customer Support team
128+
via the [{{ supportDescription }}]({{ supportUrl }}) which also include support documentation.

generators/php/templates/SHA256SUM

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

22
bb92a3f3107664c296ebc45c75bff7c88abf8b765565f4656a05e24234cb6d67 ./Configuration.mustache
3+
8eebaed003795c011df87fecd1f89c630dd3f23282d80e7f407f62009e2cd0ee ./README.mustache
34
2d94750ad5d913f8b7fbba24681c7cc1d75e96c89ec46c379e6625c825b39020 ./model_generic.mustache
45
37d3333c7c3dbc6f6bffe64ce076bc512a2a1e61e986738c8e023bb745168e9a ./phpunit.xml.mustache

0 commit comments

Comments
 (0)