SMILEY4 / ktor-swagger-ui

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

Wrong pathParameter from resources route #70

Closed Giuliopime closed 9 months ago

Giuliopime commented 9 months 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 9 months ago

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

Giuliopime commented 9 months ago

Do you plan to release the bug fix? @SMILEY4

SMILEY4 commented 9 months ago

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