On a route scoped plugin… is there any way to acce...
# ktor
r
On a route scoped plugin… is there any way to access the full path of the route it is being installed on?
a
Could you please describe your use case?
r
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
@Rustam Siniukov
r
you can cast
pipeline
to route and iterate through its parents to get the full route
👀 1
r
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
Sorry, my bad,
pipeline
is internal inside
PluginBuilder
. As a workaround you can create a hook to expose the pipeline
Copy code
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
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
if we collect more use cases for this, we can provide better API
r
fair enough, thank you 👍