Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion rest-api-json-bulk/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
plugins {
application
kotlin("jvm")
id("org.openapi.generator") version "6.2.1"
}

val ktor_version : String by project
val json_bulk_access_version: String by project
val api_gen_version: String by project

val openApiFile = layout.projectDirectory.file("../openapi/openapi.yaml")

dependencies {
implementation(project(":mps:solutions:University.Schedule.api"))

Expand All @@ -26,6 +29,42 @@ dependencies {
implementation("org.modelix.mps.api-gen:runtime:$api_gen_version")
}

val basePackage = "org.modelix.sample.restapijsonbulk"

// Use the OpenAPI generator to generate data classes representing the REST response data types.
// Unfortunately, other generated artifacts cannot be used, because the generator still assumes
// ktor 1.x and doesn't have an interfaceOnly mode such as in the Quarkus example.
openApiGenerate {
generatorName.set("kotlin-server")
inputSpec.set(openApiFile.toString())
outputDir.set("$buildDir/openapi-generator")
packageName.set(basePackage)
// The OpenAPI generator gradle plugin is strange. According to the documentation of the generator itself,
// one has to specify `true` to generate all models. However, the plugin does something such that `true`
// is assumed to be the name of a specific model to generate only then. Strangely, specifying an empty
// string configures the plugin in such a way that all available models are generated and nothing else.
globalProperties.set(
mapOf(
"models" to "",
)
)
configOptions.set(
mapOf(
"library" to "ktor",
)
)
}

// Ensure that the OpenAPI generator runs before starting to compile
tasks.named("processResources") {
dependsOn("openApiGenerate")
}
tasks.named("compileKotlin") {
dependsOn("openApiGenerate")
}

java.sourceSets.getByName("main").java.srcDir(file("$buildDir/openapi-generator/src/main/kotlin"))

application {
mainClass.set("org.modelix.sample.restapijsonbulk.ApplicationKt")
}
}
29 changes: 0 additions & 29 deletions rest-api-json-bulk/src/main/kotlin/models/Lecture.kt

This file was deleted.

21 changes: 0 additions & 21 deletions rest-api-json-bulk/src/main/kotlin/models/LectureList.kt

This file was deleted.

27 changes: 0 additions & 27 deletions rest-api-json-bulk/src/main/kotlin/models/Room.kt

This file was deleted.

21 changes: 0 additions & 21 deletions rest-api-json-bulk/src/main/kotlin/models/RoomList.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
/**
* University.Schedule.api
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.modelix.sample.restapijsonbulk.models.apis

import University.Schedule.structure.Courses
import University.Schedule.structure.Rooms
import com.google.gson.Gson
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.locations.*
Expand Down Expand Up @@ -44,9 +32,6 @@ object RouteHelper {
}

fun Route.BulkApi(loadRoots: suspend () -> List<INode>, resolve: suspend (INodeReference) -> INode?) {
val gson = Gson()
val empty = mutableMapOf<String, Any?>()

get<Paths.getLectures> {
val roots = loadRoots()
val allLectures = roots.flatMap {
Expand Down Expand Up @@ -111,4 +96,4 @@ fun Route.BulkApi(loadRoots: suspend () -> List<INode>, resolve: suspend (INodeR
call.respond(HttpStatusCode.NotFound, "Can not load Room: " + e.message)
}
}
}
}