1+ plugins {
2+ id ' org.openapi.generator'
3+ }
4+
5+ import com.adyen.sdk.Service
6+ import groovy.json.JsonOutput
7+ import groovy.json.JsonSlurper
18import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
29
310repositories {
411 // Use Maven Central for resolving dependencies.
512 mavenCentral()
613}
714
15+ List<Service > services = [
16+ // Payments
17+ new Service (name : ' Checkout' , version : 71 ),
18+ new Service (name : ' Payout' , version : 68 ),
19+ new Service (name : ' Recurring' , version : 68 , small : true ),
20+ new Service (name : ' BinLookup' , version : 54 , small : true ),
21+ // Point of Sale
22+ new Service (name : ' PosTerminalManagement' , spec : ' TfmAPIService' , version : 1 , small : true ),
23+ // Management
24+ new Service (name : ' Management' , version : 3 ),
25+ new Service (name : ' BalanceControl' , version : 1 , small : true ),
26+ // Adyen for Platforms
27+ new Service (name : ' LegalEntityManagement' , spec : ' LegalEntityService' , version : 3 ),
28+ new Service (name : ' BalancePlatform' , version : 2 ),
29+ new Service (name : ' Transfers' , spec : ' TransferService' , version : 4 ),
30+ new Service (name : ' DataProtection' , version : 1 , small : true ),
31+ // Classic Payments
32+ new Service (name : ' Payment' , version : 68 , small : true ),
33+ // Others
34+ new Service (name : ' StoredValue' , version : 46 , small : true ),
35+ new Service (name : ' Disputes' , spec : ' DisputeService' , version : 30 , small : true ),
36+ // Webhooks
37+ new Service (name : ' ConfigurationWebhooks' , spec : ' BalancePlatformConfigurationNotification' , version : 1 ),
38+ new Service (name : ' AcsWebhooks' , spec : ' BalancePlatformAcsNotification' , version : 1 ),
39+ new Service (name : ' ReportWebhooks' , spec : ' BalancePlatformReportNotification' , version : 1 ),
40+ new Service (name : ' TransferWebhooks' , spec : ' BalancePlatformTransferNotification' , version : 4 ),
41+ new Service (name : ' TransactionWebhooks' , spec : ' BalancePlatformTransactionNotification' , version : 4 ),
42+ new Service (name : ' ManagementWebhooks' , spec : ' ManagementNotificationService' , version : 3 ),
43+ ]
44+
845ext {
946 generator = project. name
1047 templates = ' templates'
11- services = [
12- // Payments
13- new Service (name : ' Checkout' , version : 71 ),
14- new Service (name : ' Payout' , version : 68 ),
15- new Service (name : ' Recurring' , version : 68 ),
16- new Service (name : ' BinLookup' , version : 54 ),
17- // Point of Sale
18- new Service (name : ' POSTerminalManagement' , spec : ' TfmAPIService' , version : 1 ),
19- // Management
20- new Service (name : ' Management' , version : 3 ),
21- new Service (name : ' BalanceControl' , version : 1 ),
22- // Adyen for Platforms
23- new Service (name : ' LegalEntityManagement' , spec : ' LegalEntityService' , version : 3 ),
24- new Service (name : ' BalancePlatform' , version : 2 ),
25- new Service (name : ' Transfers' , spec : ' TransferService' , version : 4 ),
26- new Service (name : ' DataProtection' , version : 1 ),
27- // Classic Payments
28- new Service (name : ' Payment' , version : 68 ),
29- // Others
30- new Service (name : ' StoredValue' , version : 46 ),
31- // Webhooks
32- new Service (name : ' ConfigurationWebhook' , spec : ' BalancePlatformConfigurationNotification' , version : 1 ),
33- new Service (name : ' ACSWebhook' , spec : ' BalancePlatformAcsNotification' , version : 1 ),
34- new Service (name : ' ReportWebhook' , spec : ' BalancePlatformReportNotification' , version : 1 ),
35- new Service (name : ' TransferWebhook' , spec : ' BalancePlatformTransferNotification' , version : 4 ),
36- new Service (name : ' TransactionWebhook' , spec : ' BalancePlatformTransactionNotification' , version : 4 ),
37- new Service (name : ' ManagementWebhook' , spec : ' ManagementNotificationService' , version : 3 ),
38- ]
3948 serviceName = ' '
40- }
41-
42- class Service {
43- String name, spec
44- int version
45-
46- String getSpec () { spec ?: " ${ name} Service" }
47-
48- String getId () { name. toLowerCase() }
49+ removeTags = true
50+ setProperty(' services' , services)
51+ smallServices = services. findAll { it. small }
52+ serviceNaming = services. collectEntries { [it. id, it. name] }
53+ serviceNamingCamel = services. collectEntries {
54+ [it. id, it. name. substring(0 , 1 ). toLowerCase() + it. name. substring(1 )]
55+ }
4956}
5057
5158// Generate a full client for each service
52- project . ext . services. each { Service svc ->
59+ services. each { Service svc ->
5360 def generate = tasks. register(" generate$svc . name " , GenerateTask ) {
61+ group ' generate'
5462 description " Generate a $project . name client for $svc . name . "
55- dependsOn ' clone '
63+ dependsOn ' cloneRepo '
5664 dependsOn ' :specs'
5765
5866 // Current service being processed
67+ ext. serviceId = svc. id
5968 project. ext. serviceName = svc. name
6069
6170 generatorName. set(project. ext. generator as String )
62- inputSpec. set(" $rootDir /schema/json/${ svc.spec } -v ${ svc.version } .json " )
71+ inputSpec. set(" $rootDir /schema/json/${ svc.filename } " )
6372 outputDir. set(" $buildDir /services/${ svc.id} " )
6473 templateDir. set(" $projectDir /repo/$project . ext . templates " )
74+ engine. set(' mustache' )
6575 validateSpec. set(false )
6676 skipValidateSpec. set(true )
6777 reservedWordsMappings. set([
@@ -70,31 +80,41 @@ project.ext.services.each { Service svc ->
7080 additionalProperties. set([
7181 ' serviceName' : project. ext. serviceName,
7282 ])
83+ globalProperties. set([
84+ ' modelDocs' : ' false' ,
85+ ' modelTests' : ' false'
86+ ])
7387
7488 if (project. ext. has(' configFile' )) {
7589 configFile. set(" $projectDir /repo/$project . ext . configFile " )
7690 }
7791 }
7892
7993 tasks. register(svc. id) {
94+ group ' service'
8095 description " Base task for $svc . name . "
8196 dependsOn generate
8297 }
8398}
8499
85100tasks. register(' services' ) {
86101 description ' Generate code for multiple services.'
87- dependsOn project . ext . services. collect { it. id }
102+ dependsOn services. collect { it. id }
88103}
89104
90105tasks. named(' generateCheckout' , GenerateTask ) {
106+ if (project. name == ' node' ) {
107+ // generator v5 does not support inlineSchemaNameMappings
108+ return
109+ }
91110 inlineSchemaNameMappings. set([
92111 ' PaymentRequest_paymentMethod' : ' CheckoutPaymentMethod' ,
93112 ' DonationPaymentRequest_paymentMethod' : ' DonationPaymentMethod' ,
94113 ])
95114}
96115
97- tasks. register(' clone' , Exec ) {
116+ tasks. register(' cloneRepo' , Exec ) {
117+ group ' setup'
98118 def uri = " https://github.com/Adyen/adyen-$project . name -api-library.git"
99119 def dest = ' repo'
100120 description " Clone this project's repository."
@@ -109,13 +129,51 @@ tasks.withType(GenerateTask).configureEach {
109129 outputs. cacheIf { false }
110130}
111131
112- tasks. register(' clean' , Delete ) {
113- delete buildDir
132+ tasks. register(' cleanRepo' , Delete ) {
133+ group ' clean'
134+ description ' Clean this project state'
135+ delete layout. buildDirectory
136+ doLast {
137+ exec {
138+ // cleanTracked: discard changes to existing files
139+ commandLine ' git' , ' checkout' , ' .'
140+ workingDir ' repo'
141+ }
142+ exec {
143+ // cleanUntracked: discard unknown files
144+ commandLine ' git' , ' clean' , ' -f' , ' -d'
145+ workingDir ' repo'
146+ }
147+ }
114148}
115149
116150tasks. register(' addPMTable' , Copy ) {
117- dependsOn(" clone " )
151+ dependsOn(" cloneRepo " )
118152 dependsOn(" :pmTable" )
119153 from(rootProject. file(' PaymentMethodOverview.md' ))
120154 into layout. projectDirectory. dir(" repo" )
121- }
155+ }
156+
157+ project. ext. smallServices. each { Service svc ->
158+ def ungroup = tasks. register(" ungroup${ svc.name} " ) {
159+ group ' specs'
160+ description " Remove tags from ${ svc.name} "
161+ dependsOn ' :specs'
162+ // The `removeTags` setting only works in isolation (e.g. CI). Locally, specs are shared between all projects.
163+ onlyIf { project. ext. removeTags }
164+ doLast {
165+ def specFile = file(" $rootDir /schema/json/${ svc.filename} " )
166+ def json = new JsonSlurper (). parse(specFile)
167+
168+ json[" paths" ]. each { Map.Entry endpoint ->
169+ endpoint. value. each { Map.Entry httpMethod ->
170+ httpMethod. value. remove(' tags' )
171+ }
172+ }
173+
174+ specFile. text = JsonOutput . prettyPrint(JsonOutput . toJson(json))
175+ }
176+ }
177+
178+ tasks. named(" generate$svc . name " ) { dependsOn ungroup }
179+ }
0 commit comments