https://kotlinlang.org logo
Title
r

Ryan Brink

05/07/2022, 2:52 PM
On a route scoped plugin… is there any way to access the full path of the route it is being installed on?
a

Aleksei Tirman [JB]

05/08/2022, 8:43 AM
Could you please describe your use case?
r

Ryan Brink

05/08/2022, 1:45 PM
For building an openapi generator, I want the route plug-in to be able to see the full path so it knows where to store the route metadata in the generated spec
a

Aleksei Tirman [JB]

05/09/2022, 7:04 AM
@Rustam Siniukov
r

Rustam Siniukov

05/09/2022, 12:51 PM
you can cast
pipeline
to route and iterate through its parents to get the full route
👀 1
r

Ryan Brink

05/20/2022, 12:54 AM
apologies for the really late reply here, I’m just getting to picking this up again… I’m a bit confused… where is the pipeline accessible from? With the new plugin syntax
createRouteScopedPlugin()
I’m not sure where I’m finding this pipeline. Would I need to wait until an application event trigger to do this? Because at the moment I am able to handle everything in the PluginBuilder context, and would prefer to not have to monitor for some API event before constructing the path (if possible)
r

Rustam Siniukov

05/20/2022, 12:07 PM
Sorry, my bad,
pipeline
is internal inside
PluginBuilder
. As a workaround you can create a hook to expose the pipeline
private object InstallHook : Hook<(ApplicationCallPipeline) -> Unit> {
    override fun install(pipeline: ApplicationCallPipeline, handler: (ApplicationCallPipeline) -> Unit) {
        handler(pipeline)   
    }
}
public val plugin = createRouteScopedPlugin("MyPlugin") {
    on(InstallHook) {
        val route = it as? Route ?: return@on
    }
}
r

Ryan Brink

05/20/2022, 3:42 PM
interesting, I will give this a go, thank you! out of curiosity… are there plans to streamline this in future releases? this feels a bit hacky
r

Rustam Siniukov

05/20/2022, 3:46 PM
if we collect more use cases for this, we can provide better API
r

Ryan Brink

05/20/2022, 3:49 PM
fair enough, thank you 👍