bkbnio / kompendium

Ktor OpenAPI Spec Generator
https://bkbn.gitbook.io/kompendium
MIT License
153 stars 24 forks source link

Incompatible with Ktor 3.x #644

Closed gavvvr closed 2 weeks ago

gavvvr commented 1 month ago

Hi. Ktor 3.0.0 is out. I'm trying to migrate my apps and faced the problem with Kompendium.

Describe the bug This plugin throws java.lang.NoClassDefFoundError: io/ktor/server/routing/RoutingKt with Ktor 3.x

Here is the complete stacktrace:

Click me ``` Exception in thread "main" java.lang.NoClassDefFoundError: io/ktor/server/routing/RoutingKt at io.bkbn.kompendium.core.plugin.NotarizedApplication$invoke$2.invoke(NotarizedApplication.kt:39) at io.bkbn.kompendium.core.plugin.NotarizedApplication$invoke$2.invoke(NotarizedApplication.kt:34) at io.ktor.server.application.CreatePluginUtilsKt.setupPlugin(CreatePluginUtils.kt:276) at io.ktor.server.application.CreatePluginUtilsKt.createPluginInstance(CreatePluginUtils.kt:245) at io.ktor.server.application.CreatePluginUtilsKt.access$createPluginInstance(CreatePluginUtils.kt:1) at io.ktor.server.application.ApplicationPluginImpl.install(CreatePluginUtils.kt:83) at io.ktor.server.application.ApplicationPluginImpl.install(CreatePluginUtils.kt:71) at io.ktor.server.application.ApplicationPluginKt.install(ApplicationPlugin.kt:100) at example.com.plugins.RoutingKt.configureRouting(Routing.kt:11) at example.com.ApplicationKt.module(Application.kt:11) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.base/java.lang.reflect.Method.invoke(Method.java:580) at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:97) at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Static.call(CallerImpl.kt:106) at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:207) at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:112) at io.ktor.server.engine.internal.CallableUtilsKt.callFunctionWithInjection(CallableUtils.kt:120) at io.ktor.server.engine.internal.CallableUtilsKt.executeModuleFunction(CallableUtils.kt:36) at io.ktor.server.engine.EmbeddedServer.launchModuleByName$lambda$26(EmbeddedServerJvm.kt:354) at io.ktor.server.engine.EmbeddedServer.avoidingDoubleStartupFor(EmbeddedServerJvm.kt:378) at io.ktor.server.engine.EmbeddedServer.launchModuleByName(EmbeddedServerJvm.kt:353) at io.ktor.server.engine.EmbeddedServer.instantiateAndConfigureApplication$lambda$25(EmbeddedServerJvm.kt:334) at io.ktor.server.engine.EmbeddedServer.avoidingDoubleStartup(EmbeddedServerJvm.kt:360) at io.ktor.server.engine.EmbeddedServer.instantiateAndConfigureApplication(EmbeddedServerJvm.kt:332) at io.ktor.server.engine.EmbeddedServer.createApplication(EmbeddedServerJvm.kt:142) at io.ktor.server.engine.EmbeddedServer.start(EmbeddedServerJvm.kt:271) at io.ktor.server.netty.EngineMain.main(EngineMain.kt:25) Caused by: java.lang.ClassNotFoundException: io.ktor.server.routing.RoutingKt at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) ... 27 more ```

To Reproduce Steps to reproduce the behavior:

  1. Generate a new project at https://start.ktor.io/ with "Routing" plugin
  2. Add NotarizedApplication plugin, for example:
fun Application.configureRouting() {
    install(NotarizedApplication()) {
        spec = OpenApiSpec(
            info = Info("Some service API", version = "1.0.0"),
        )
    }
    routing {
        get("/") {
            call.respondText("Hello World!")
        }
    }
}
  1. Run the app with ./gradlew :run and it will fail to start with the above stacktrace.
knmueller commented 1 month ago

I know this is only 5 days old, but any chance this is going to be a priority? I have a ktor app using Resources, and I haven't found anything comparable to how kompendium is used on Resources. I have forked the code and started making some changes, but alot has changed in ktor 3.0.0 and it seems there are some larger changes needed for kompendium to support it (especially when it comes to some of the Routing -> Route changes in ktor).

knmueller commented 1 month ago

Update here -- I was able to make the necessary changes to get this compiling and passing the unittests locally. The changes are a combo of getting it running with Ktor 3.0.0 as well as updating the versions from the other automatic renovate PRs.

I'd be happy to get this up for PR -- I am new to kompendium so would certainly need some feedback. Please let me know.

Side-note: Locations were removed and replaced with Resources in the Ktor update, so my changes also remove NotorizedLocations and anything associated to it (including the locations subproject in this repo.

brizzbuzz commented 1 month ago

nice! ive been very behind on maintaining this repo. There was an issue a while back where the Maven central folks did an upgrade that broke publishing for all of my JVM repos, and that really took the wind out of my sails.

That should be fixed so I will try and find some time in the near future to get this repo ready for Ktor 3.

Please publish your PR I will definitely take a look at it :) will give me a good head start on Ktor 3 integration.

gavvvr commented 1 week ago

Hello. Thanks for the update! Tried to gradually migrate to Kompendium v4.0.1, then to Ktor 3.x, but failed. Looks like I need to do both at once. I think the number 1 item in v4.0.1 changelog should be a note on breaking change about dropping support for Ktor 2.x