Raise error if method parameter does not have @Body()
Hi, I spent a good amount of time trying to understand why my request bodies were not being sent. Eventually I found @Body() annotation, but it could have been easier if the library:
- Raised an error, since the parameter has no annotation.
- Just consider the parameter as a body.
Thanks
Not having any annotation on endpoint call method parameters in Retrofit (on Android) raises a runtime IllegalArgumentException .
For example if you have an API interface like this with Retrofit:
interface RetrofitTestApi {
@POST("/api/test")
fun getId(param: String): Call<String>
}
You will get the following IAE when trying to call getId (built with a valid Retrofit builder of course) in runtime:
Process: hu.stewe.playground, PID: 12197
java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #1)
for method RetrofitTestApi.getId
Because the original Retrofit uses runtime reflection magic, we can only get runtime errors from it, like the one above.
Considering all of the above, chopper should go with the first solution proposed by @BugsBunnyBR:
The generator should raise an error when it finds and endpoint method that has at least one parameter without any valid annotations.
Closing this issue since chopper_generator displays a warning in this case https://github.com/lejard-h/chopper/blob/chopper_generator-v7.0.5%2B1/chopper_generator/lib/src/generator.dart#L347