-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
68 lines (64 loc) · 2.47 KB
/
build.gradle.kts
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
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
import com.genestack.openapi.MergeDefinitions
import kotlin.io.path.listDirectoryEntries
import kotlin.io.path.name
import kotlin.io.path.Path as KotlinPath
plugins {
alias(libs.plugins.openapi.generator) apply true
}
val openApiVersion: String = System.getenv("OPENAPI_VERSION") ?: "1.0.0"
val sourceDirectory = "$rootDir/openapi/v1"
val fileNameList = KotlinPath(sourceDirectory)
.listDirectoryEntries("*.yaml")
.sorted()
val mergedFileName = "odmApi.yaml"
val sourceFileList = fileNameList.map {
layout.projectDirectory.file("${sourceDirectory}/${it.name}")
}
tasks {
register("generateOdmApiPython", GenerateTask::class) {
generatorName.set("python")
inputSpec.set("${sourceDirectory}/odmApi.yaml")
outputDir.set("$rootDir/generated/python")
packageName.set("odm_api")
gitUserId.set("genestack")
gitRepoId.set("openapi")
configOptions = mapOf(
"packageVersion" to openApiVersion
// "disallowAdditionalPropertiesIfNotPresent" to "true"
)
}
register("generateOdmApiR", GenerateTask::class) {
generatorName.set("r")
inputSpec.set("${sourceDirectory}/odmApi.yaml")
outputDir.set("$rootDir/generated/r")
packageName.set("odmApi")
gitUserId.set("genestack")
gitRepoId.set("openapi")
configOptions = mapOf(
"packageVersion" to openApiVersion
// "disallowAdditionalPropertiesIfNotPresent" to "true"
)
}
register("generateOdmApiPostmanCollection", GenerateTask::class) {
generatorName.set("postman-collection")
inputSpec.set("${sourceDirectory}/odmApi.yaml")
outputDir.set("$rootDir/generated/postman-collection")
packageName.set("odm-api")
gitUserId.set("genestack")
gitRepoId.set("openapi")
configOptions = mapOf(
"packageVersion" to openApiVersion
// "disallowAdditionalPropertiesIfNotPresent" to "true"
)
}
// Should be used in pre-commit
register("mergeDefinitions", MergeDefinitions::class) {
inputFiles = sourceFileList
outputFile = layout.projectDirectory.file("${sourceDirectory}/${mergedFileName}")
}
val generateAll by registering(GradleBuild::class) {
file("$rootDir/generated").deleteRecursively()
tasks = listOf("generateOdmApiPython", "generateOdmApiR", "generateOdmApiPostmanCollection")
}
}