Skip to content

Commit 32f8bf8

Browse files
authored
PW-7045: Model generation workflow (#809)
* PW-7045: Model generator * PW-7045: Generate models workflow * PW-7045: Link to spec source * PW-7045: Use @AdyenAutomationBot * PW-7045: Generate models only for classic payments Other services need more more work on schemas, templates and dependencies. * PW-7045: Remove PR event
1 parent a1de50f commit 32f8bf8

File tree

4 files changed

+119
-3
lines changed

4 files changed

+119
-3
lines changed

.github/workflows/models.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Java Models
2+
3+
on: [ workflow_dispatch ]
4+
5+
jobs:
6+
generate:
7+
runs-on: ubuntu-latest
8+
name: Generate Models
9+
steps:
10+
- uses: actions/checkout@v3
11+
- run: make models
12+
- name: Set PR variables
13+
id: vars
14+
run: |
15+
cd target/spec
16+
echo ::set-output name=pr_title::"Update models"
17+
echo ::set-output name=pr_body::"OpenAPI spec or templates produced new models on $(date +%d-%m-%Y) \
18+
by [commit](https://github.com/Adyen/adyen-openapi/commit/$(git rev-parse HEAD))."
19+
- name: Create Pull Request
20+
uses: peter-evans/create-pull-request@v4
21+
with:
22+
token: ${{ secrets.ADYEN_AUTOMATION_BOT_ACCESS_TOKEN }}
23+
committer: ${{ secrets.ADYEN_AUTOMATION_BOT_EMAIL }}
24+
author: ${{ secrets.ADYEN_AUTOMATION_BOT_EMAIL }}
25+
base: develop
26+
branch: automation/models
27+
title: ${{ steps.vars.outputs.pr_title }}
28+
body: ${{ steps.vars.outputs.pr_body }}
29+
add-paths: |
30+
src/main/java/com/adyen/model

.openapi-generator-ignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# These models cannot properly represent additional data, a `Map<String, String>` is used instead
2-
src/main/java/com/adyen/model/payments/AdditionalData*
3-
src/main/java/com/adyen/model/payments/ResponseAdditionalData*
2+
target/out/src/main/java/com/adyen/model/payments/AdditionalData*
3+
target/out/src/main/java/com/adyen/model/payments/ResponseAdditionalData*

Makefile

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
openapi-generator-version:=6.0.1
2+
openapi-generator-url:=https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/$(openapi-generator-version)/openapi-generator-cli-$(openapi-generator-version).jar
3+
openapi-generator-jar:=target/openapi-generator-cli.jar
4+
openapi-generator-cli:=java -jar $(openapi-generator-jar)
5+
6+
generator:=java
7+
library:=okhttp-gson
8+
services:=payments
9+
models:=src/main/java/com/adyen/model
10+
output:=target/out
11+
12+
13+
# Generate models (for each service)
14+
models: $(services)
15+
16+
binlookup: spec=BinLookupService-v52
17+
checkout: spec=CheckoutService-v69
18+
storedValue: spec=StoredValueService-v46
19+
posterminalmanagement: spec=TfmAPIService-v1
20+
payments: spec=PaymentService-v68
21+
recurring: spec=RecurringService-v68
22+
payout: spec=PayoutService-v68
23+
management: spec=ManagementService-v1
24+
balanceplatform: spec=BalancePlatformService-v2
25+
transfers: spec=TransferService-v3
26+
# Classic Platforms
27+
marketpay/account: spec=AccountService-v6
28+
marketpay/fund: spec=FundService-v6
29+
marketpay/configuration: spec=NotificationConfigurationService-v6
30+
marketpay/webhooks: spec=MarketPayNotificationService-v6
31+
hop: spec=HopService-v6
32+
33+
$(services): target/spec $(openapi-generator-jar)
34+
rm -rf $(models)/$@ $(output)
35+
$(openapi-generator-cli) generate \
36+
-i target/spec/json/$(spec).json \
37+
-g $(generator) \
38+
-t templates \
39+
-o $(output) \
40+
--ignore-file-override ./.openapi-generator-ignore \
41+
--skip-validate-spec \
42+
--model-package $(subst /,.,com.adyen.model.$@) \
43+
--library $(library) \
44+
--global-property models \
45+
--global-property modelDocs=false \
46+
--global-property modelTests=false \
47+
--additional-properties=dateLibrary=legacy
48+
mv $(output)/$(models)/$@ $(models)/$@
49+
50+
51+
# Checkout spec (and patch version)
52+
target/spec:
53+
git clone https://github.com/Adyen/adyen-openapi.git target/spec
54+
perl -i -pe's/"openapi" : "3.[0-9].[0-9]"/"openapi" : "3.0.0"/' target/spec/json/*.json
55+
56+
57+
# Extract templates (copy them for modifications)
58+
templates: $(openapi-generator-jar)
59+
$(openapi-generator-cli) author template -g $(generator) --library $(library) -o target/templates
60+
61+
62+
# Download the generator
63+
$(openapi-generator-jar):
64+
wget --quiet -o /dev/null $(openapi-generator-url) -O $(openapi-generator-jar)
65+
66+
67+
# Discard generated artifacts and changed models
68+
clean:
69+
rm -rf $(output)
70+
git checkout $(models)
71+
git clean -f -d $(models)
72+
73+
74+
.PHONY: templates models $(services)

pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<properties>
2626
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2727
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
28+
<swagger-core-version>1.6.5</swagger-core-version>
2829
</properties>
2930
<scm>
3031
<connection>scm:git:[email protected]:Adyen/adyen-java-api-library.git</connection>
@@ -137,7 +138,6 @@
137138
<version>3.2.0</version>
138139
<configuration>
139140
<configLocation>checkstyle.xml</configLocation>
140-
<encoding>UTF-8</encoding>
141141
<consoleOutput>true</consoleOutput>
142142
<failsOnError>true</failsOnError>
143143
</configuration>
@@ -231,5 +231,17 @@
231231
<artifactId>swagger-annotations</artifactId>
232232
<version>2.2.2</version>
233233
</dependency>
234+
<!-- Generated model annotations -->
235+
<dependency>
236+
<groupId>io.swagger</groupId>
237+
<artifactId>swagger-annotations</artifactId>
238+
<version>${swagger-core-version}</version>
239+
</dependency>
240+
<!-- @Nullable annotation -->
241+
<dependency>
242+
<groupId>com.google.code.findbugs</groupId>
243+
<artifactId>jsr305</artifactId>
244+
<version>3.0.2</version>
245+
</dependency>
234246
</dependencies>
235247
</project>

0 commit comments

Comments
 (0)