-
Notifications
You must be signed in to change notification settings - Fork 28
/
Makefile
120 lines (103 loc) · 4.31 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
goimports:=$(shell go env GOPATH)/bin/goimports
build:
@echo "Building Adyen Go API library"
go build -o bin/main main.go
run:
@echo "Building and running Adyen Go API library"
go run main.go
test:
@echo "Testing Adyen Go API library"
go test ./...
# Download the import optimizer (and code formatter)
$(goimports):
go install golang.org/x/tools/cmd/goimports@v0.24.0
fmt: $(goimports)
$(goimports) -w src
verify: build run test
## Automation
openapi-generator-version:=6.5.0
openapi-generator-url:=https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/$(openapi-generator-version)/openapi-generator-cli-$(openapi-generator-version).jar
openapi-generator-jar:=bin/openapi-generator-cli.jar
openapi-generator-cli:=java -jar $(openapi-generator-jar)
generator:=go
services:=balancecontrol balanceplatform acswebhook configurationwebhook reportwebhook transferwebhook binlookup checkout legalentity management managementwebhook payments payout posterminalmanagement recurring storedvalue transfers dataprotection
services+=disputes transactionwebhook
output:=src
templates:=templates/custom
# Generate models (for each service)
models: $(services)
balancecontrol: spec=BalanceControlService-v1
balanceplatform: spec=BalancePlatformService-v2
balanceplatform: serviceName=BalancePlatform
balanceplatform: hasRestServiceError=true
# Balance Platform Webhooks
acswebhook: spec=BalancePlatformAcsNotification-v1
configurationwebhook: spec=BalancePlatformConfigurationNotification-v1
reportwebhook: spec=BalancePlatformReportNotification-v1
transferwebhook: spec=BalancePlatformTransferNotification-v4
binlookup: spec=BinLookupService-v54
checkout: spec=CheckoutService-v71
checkout: serviceName=Checkout
legalentity: spec=LegalEntityService-v3
legalentity: serviceName=LegalEntity
payments: spec=PaymentService-v68
payout: spec=PayoutService-v68
recurring: spec=RecurringService-v68
storedvalue: spec=StoredValueService-v46
storedvalue: serviceName=StoredValue
transfers: spec=TransferService-v4
transfers: serviceName=Transfers
transfers: hasRestServiceError=true
management: spec=ManagementService-v3
management: serviceName=Management
management: hasRestServiceError=true
managementwebhook: spec=ManagementNotificationService-v3
transactionwebhook: spec=BalancePlatformTransactionNotification-v4
posterminalmanagement: spec=TfmAPIService-v1
posterminalmanagement: serviceName=PosTerminalManagementApi
dataprotection: spec=DataProtectionService-v1
dataprotection: serviceName=DataProtection
disputes: spec=DisputeService-v30
disputes: serviceName=Disputes
# Generate a full client (models and service classes)
$(services): schema $(openapi-generator-jar) $(goimports)
GO_POST_PROCESS_FILE="$(goimports) -w" $(openapi-generator-cli) generate \
-i schema/json/$(spec).json \
-g $(generator) \
-t $(templates) \
-o $(output)/$(@) \
-p packageName=$(@) \
-c ./templates/config.yaml \
--global-property apis,models \
--global-property supportingFiles=client.go \
--global-property apiTests=false \
--global-property apiDocs=false \
--global-property modelDocs=false \
--skip-validate-spec \
--enable-post-process-file \
--inline-schema-name-mappings PaymentRequest_paymentMethod=CheckoutPaymentMethod \
--inline-schema-name-mappings DonationPaymentRequest_paymentMethod=DonationPaymentMethod \
--additional-properties=serviceName=$(serviceName) \
--additional-properties=$(if $(hasRestServiceError),hasRestServiceError=true)
rm -rf $(output)/$(@)/go.{mod,sum}
rm -rf $(output)/$(@)/.openapi-generator/FILES
# Clone OpenAPI spec (and apply local patches)
schema:
git clone https://github.com/Adyen/adyen-openapi.git schema
perl -i -pe 's/"openapi" : "3.[0-9].[0-9]"/"openapi" : "3.0.0"/' schema/json/*.json
for json in schema/json/*.json; do \
jq -e 'if has("paths") then .paths[][] |= (.operationId = ."x-methodName") else . end' $$json > "$${json}.tmp"; \
mv "$${json}.tmp" $$json; \
done
# Extract templates (copy them for modifications)
templates: $(openapi-generator-jar)
$(openapi-generator-cli) author template -g $(generator) -o schema/templates
# Download the generator
$(openapi-generator-jar):
mkdir -p bin
wget --quiet -o /dev/null $(openapi-generator-url) -O $(openapi-generator-jar)
# Discard generated artifacts and changed models
clean:
git checkout src
git clean -f -d src
.PHONY: templates models $(services)