Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODELIX-646 Use resource based routing in model-server #353

Merged
merged 19 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b4e396b
feat(model-server): migrate to resource based routing based on OpenAP…
nkoester Dec 1, 2023
e1959f1
feat(model-server): deduplicate openapi responses
nkoester Dec 5, 2023
11985e3
feat(model-server): add known specific operationIds
nkoester Dec 5, 2023
eefe8a1
chore(model-server): remove commented legacy code
nkoester Dec 5, 2023
33a2617
feat(model-server): use openapi resources in KeyValueLikeModelServer
nkoester Dec 5, 2023
8a71831
feat(model-server): split openAPI spec into multiple files
nkoester Dec 7, 2023
9a095d7
feat(model-server): generate openAPI task per file
nkoester Dec 7, 2023
672d329
feat(model-server): use resource based paths in all model-server endp…
nkoester Dec 7, 2023
e2c182d
fix(light-model-client): use resource ktor plugin in tests
nkoester Dec 8, 2023
9764c5b
fix(model-server): use correct resource for posting contentVersionHash
nkoester Dec 8, 2023
770fdfa
chore(model-server): use 'to' notation for pairs
nkoester Dec 8, 2023
c640a37
build: add dedicated openapi module
nkoester Dec 11, 2023
4768158
chore(openapi): remove empty descriptions
nkoester Dec 11, 2023
cf389fa
build: small fixes and documentation
nkoester Dec 11, 2023
f949cdc
feat(openapi): provide swagger ui of `model-server.yaml` at endpoint …
nkoester Dec 11, 2023
b1855bd
chore(openapi): use dedicated `operationId`s wherever possible
nkoester Dec 11, 2023
fab8809
chore(openapi): document serving of public api only
nkoester Dec 12, 2023
2db8b16
Merge remote-tracking branch 'origin/main' into feature/resource-base…
nkoester Jan 9, 2024
7934127
chore(openapi): add new objects endpoint
nkoester Jan 9, 2024
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
1,365 changes: 1,365 additions & 0 deletions api/public.yaml
odzhychko marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ dokka = {id = "org.jetbrains.dokka", version = "1.9.10"}
node = {id = "com.github.node-gradle.node", version = "7.0.1"}
detekt = { id = "io.gitlab.arturbosch.detekt", version = "1.23.4" }
npm-publish = { id = "dev.petuska.npm.publish", version = "3.4.1" }
openapi-generator = {id = "org.openapi.generator", version.ref = "openapi"}
#kotlin-plugin-allopen = { id = "org.jetbrains.kotlin.plugin.allopen", version.ref = "kotlin" }

[versions]
kotlin = "1.9.21"
Expand All @@ -30,6 +32,7 @@ ignite="2.15.0"
apacheCxf="3.6.2"
node="18.17.1"
modelixBuildtools="1.2.0"
openapi = "7.0.1"

[libraries]

Expand Down Expand Up @@ -57,6 +60,7 @@ ktor-server-sessions = { group = "io.ktor", name = "ktor-server-sessions", versi
ktor-server-status-pages = { group = "io.ktor", name = "ktor-server-status-pages", version.ref = "ktor" }
ktor-server-test-host = { group = "io.ktor", name = "ktor-server-test-host", version.ref = "ktor" }
ktor-server-websockets = { group = "io.ktor", name = "ktor-server-websockets", version.ref = "ktor" }
ktor-server-resources = { group = "io.ktor", name = "ktor-server-resources", version.ref = "ktor" }

ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktor" }
ktor-client-content-negotiation = { group = "io.ktor", name = "ktor-client-content-negotiation", version.ref = "ktor" }
Expand Down
84 changes: 84 additions & 0 deletions model-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ plugins {
id("org.jetbrains.kotlin.jvm")
id("com.github.johnrengelman.shadow") version "8.1.1"
kotlin("plugin.serialization")
alias(libs.plugins.openapi.generator)
// alias(libs.plugins.kotlin.plugin.allopen)
}

description = "Model Server offering access to model storage"
Expand Down Expand Up @@ -48,6 +50,7 @@ dependencies {
implementation(libs.ktor.server.forwarded.header)
implementation(libs.ktor.server.websockets)
implementation(libs.ktor.server.content.negotiation)
implementation(libs.ktor.server.resources)
implementation(libs.ktor.serialization.json)

implementation(libs.bundles.ignite)
Expand All @@ -64,6 +67,9 @@ dependencies {
testImplementation(libs.ktor.server.test.host)
testImplementation(kotlin("test"))
testImplementation(project(":modelql-untyped"))

// implementation("jakarta.ws.rs:jakarta.ws.rs-api:2.1.6")
// implementation("jakarta.annotation:jakarta.annotation-api:1.3.5")
}

tasks.test {
Expand Down Expand Up @@ -184,3 +190,81 @@ spotless {
'\n'*/
}
}

// OpenAPI integration
val basePackage = project.group.toString()
val openAPIgenerationPath = "$buildDir/generated/openapi"
nkoester marked this conversation as resolved.
Show resolved Hide resolved

// We let the Gradle OpenAPI generator plugin build data classes and API interfaces based on the provided
// OpenAPI specification. That way, the code is forced to stay in sync with the API specification.
openApiGenerate {
generatorName.set("kotlin-server")
inputSpec.set(layout.projectDirectory.file("../api/public.yaml").toString())
outputDir.set(openAPIgenerationPath)
packageName.set(basePackage)
packageName.set(basePackage)
apiPackage.set(basePackage)
modelPackage.set(basePackage)
// WARNING: there are patched mustache files used!
templateDir.set("$projectDir/src/main/resources/openapi/templates")
configOptions.set(
mapOf(
"library" to "ktor",
"omitGradleWrapper" to "true",
"featureResources" to "true",
"featureAutoHead" to "false",
"featureCompression" to "false",
"featureHSTS" to "false",
"featureMetrics" to "false",
),
)
globalProperties.putAll(
mapOf(
// "debugOpenAPI" to "true",
// "debugModels" to "true",
// "debugSupportingFiles" to "true",
// "debugOperations" to "true",

// "models" to "",
// "apis" to "",
// "supportingFiles" to "",
// "apiTests" to "false",
// "modelTests" to "false",
// "modelDocs" to "false",
),
)
}

// Ensure that the OpenAPI generator runs before starting to compile
tasks.named("build") {
dependsOn("openApiGenerate")
}
tasks.named("processResources") {
dependsOn("openApiGenerate")
}
tasks.named("compileKotlin") {
dependsOn("openApiGenerate")
}
tasks.named("runKtlintCheckOverMainSourceSet") {
dependsOn("openApiGenerate")
}
languitar marked this conversation as resolved.
Show resolved Hide resolved

// do not apply ktlint on the generated files
ktlint {
filter {
exclude {
it.file.toPath().toAbsolutePath().startsWith(openAPIgenerationPath)
}
// exclude("$openAPIgenerationPath/src/main/kotlin/**")
// exclude("$openAPIgenerationPath/**")
// exclude("**/generated/**")
}
}

// allOpen {
// annotation("javax.ws.rs.Path")
// annotation("javax.enterprise.context.ApplicationScoped")
// }

// add openAPI generated artifacts to the sourceSets
java.sourceSets.getByName("main").java.srcDir(file("$openAPIgenerationPath/src/main/kotlin"))
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import io.ktor.server.netty.NettyApplicationEngine
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
import io.ktor.server.plugins.cors.routing.CORS
import io.ktor.server.plugins.forwardedheaders.ForwardedHeaders
import io.ktor.server.resources.Resources
import io.ktor.server.response.respondText
import io.ktor.server.routing.IgnoreTrailingSlash
import io.ktor.server.routing.Routing
import io.ktor.server.routing.get
import io.ktor.server.routing.routing
Expand Down Expand Up @@ -159,6 +161,8 @@ object Main {
install(Routing)
installAuthentication(unitTestMode = !KeycloakUtils.isEnabled())
install(ForwardedHeaders)
install(Resources)
install(IgnoreTrailingSlash)
odzhychko marked this conversation as resolved.
Show resolved Hide resolved
install(WebSockets) {
pingPeriod = Duration.ofSeconds(30)
timeout = Duration.ofSeconds(30)
Expand Down
Loading
Loading