-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
83 lines (75 loc) · 2.59 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
plugins {
kotlin("multiplatform")
id("org.openapi.generator")
kotlin("plugin.serialization")
}
kotlin {
jvm { }
linuxX64 { }
macosX64 { }
macosArm64 { }
sourceSets {
val serializationVersion: String by project
val commonMain by getting {
kotlin.srcDirs("$buildDir/generate-resources/main/src/commonMain/kotlin")
dependencies {
implementation(kotlin("stdlib-common"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit"))
}
}
}
}
/**
* Настраиваем генерацию здесь
*/
openApiGenerate {
val openapiGroup = "${rootProject.group}.api.v2"
generatorName.set("kotlin") // Это и есть активный генератор
packageName.set(openapiGroup)
apiPackage.set("$openapiGroup.api")
modelPackage.set("$openapiGroup.models")
invokerPackage.set("$openapiGroup.invoker")
inputSpec.set("$rootDir/specs/specs-ad-v2.yaml")
library.set("multiplatform")
/**
* Здесь указываем, что нам нужны только модели, все остальное не нужно
*/
globalProperties.apply {
put("models", "")
put("modelDocs", "false")
}
/**
* Настройка дополнительных параметров из документации по генератору
* https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/kotlin.md
*/
configOptions.set(
mapOf(
"dateLibrary" to "string",
"enumPropertyNaming" to "UPPERCASE",
"collectionType" to "list",
)
)
}
tasks {
val openApiGenerateTask: GenerateTask = getByName("openApiGenerate", GenerateTask::class) {
outputDir.set("$buildDir/generate-resources/main/src/commonMain/kotlin")
mustRunAfter("compileCommonMainKotlinMetadata")
}
filter { it.name.startsWith("compile") }.forEach {
println("TASK attach $it")
it.dependsOn(openApiGenerateTask)
}
}