forked from Adyen/adyen-sdk-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
84 lines (76 loc) · 2.96 KB
/
build.gradle
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
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
def uri = "https://github.com/Adyen/adyen-openapi.git"
def specsDir = "$projectDir/schema"
def checkoutDir = "$projectDir/schema/json/CheckoutService-v71.json"
tasks.register('specs', Exec) {
group 'setup'
description 'Clone OpenAPI spec (and apply local patches).'
commandLine 'git', 'clone', '--depth', '1', uri, specsDir
outputs.dir specsDir
onlyIf { !file(specsDir).exists() }
doLast {
File folder = new File("$specsDir/json");
assert folder.exists()
assert folder.isDirectory()
assert folder.list().length > 0: "Folder cannot be empty after clone"
file(folder).eachFile { specFile ->
if (specFile.name.endsWith('.json')) {
def json = new JsonSlurper().parseText(specFile.text)
// Modify the 'openapi' field
json.openapi = '3.0.0'
json["paths"].each { Map.Entry endpoint ->
endpoint.value.each { Map.Entry httpMethod ->
// overwrite operationId
httpMethod.value["operationId"] = httpMethod.value["x-methodName"]
}
}
// Overwrite the file with updated content
specFile.text = JsonOutput.prettyPrint(JsonOutput.toJson(json))
}
}
}
}
tasks.register('pmTable', Task) {
group 'specs'
description 'Generate Checkout Payment Method Table'
dependsOn('specs')
onlyIf { file(checkoutDir).exists() }
File folder = new File(checkoutDir);
doLast {
def json = new JsonSlurper().parseText(file(folder).text)
def base = json.components.schemas
def pmList = new HashMap<String, ArrayList<String>>()
// find list of PaymentMethod Classes
base.'PaymentRequest'.'properties'.'paymentMethod'.'oneOf'.each {
pmClass -> pmList.put(pmClass.'$ref'.replace('#/components/schemas/', ''), new ArrayList())
}
// populate available tx variants per PaymentMethodDetailsClass
pmList.each {
entry ->
def keyString = entry.getKey()
base."$keyString".'properties'.'type'.'enum'.each {
pm -> entry.getValue().add(pm)
}
}
outputs.println(pmList)
// Output the list into a .md file
def pmFile = new File("$projectDir/PaymentMethodOverview.md")
new FileWriter(pmFile).with {
write("# PaymentMethod Overview For Checkout\n" +
"| Java Class | tx_variants |\n" +
"|---------------|---------------|\n")
pmList.each {
entry ->
write("|$entry.key|$entry.value|\n")
}
flush()
}
pmFile.createNewFile()
}
}
tasks.register('cleanSpecs', Delete) {
group 'clean'
description 'Delete OpenAPI specifications'
delete specsDir
}