papsign / Ktor-OpenAPI-Generator

Ktor OpenAPI/Swagger 3 Generator
Apache License 2.0
243 stars 42 forks source link

Correct way to do subrouting? #102

Closed choffa closed 2 years ago

choffa commented 3 years ago

What would be the correct way of doing subrouting with typed parameters?

I am trying to do something similar to this example in the Locations-plugin documentation:

@Location("/type/{name}") data class Type(val name: String) {
    // In these classes we have to include the `name` property matching the parent.
    @Location("/edit") data class Edit(val parent: Type)
    @Location("/list/{page}") data class List(val parent: Type, val page: Int)
}

I assumed from the wiki-page "Basic Routing" that @Path would do the trick. However, the compiler complains that the parent parameter must be annotated with @PathParam or @QueryParam. Is there something I am missing or will I just have to repeat the full URI for all "subroutes"?

Wicpar commented 3 years ago

Indeed it does not work like that, but you can use .route("path") in the dsl. Any further @Path annotations will be appended