SMILEY4 / ktor-swagger-ui

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

OpenApiResponses.code incorrectly uses toString on statusCode #131

Closed NecroKote closed 1 month ago

NecroKote commented 2 months ago

On the following line:

https://github.com/SMILEY4/ktor-swagger-ui/blob/013161a5c301a331e707e393fecfc13c4e405ec4/ktor-swagger-ui/src/main/kotlin/io/github/smiley4/ktorswaggerui/dsl/routes/OpenApiResponses.kt#L38

statusCode.toString() should be replaced with statusCode.value.toString()

Otherwise, the resulting schema contains incorrect values. For example, with code(HttpStatusCode.BadRequest):

"responses": {
    "400 Bad Request": {
        "headers": {...},
        "content": {...}
    }
}

For the time being, I'm using following workaround:

fun OpenApiResponses.status(code: HttpStatusCode, block: OpenApiResponse.() -> Unit) {
    return code(code.value.toString(), block)
}
SMILEY4 commented 1 month ago

Hi, thanks for the info :+1: the bug is fixed and included in version 3.5.0