How to make query parameters show up in OpenApi generated from KTOR code by the IntelliJ plugin?
I use the IntelliJ plugin to generate OpenApi documentation for my ktor backend:
https://www.jetbrains.com/help/idea/ktor.html#generate-openapi
However, any query parameters that I use is not included in the generated documentation, for example bankIdLoginAttemptToken
in the example below:
Router.kt
fun Routing.bankIdAuth(bankIdController: BankIdController) {
route("v1") {
route("bankid") {
route("auth") {
get("collect") { bankIdController.collectLogin(this.context) }
}
}
}
}
BankIdController.kt:
suspend fun collectLogin(call: ApplicationCall) {
val bankIdLoginAttemptToken: String by call.request.queryParameters // This bankIdLoginAttemptToken query parameter does not show up in Swagger
val result = bankIdAuthService.collectLogin(bankIdLoginAttemptToken)
call.respond(result)
}
请先登录再写评论。
Hi!
Unfortunately we don't support this syntax yet (IDEA-346473)
val bankIdLoginAttemptToken: String by call.request.queryParameters
But You can use Resources for type-safe routing
Or
call.parameter["bankIdLoginAttemptToken"]
like this
Thanks! I think I'll just do a dummy workaround in Router.kt to make the parameters show up for now!
fun Routing.bankIdAuth(bankIdController: BankIdController) {
route("v1") {
route("bankid") {
route("auth") {
get("collect") {
this.context.parameters["bankIdLoginAttemptToken"] // Dummy to make the parameter show up in docs
bankIdController.collectLogin(this.context)
}
}
}
}
}