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

Function name generation may be misleading/incorrect #821

Open
lionel87 opened this issue Jul 9, 2024 · 2 comments
Open

Function name generation may be misleading/incorrect #821

lionel87 opened this issue Jul 9, 2024 · 2 comments

Comments

@lionel87
Copy link

lionel87 commented Jul 9, 2024

I had issues with the function name generation, a path like /user/logout generated as api.user.logoutList() but it is not actually a list.
A different path like /clients/{zone} is generated as api.clientsDetail() which is actually a list.

It would be a good feature to give control over the naming, or use the naming scheme that the swagger.io generator uses. it suffixes the name with the http method, like api.user.logoutGET() and api.clientsGET().

The current behavior that checks if the path contains placeholders are working only on simple or example apis I quess.

_.camelCase(`${pathName}_${hasPathInserts ? "detail" : "list"}`),

swagger-typescript-api version: 13.0.12

@snuup
Copy link

snuup commented Aug 13, 2024

This is very serious. WIthout any reason my api method "getBunny" is renamed into "getBunnyList". Makes no sense at all.

@petr-jilek
Copy link

You can create your template for your project.

For example, you can create the templates folder in your project and add the mentioned route-name.ejs file to this folder.

In this file templates/route-name.ejs you can create custom behavior. For example update the methodAliases part like:

const methodAliases = {
  get: (pathName, hasPathInserts) => _.camelCase(`${pathName}_get`),
  post: (pathName, hasPathInserts) => _.camelCase(`${pathName}_post`),
  put: (pathName, hasPathInserts) => _.camelCase(`${pathName}_put`),
  patch: (pathName, hasPathInserts) => _.camelCase(`${pathName}_patch`),
  delete: (pathName, hasPathInserts) => _.camelCase(`${pathName}_delete`),
};

Then in your command specify the template folder path. For example:

swagger-typescript-api -p http://localhost:5000/swagger/v1/swagger.json -o ./api -n api.ts -t ./templates

I tried it only with this file in the templates folder and it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants