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

[typescript-angular] how to customize output filenames? #727

Closed
softdays opened this issue Aug 3, 2018 · 17 comments
Closed

[typescript-angular] how to customize output filenames? #727

softdays opened this issue Aug 3, 2018 · 17 comments

Comments

@softdays
Copy link
Contributor

softdays commented Aug 3, 2018

Do someone can help me to customize output files names?

Given the tag below:
My Resource
I want to obtain the output file:
my-resource.service.ts
instead of myResource.service.ts

Given the model below:
MyModel
I want to obtain the output file:
my-model.ts
instead of myModel.ts

Many thanks for your help

@softdays
Copy link
Contributor Author

softdays commented Aug 3, 2018

@wing328 many thanks for the code highlights

See this guide for TypeScript/Angular conventions:
https://angular.io/guide/styleguide#service-names

Do you think this could be the subject of a feature request and/or PR?

@wing328
Copy link
Member

wing328 commented Aug 3, 2018

Thanks for sharing more.

Yes, I think we should follow the style guide.

May I know if you've time to file a PR with the correction/enhancement?

cc @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01)

@softdays
Copy link
Contributor Author

softdays commented Aug 4, 2018

It will depend of the workload. Should the PR just be a drop-in replacement of the current camelCase strategy? Or do you prefer to implement a new option driving different strategies? I think about something similar that we already have with modelPropertyNaming for example...

@wing328
Copy link
Member

wing328 commented Aug 4, 2018 via email

@softdays
Copy link
Contributor Author

softdays commented Aug 4, 2018

Do you have any preference for the name of the new property defining the naming strategy?
Should I use the master branch (3.2-SNAPSHOT) for this job as this will be a non-breaking change?

@wing328
Copy link
Member

wing328 commented Aug 4, 2018

For option name, I would suggest "fileNaming".

(please add this option as a TypeScript Angular option only (not a global option))

Should I use the master branch (3.2-SNAPSHOT) for this job as this will be a non-breaking change?

Yes, please.

@softdays
Copy link
Contributor Author

@wing328: at the moment, the names of the imported classes are deduced from their file names. This causes some trouble with the new dash-case strategy.

Let's take an example. Given the following resource tag name: MY Resource AAA.
The generated service name will be MYResourceAAAService

With default fileNaming property value (i.e. original code using camelCase) we got the following filename: mYResourceAAA.service.ts
In this case we can indeed deduce the import className from the fileName because we preserved case.

But with fileNaming=dash-case, the file name we got is: my-resource-aaa.service.ts
So we cannot deduce the right className anymore because we lost original letter case.

My proposal would be to normalize the names of the services in order to get: MyResourceAaaService.
In this way we can deduce the names of the imported classes from their files names.

What do you think?

@macjohnny
Copy link
Member

My proposal would be to normalize the names of the services in order to get: MyResourceAaaService.
In this way we can deduce the names of the imported classes from their files names.

this could lead to potential problems. file names and class names can differ. if i remember correctly, there were PRs that explicitly introduced this feature.

@softdays
Copy link
Contributor Author

Ok I understand.

Another way could be to extend the imports model to add a class name in addition to the import path. What do you think about it?

@softdays
Copy link
Contributor Author

No feedback on this proposal? Maybe my proposal is not clear enough...

@wing328
Copy link
Member

wing328 commented Aug 24, 2018

@softdays to move this forward, what about testing different API and model naming (PascalCase, snake-case, etc) with your PR? That way we can ensure the new naming option you introduced works with different cases.

@softdays
Copy link
Contributor Author

Not sure to understand what you suggest...
Would you suggest that I should continue my PR by adding more output possibilities for filenames?

As you know I'm currently facing a structural issue with my PR concerning 'imports' generation using kebab-case and I don't have any potential solution for that...

@wing328
Copy link
Member

wing328 commented Aug 25, 2018

Would you suggest that I should continue my PR by adding more output possibilities for filenames?

Sorry, that's not what I meant.

Your PR add an option to choosing the naming convention: camelCase, dash-case, which is good.

My question is have you test both to ensure the issue mentioned by @macjohnny does not occur:

file names and class names can differ.

If both options (camelCase, dash-case) have been tested to ensure there's no discrepancy between the two and the code is compilable, then we can move forward with your PR.

@softdays
Copy link
Contributor Author

softdays commented Aug 25, 2018

The issue mentioned by @macjohnny is related to my proposal concerning class names normalization.
But as you can see in the code below the model names of imports are already deduced from file names, at least for the typescript-angular generator. So I don't understand how file names and class names can differ given that imported model names of a service will be resolved from their file names:

im.put("classname", getModelnameFromModelFilename(im.get("filename").toString()));

@wing328
Copy link
Member

wing328 commented Aug 29, 2018

@softdays as discussed, there's a way to retrieve the "original" model/class name. Using that will fix the import issue.

@wing328
Copy link
Member

wing328 commented Aug 29, 2018

cc @TiFu as we may also need this feature/option in the refactored TS generator.

softdays added a commit to softdays/openapi-generator that referenced this issue Aug 30, 2018
@wing328 wing328 closed this as completed in 7a18a1a Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants