ktor-swagger icon indicating copy to clipboard operation
ktor-swagger copied to clipboard

Support of Ktor-Routing

Open Dimdron opened this issue 5 years ago • 6 comments

Can I integrate this library to project with Structured Handling of HTTP Requests ?

Dimdron avatar Oct 21 '18 10:10 Dimdron

This Library is ment as Ktor-plugin. But you need to add additional description so the swagger.json can be generated.

nielsfalk avatar Oct 22 '18 10:10 nielsfalk

@nielsfalk : Could you please elaborate on this? What additional description needs to be added?

In the ktor-swagger example, it seems that all routes are "flat" and do not use the routing tree as on the linked page.

Ktor-swagger treats the path on @Location as absolute as opposed to relative to the current nesting in the routing tree. The documentation thus contains paths different from the actual routing structure.

REPLicated avatar Feb 25 '19 08:02 REPLicated

We use the mentioned Structured Handling of HTTP Requests with the RoutingTree intensively. for example:

@Location("/list/{name}")
data class Listing(val name: String, val page: Int, val count: Int)

route("a") { // matches first segment with the value "a"
  route("b") { // matches second segment with the value "b"
    get<Listing> { listing ->
        call.respondText("Listing ${listing.name}, page ${listing.page}")
    }
  }
}

The generated swagger spec should have an api at: /a/b/list/{name} but at the moment only the path from the @Location is considered. The resulting generated spec is /list/{name}.

I do think that most people use structured routing and that this feature is really missing in ktor-swagger and that it should be prioritized.

scic avatar Apr 03 '19 12:04 scic

@scic Currently there is no active development of Ktor-Swagger beyond what contributors add.

The only reason that @nielsfalk's original POC was even updated to turn it into a full-blown library was that I needed this solution for my API at work.

If it's a solution your company really needs, discuss allocating some time to implement it. I'm happy to review PR's that add support for this functionality.

JLLeitschuh avatar Apr 03 '19 14:04 JLLeitschuh

Hi,

I had the same need, and went increasingly frustrated with this library's syntax and maintainability of code so i made Ktor-OpenAPI-Generator. We use it in production at our company without any issues.

Wicpar avatar Dec 03 '19 07:12 Wicpar

@Wicpar Feel free to open a PR to link to your project from our README for others to discover it more easily. I'm all for other solutions to this problem. As I've said, this was simply something I needed for work at a company I'm no longer working for. More than happy to point people in your direction.

JLLeitschuh avatar Dec 04 '19 00:12 JLLeitschuh