Closed mintu19 closed 4 years ago
On non authenticated routes it does work on the experimental branch.
I find it odd that you declare a post on an authenticated route without giving it the principal type, are you authenticating the route, and if yes why is it not the OpenAPIAuthenticatedRoute<A>
context that requires you to give the authentication type parameter ?
fun <reified P : Any, reified R : Any, reified B : Any, A> OpenAPIAuthenticatedRoute<A>.post
yes i am using authenticated route. I missed writing proper signature while posting here. It is like this:
post<MyParams, PResponse, PRequest, IdPrincipal>(
what is the issue and why route is not properly generated?
What version are you using ? 0.1 or 0.2 experimental ?
i am using implementation 'com.github.papsign:Ktor-OpenAPI-Generator:-SNAPSHOT'
The snapshots might be unstable, can you try the tagged versions to see if there is one that works ?
Le dim. 19 avr. 2020 à 16:32, Akshit Bhandari notifications@github.com a écrit :
i am using implementation 'com.github.papsign:Ktor-OpenAPI-Generator:-SNAPSHOT'
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/papsign/Ktor-OpenAPI-Generator/issues/35#issuecomment-616148542, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJHT75OZRJNS5HYRB7FVPDRNMDPTANCNFSM4MLYXD4Q .
using implementation 'com.github.papsign:Ktor-OpenAPI-Generator:0.2-beta.2-experimental'
getting:
19-04-2020 21:0
5:12.678 [main] INFO Application - route: /openapi.json/(method:GET)
19-04-2020 21:05:12.678 [main] INFO Application - route: /(method:GET)
19-04-2020 21:05:12.679 [main] INFO Application - route: /(authenticate "default")/com.papsign.ktor.openapigen.route.util.ConstantRouteSelector@646c0a67/users/agent/(method:GET)
19-04-2020 21:05:12.679 [main] INFO Application - route: /(authenticate "default")/com.papsign.ktor.openapigen.route.util.ConstantRouteSelector@3804a9a8/images/(method:POST)
it doesn't look good
What is the import you use for the path annotation, is it the one from the library ?
yes
import com.papsign.ktor.openapigen.annotations.Path
I have verified it is not working without auth also
@Path("/my/{id}")
data class TestParam(@PathParam("id") val id: String)
apiRouting {
head<TestParam, Boolean>(
info("id")
) {
respond(true)
}
}
This will generate 19-04-2020 23:52:15.117 [main] INFO Application - route: /(method:HEAD) instead of route /my/{id}
if i use get instead of head no new route is generated (as get root is already there in normal ktor routes i created).
Path annotation is not working as expected
You can debug the function package com.papsign.ktor.openapigen.route.preHandle
at this line:
val path = P::class.findAnnotation<Path>()
this is common code, it should be called by both normal and authenticated routes, it should not be null, and should contain your path string. This is the only relevant code to this issue, if there is a problem it can be seen here...
It could be:
In case it cannot be found you can specify the params in the route directly instead of the annotation:
route("{param}").post()
If you have a code snippet (with all the imports) i can clone that recreates the issue it would be great so i can debug it.
i am not able to debug this via intellij idea. IDE hangs on debug that code... I will try to make a sample for you to debug...
Using this will generate doc properly?
route("{param}").post()
and how to use in call inside post method to get parameter as call is not available
Yes, the path annotation is just a convenience.
Resolved the issue while creating example project. Route was created properly. It was not displayed in log because ktor have no way to list routes so routes were logged based on selector. I printed all routes and then my routes were visible. Given routes may or may not have handler but there is no way to check as handlers are internal field. So have to list all routes.
Also the api was not called because content Type header was missing while sending. It gets added in postman auto but dont know why it was't. Tracing routes helped with that.
Anyways it works now.Thanks
I am using @Path like
When i use it with route, proper openapi definitions are created but ktor route is not working. I listed routes and checked... It doesn't show as parameterized route and also none of post method works...
route listing on ktor show
Sending port request to images/1 or images/ routes produces error 404
Why route is shown unhandled and it is generated as above without parameters