-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Rust client code generation is unhygenic #512
Comments
We use this approach for other generators (e.g. C#, Ruby client generators) by prefixing "local_var_" or "localVar", e.g. For Rust, I suggest we follow the similar approach to avoid conflicts with variable naming. May I know if you have time to contribute the enhancement? I can show you some good starting points if you want. |
I've started working on writing a generic helper that is called by the generated methods since I think that's an aesthetically nicer solution. I do expect I'll be able to get it working and contribute it, but if I can't I can easily enough prefix all the local variables and PR that instead. |
This reduces the number of variables which are used in the generated operations, thus fixing OpenAPITools#512. This also fixed a TODO related to URI parsing errors. Other than that, it is meant to be functionally identical.
* [Rust] Move request logic into standalone file This reduces the number of variables which are used in the generated operations, thus fixing #512. This also fixed a TODO related to URI parsing errors. Other than that, it is meant to be functionally identical. * [Rust] Add support for non-file form params Up until now, they just weren't there at all * [Rust] Use more rustic terms in example
…ls#528) * [Rust] Move request logic into standalone file This reduces the number of variables which are used in the generated operations, thus fixing OpenAPITools#512. This also fixed a TODO related to URI parsing errors. Other than that, it is meant to be functionally identical. * [Rust] Add support for non-file form params Up until now, they just weren't there at all * [Rust] Use more rustic terms in example
Description
The rust client's code generation can have variable name conflicts with function's definition and the generated parameter names. For example, if a parameter to a function using oauth2 auth is called "token", the below code will override its value:
openapi-generator/modules/openapi-generator/src/main/resources/rust/api.mustache
Lines 73 to 75 in b594262
Suggest a fix/enhancement
There are a couple possible options here.
One option would be to reserve all variable names used in the body of such functions and ave the java code remap the parameter names.
Another could be to prefix all those variables with something like "openapi_local" and assume no one will name parameters starting with that string.
We could also rebind all the parameters immediately to known names which won't conflict, and then allow shadowing throughout the rest of the function. This is also fairly easy, and I think might be the best short term solution.
In the long term, I think this can be improved by having a helper non-generated method to make the request, and then have each generated method simply be a call to that helper with the correct parameters, allowing the generated method's scope to not polute the main logic of handling a request.
The text was updated successfully, but these errors were encountered: