Skip to content

Commit cf389fa

Browse files
committed
build: small fixes and documentation
1 parent 4768158 commit cf389fa

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

model-server/build.gradle.kts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ spotless {
190190

191191
// OpenAPI integration
192192
val basePackage = project.group.toString()
193-
val openAPIgenerationPath = "$buildDir/generated/openapi"
193+
val openAPIgenerationPath = "${project.layout.buildDirectory}/generated/openapi"
194194

195195
// Pairs of the different OpenAPI files we use. Each pair must have its own 'category' as first argument as these
196196
// are used to generate corresponding packages
@@ -215,20 +215,28 @@ openApiFiles.forEach {
215215
packageName.set(targetPackageName)
216216
apiPackage.set(targetPackageName)
217217
modelPackage.set(targetPackageName)
218-
// WARNING: there are patched mustache files used!
218+
// We use patched mustache so that only the necessary parts (i.e. resources and models)
219+
// are generated. additionally we patch the used serialization framework as the `ktor` plugin
220+
// uses a different one than we do in the model-server. The templates are based on
221+
// https://github.com/OpenAPITools/openapi-generator/tree/809b3331a95b3c3b7bcf025d16ae09dc0682cd69/modules/openapi-generator/src/main/resources/kotlin-server
219222
templateDir.set("$projectDir/src/main/resources/openapi/templates")
220223
configOptions.set(
221224
mapOf(
225+
// we use the ktor generator to generate server side resources and model (i.e. data classes)
222226
"library" to "ktor",
227+
// the generated artifacts are not built independently, thus no dedicated build files have to be generated
223228
"omitGradleWrapper" to "true",
229+
// the path to resource generation we need
224230
"featureResources" to "true",
231+
// disable features we do not use
225232
"featureAutoHead" to "false",
226233
"featureCompression" to "false",
227234
"featureHSTS" to "false",
228235
"featureMetrics" to "false",
229236
),
230237
)
231-
// generate only Paths and Models
238+
// generate only Paths and Models - only this set will produce the intended Paths.kt as well as the models
239+
// the openapi generator is generally very picky and configuring it is rather complex
232240
globalProperties.putAll(
233241
mapOf(
234242
"models" to "",
@@ -259,5 +267,5 @@ openApiFiles.forEach {
259267
}
260268

261269
// add openAPI generated artifacts to the sourceSets
262-
java.sourceSets.getByName("main").java.srcDir(file("$outputPath/src/main/kotlin"))
270+
sourceSets["main"].kotlin.srcDir("$outputPath/src/main/kotlin")
263271
}

0 commit comments

Comments
 (0)