chopper icon indicating copy to clipboard operation
chopper copied to clipboard

Raise error if method parameter does not have @Body()

Open juliocbcotta opened this issue 6 years ago • 1 comments

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:

  1. Raised an error, since the parameter has no annotation.
  2. Just consider the parameter as a body.

Thanks

juliocbcotta avatar Sep 02 '19 23:09 juliocbcotta

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.

stewemetal avatar Mar 11 '20 21:03 stewemetal

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

techouse avatar Oct 11 '23 19:10 techouse