SMILEY4 / ktor-swagger-ui

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

No code completion when using `to` inside OpenApiResponses #112

Closed Him188 closed 1 month ago

Him188 commented 1 month ago

When you add a reponse code definition like this:

post({
    description = "test"
    response {
        HttpStatusCode.Created to {
            description = "Subject created"
            body<CreateApiKeyResponse>()
        }
    }
}) 

You always have to type HttpStatusCode. before IDE can help you.

Also the to with a lambda sounds odd to me, as the standard library use it to create a Pair. It really sounds like the to will create a Pair and does not register something.

What I would suggest is:

post({
    description = "test"
    response {
        code(HttpStatusCode.Created) {
            description = "Subject created"
            body<CreateApiKeyResponse>()
        }
        code(HttpStatusCode.Conflict) {
            description = "You have reached the limit"
            body<Unit>()
        }
    }
}) {

}

You type smaller case code without pressing shift, you press enter, then IDE will prompt for completion for HttpStatusCode. This could give both better typing experience and looking.

image

SMILEY4 commented 1 month ago

hi, thanks for your suggestions. I added some improvements / alternatives to the dsl which are included in version 3.2.0.