Skip to content

Commit

Permalink
fix classloading error
Browse files Browse the repository at this point in the history
  • Loading branch information
darkxanter committed Oct 31, 2024
1 parent 9879ff4 commit f17efc4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
9 changes: 7 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import pl.allegro.tech.build.axion.release.domain.properties.TagProperties
import pl.allegro.tech.build.axion.release.domain.scm.ScmPosition
import java.net.URL
Expand Down Expand Up @@ -74,10 +75,14 @@ java {

tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
}
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
}
}

test {
Expand Down
19 changes: 13 additions & 6 deletions src/main/kotlin/com/papsign/ktor/openapigen/OpenAPIGen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,26 @@ import io.ktor.server.response.respond
import io.ktor.server.response.respondRedirect
import io.ktor.util.AttributeKey
import org.reflections.Reflections
import org.reflections.util.ConfigurationBuilder
import kotlin.reflect.full.starProjectedType

class OpenAPIGen(
config: Configuration,
@Deprecated("Will be replaced with less dangerous alternative when the use case has been fleshed out.") val pipeline: ApplicationCallPipeline
@Deprecated("Will be replaced with less dangerous alternative when the use case has been fleshed out.") val pipeline: ApplicationCallPipeline,
) {
private val log = classLogger()

val api = config.api

private val tags = HashMap<String, APITag>()

val api = config.api
val globalModuleProvider = CachingModuleProvider()

init {
(config.scanPackagesForModules + javaClass.`package`.name).forEach { packageName ->
val reflections = Reflections(packageName)
val reflections = Reflections(
ConfigurationBuilder()
.forPackages(packageName)
.addClassLoaders(OpenAPIGen::class.java.classLoader)
)
log.debug("Registering modules in package $packageName")
val objects = reflections.getSubTypesOf(OpenAPIGenExtension::class.java).mapNotNull { it.kotlin.objectInstance }
objects.forEach {
Expand Down Expand Up @@ -120,7 +123,11 @@ class OpenAPIGen(
}

if (cfg.serveSwaggerUi) {
val ui = SwaggerUi(cfg.swaggerUiPath, cfg.swaggerUiVersion, if (cfg.serveOpenApiJson) cfg.openApiJsonPath else null)
val ui = SwaggerUi(
cfg.swaggerUiPath,
cfg.swaggerUiVersion,
if (cfg.serveOpenApiJson) cfg.openApiJsonPath else null
)
val swaggerRoot = "/${cfg.swaggerUiPath.removePrefix("/")}"
val swaggerUiResources = "/${cfg.swaggerUiPath.trim('/')}/"
pipeline.intercept(ApplicationCallPipeline.Call) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/TestServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ object TestServer {
email = "[email protected]"
}
}
server("https://api.test.com/") {
server("http://localhost:8080") {
description = "Main production server"
}
replaceModule(DefaultSchemaNamer, object : SchemaNamer {
Expand Down

0 comments on commit f17efc4

Please sign in to comment.