-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to have 'value' as a parameter identifier in annotated methods #639
Allow to have 'value' as a parameter identifier in annotated methods #639
Conversation
Thanks for the contribution. Pls fix the test error. You can run the following commands in your local environment.
|
Hi ! Thanks for the instructions on running the tests, and sorry it took me a while to get back to it. |
HI @IcarusSosie Thanks for the update. The test code must be updated accordingly. |
@IcarusSosie |
Conflicts: generator/test/src/generator_test_src.dart
Hi ! Sorry for taking so long to get back to this, life got in the way these last few months. I've fixed a few spots where I'd wrongly assumed Again, I'm sorry I left this issue hanging for so long 😮 |
Currently it is not possible to have a parameter named
value
in methods annotated with@GET/POST/PUT...
I'm in the complex process of setting up retrofit.dart to generate an API Client from an OpenAPI specification file, which itself is generated by api-platform, the boilerplate code of which is also generated. (by a custom built code-generator based on php-generator)
To make a long story shorter, this means that the method parameters in my RestClient have identifiers based on the column names of the underlying database. Here is an example of such a method :
The lack of control I have on the identifiers causes this of course. I could rename the parameter since I have an
@Field()
annotation anyway, but I want to limit the chance of runtime errors and special cases in my generation code. This happens mostly in PATCH methods, but also affects some filters for GET methods. Here's the generated code for this specific method :Which results in the
value
parameter clashing with thefinal value
declaration.I'm not yet super familiar with retrofit.dart, so this might not be ideal, but changing the value of
_valueVar
from'value'
to'_value'
ingenerator/lib/src/generator.dart
seems to solve the issue for me, and would allow to usevalue
as an identifier for method parameters in the package user'sRestClient
class.It also seems to me like the current value of
_valueVar
,'value'
, is hard-coded in some places, and should be using_valueVar
or$_valueVar
to lessen the risk of bugs in the generated code in case of edits. Again, I'm not quite familiar with the code, so I'd appreciate a look-over make sure the edits I've made are indeed correct.Additionally, the local
queryParameter
variable in the generated code suffers from this as well. I haven't modified it in this branch yet, but I could if deemed necessary.