nielsfalk / ktor-swagger

Apache License 2.0
133 stars 38 forks source link

Support of Ktor-Routing #19

Open Dimdron opened 6 years ago

Dimdron commented 6 years ago

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

nielsfalk commented 6 years ago

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

REPLicated commented 5 years ago

@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.

scic commented 5 years ago

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.

JLLeitschuh commented 5 years ago

@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.

Wicpar commented 4 years ago

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.

JLLeitschuh commented 4 years ago

@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.