Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #512
Closed
Open
Issue created Jul 09, 2018 by Administrator@rootContributor

Rust client code generation is unhygenic

Created by: euank

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:

https://github.com/OpenAPITools/openapi-generator/blob/b5942624d6714f38c0bde9ae9c7400df1d48b1ed/modules/openapi-generator/src/main/resources/rust/api.mustache#L73-L75

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.

Assignee
Assign to
Time tracking