Skip to content
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

[REQ] operationId: Allow getting only the method name #9719

Closed
ygalblum opened this issue Jun 8, 2021 · 0 comments · Fixed by #9724
Closed

[REQ] operationId: Allow getting only the method name #9719

ygalblum opened this issue Jun 8, 2021 · 0 comments · Fixed by #9724

Comments

@ygalblum
Copy link
Contributor

ygalblum commented Jun 8, 2021

Is your feature request related to a problem? Please describe.

I have an OpenAPI server based on Python Connexion (https://github.com/zalando/connexion). Since this is a Python module the operationId fields take the form of "package_name.api.module_name.method". For example, the operationId for the "/users" GET operation will be "my_server.api.users.get".
As a result, the Go code generator will create an service called UsersApiService that will have a method called MyServerApiUsersGet. To me, this name has a lot of unneeded sections. The Python package name is obviously not needed, the word Api is not needed and also the Service name is not needed since the method is already inside a service with that name. So, instead, I would like to have the method be just "get".
Please do not focus on this specific "GET" operation, the naming could be anything.

Describe the solution you'd like

Today, the code generator allows removing the prefix, but it assumes the delimiter is an underscore and takes everything after the first one. In my case, the delimiter is a period and I would like to get everything after the last one.

So, I would like to suggest broadening this option by adding two configuration fields:

  1. Delimiter - allowing the user to choose which delimiter to use. The default should be underscore
  2. Count - The X occurrence of the delimiter that constitutes a prefix. The default should be 1 and -1 should be used for last

Describe alternatives you've considered

I saw your comment about using templates. But, since this change relates to all languages, I think my suggestion is the way to go

ygalblum added a commit to ygalblum/openapi-generator that referenced this issue Jun 10, 2021
Add new configuration flags: REMOVE_OPERATION_ID_PREFIX_DELIMITER and REMOVE_OPERATION_ID_PREFIX_COUNT
Add the corresponding fields in the DefaultCodegen
Sanitize the operationId according to the new fields
Add delimiter to list of nonNameElementPattern
Add unit test
wing328 pushed a commit that referenced this issue Jun 10, 2021
Add new configuration flags: REMOVE_OPERATION_ID_PREFIX_DELIMITER and REMOVE_OPERATION_ID_PREFIX_COUNT
Add the corresponding fields in the DefaultCodegen
Sanitize the operationId according to the new fields
Add delimiter to list of nonNameElementPattern
Add unit test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant