@@ -9,6 +9,8 @@ plugins {
9
9
id(" org.jetbrains.kotlin.jvm" )
10
10
id(" com.github.johnrengelman.shadow" ) version " 8.1.1"
11
11
kotlin(" plugin.serialization" )
12
+ alias(libs.plugins.openapi.generator)
13
+ // alias(libs.plugins.kotlin.plugin.allopen)
12
14
}
13
15
14
16
description = " Model Server offering access to model storage"
@@ -48,6 +50,7 @@ dependencies {
48
50
implementation(libs.ktor.server.forwarded.header)
49
51
implementation(libs.ktor.server.websockets)
50
52
implementation(libs.ktor.server.content.negotiation)
53
+ implementation(libs.ktor.server.resources)
51
54
implementation(libs.ktor.serialization.json)
52
55
53
56
implementation(libs.bundles.ignite)
@@ -64,6 +67,9 @@ dependencies {
64
67
testImplementation(libs.ktor.server.test.host)
65
68
testImplementation(kotlin(" test" ))
66
69
testImplementation(project(" :modelql-untyped" ))
70
+
71
+ // implementation("jakarta.ws.rs:jakarta.ws.rs-api:2.1.6")
72
+ // implementation("jakarta.annotation:jakarta.annotation-api:1.3.5")
67
73
}
68
74
69
75
tasks.test {
@@ -184,3 +190,81 @@ spotless {
184
190
'\n'*/
185
191
}
186
192
}
193
+
194
+ // OpenAPI integration
195
+ val basePackage = project.group.toString()
196
+ val openAPIgenerationPath = " $buildDir /generated/openapi"
197
+
198
+ // We let the Gradle OpenAPI generator plugin build data classes and API interfaces based on the provided
199
+ // OpenAPI specification. That way, the code is forced to stay in sync with the API specification.
200
+ openApiGenerate {
201
+ generatorName.set(" kotlin-server" )
202
+ inputSpec.set(layout.projectDirectory.file(" ../api/public.yaml" ).toString())
203
+ outputDir.set(openAPIgenerationPath)
204
+ packageName.set(basePackage)
205
+ packageName.set(basePackage)
206
+ apiPackage.set(basePackage)
207
+ modelPackage.set(basePackage)
208
+ // WARNING: there are patched mustache files used!
209
+ templateDir.set(" $projectDir /src/main/resources/openapi/templates" )
210
+ configOptions.set(
211
+ mapOf (
212
+ " library" to " ktor" ,
213
+ " omitGradleWrapper" to " true" ,
214
+ " featureResources" to " true" ,
215
+ " featureAutoHead" to " false" ,
216
+ " featureCompression" to " false" ,
217
+ " featureHSTS" to " false" ,
218
+ " featureMetrics" to " false" ,
219
+ ),
220
+ )
221
+ globalProperties.putAll(
222
+ mapOf (
223
+ // "debugOpenAPI" to "true",
224
+ // "debugModels" to "true",
225
+ // "debugSupportingFiles" to "true",
226
+ // "debugOperations" to "true",
227
+
228
+ // "models" to "",
229
+ // "apis" to "",
230
+ // "supportingFiles" to "",
231
+ // "apiTests" to "false",
232
+ // "modelTests" to "false",
233
+ // "modelDocs" to "false",
234
+ ),
235
+ )
236
+ }
237
+
238
+ // Ensure that the OpenAPI generator runs before starting to compile
239
+ tasks.named(" build" ) {
240
+ dependsOn(" openApiGenerate" )
241
+ }
242
+ tasks.named(" processResources" ) {
243
+ dependsOn(" openApiGenerate" )
244
+ }
245
+ tasks.named(" compileKotlin" ) {
246
+ dependsOn(" openApiGenerate" )
247
+ }
248
+ tasks.named(" runKtlintCheckOverMainSourceSet" ) {
249
+ dependsOn(" openApiGenerate" )
250
+ }
251
+
252
+ // do not apply ktlint on the generated files
253
+ ktlint {
254
+ filter {
255
+ exclude {
256
+ it.file.toPath().toAbsolutePath().startsWith(openAPIgenerationPath)
257
+ }
258
+ // exclude("$openAPIgenerationPath/src/main/kotlin/**")
259
+ // exclude("$openAPIgenerationPath/**")
260
+ // exclude("**/generated/**")
261
+ }
262
+ }
263
+
264
+ // allOpen {
265
+ // annotation("javax.ws.rs.Path")
266
+ // annotation("javax.enterprise.context.ApplicationScoped")
267
+ // }
268
+
269
+ // add openAPI generated artifacts to the sourceSets
270
+ java.sourceSets.getByName(" main" ).java.srcDir(file(" $openAPIgenerationPath /src/main/kotlin" ))
0 commit comments