SMILEY4 / ktor-swagger-ui

Kotlin Ktor plugin to generate OpenAPI and provide Swagger UI
Apache License 2.0
182 stars 33 forks source link

Wrong pathParameter from resources route #70

Closed Giuliopime closed 1 year ago

Giuliopime commented 1 year ago

If you have a route that uses ktor Resources for type safe routes, the properties of the data class describing the resource are added to the route string generated for swagger.

For example:

@Resource(path = "/welcome-action")
class WelcomeActionRoute(val email: String)

Will generate

image

Even though that is a query parameter, not a path parameter, and I properly described it in the OpenApiDocs of that route

get<WelcomeActionRoute>({
        // ...
        request {
            queryParameter<String>("email") {
                description = "the encoded email of the user"
                example = "sample%40mail.com"
                required = true
                allowEmptyValue = false
                allowReserved = false
            }
        }
        // ...

Which part of the lib is responsible from doing this? The resources data classes should be converted to string using only the path from the @Resource annotation, and ignore every other property of the data class. I can open a PR if pointed in the right direction to resolve this 👍🏼

SMILEY4 commented 1 year ago

Thanks a lot! The responsible code should be in builder/route/RouteCollector.kt#getPath (probably line 66.)

Giuliopime commented 1 year ago

Do you plan to release the bug fix? @SMILEY4

SMILEY4 commented 1 year ago

Yes, ill create it probably tomorrow or until end of this week 👍