-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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 2: Make service suffix configurable #341
Conversation
What do you meant by naming collisions? What problems are you getting that
can't be resolve with
Import { service as another name } from '@myscope/service'
…On Mon, Jun 18, 2018, 8:23 AM tomvangreen ***@***.***> wrote:
PR checklist
- Read the contribution guidelines
<https://github.com/openapitools/openapi-generator/blob/master/CONTRIBUTING.md>
.
- Ran the shell script under ./bin/ to update Petstore sample so that
CIs can verify the change. (For instance, only need to run
./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if
updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG}
client's mustache templates). Windows batch files can be found in
.\bin\windows\.
- Filed the PR against the correct branch
<https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches>:
master, 3.1.x, 4.0.x. Default: master.
- Copied the technical committee
<https://github.com/openapitools/openapi-generator/#62---openapi-generator-technical-committee>
to review the pull request if your PR is targeting a particular programming
language.
Description of the PR
In earlier versions of the typescript-angular (2) swagger-codegen /
openapi-generator, the suffix of the generated api servies was Api. This
has been changed to Service in order to conform to angular naming
guidelines.
For our project it makes sense that we can chose a different prefix in
order to avoid naming collisions. For this I introduced 2 configuration
parameters. serviceSuffix and serviceFileSuffix.
Service suffix is used as a suffix in the generated class name. Service
file suffix is used as suffix in the file name (before the .ts extensions).
Technical comitee typescript: @TiFu <https://github.com/TiFu>, @taxpon
<https://github.com/taxpon>, @sebastianhaas
<https://github.com/sebastianhaas>, @kenisteward
<https://github.com/kenisteward>, @Vrolijkx <https://github.com/Vrolijkx>,
@macjohnny <https://github.com/macjohnny>
#234 <#234>
------------------------------
You can view, comment on, or merge this pull request online at:
#341
Commit Summary
- Added serviceSuffix and serviceFileSuffix parameters to control the
suffixes of generated class and file names
- Updated TypeScriptAngularClientOptionsProvider to include the new
serviceSuffix and serviceFileSuffix parameters
- Fixed part in generator where hardcoded 'Service' suffix was used.
- Made the . in the service file name part of the config setting
- Updated cli message
File Changes
- *M*
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java
<https://github.com/OpenAPITools/openapi-generator/pull/341/files#diff-0>
(19)
- *M*
modules/openapi-generator/src/test/java/org/openapitools/codegen/options/TypeScriptAngularClientOptionsProvider.java
<https://github.com/OpenAPITools/openapi-generator/pull/341/files#diff-1>
(4)
- *M*
samples/client/petstore/typescript-angular-v2/default/.openapi-generator/VERSION
<https://github.com/OpenAPITools/openapi-generator/pull/341/files#diff-2>
(2)
- *M*
samples/client/petstore/typescript-angular-v2/with-interfaces/.openapi-generator/VERSION
<https://github.com/OpenAPITools/openapi-generator/pull/341/files#diff-3>
(2)
- *M*
samples/client/petstore/typescript-angular-v4.3/npm/.openapi-generator/VERSION
<https://github.com/OpenAPITools/openapi-generator/pull/341/files#diff-4>
(2)
- *M*
samples/client/petstore/typescript-angular-v4/npm/.openapi-generator/VERSION
<https://github.com/OpenAPITools/openapi-generator/pull/341/files#diff-5>
(2)
- *M*
samples/client/petstore/typescript-angular-v6-not-provided-in-root/default/.openapi-generator/VERSION
<https://github.com/OpenAPITools/openapi-generator/pull/341/files#diff-6>
(2)
- *M*
samples/client/petstore/typescript-angular-v6-provided-in-root/default/.openapi-generator/VERSION
<https://github.com/OpenAPITools/openapi-generator/pull/341/files#diff-7>
(2)
Patch Links:
- https://github.com/OpenAPITools/openapi-generator/pull/341.patch
- https://github.com/OpenAPITools/openapi-generator/pull/341.diff
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#341>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AMPLtUVRcRIKFNylnwo_sxrapHVkUZ5Qks5t96nogaJpZM4Urvsk>
.
|
We are doing aliasing now, but we have a lot of services that exist in the api and have a counter part that we have written ourselves, which uses the same name (I know, this is not optimal, but we inherited this code base). Aliasing comes with some disadvantages. Auto import in IDE's does not work so well, as you anyway need to manually alias it after the import. Additionally we can never be sure by just looking at the class, if it is now a service or an api, because it might be that somebody forgot to alias the service. Additionally, I really like to have the distinction between generated and self written serviecs. Having this api suffix makes it clear (without having to consult the import statement) on what exactly we are looking at. Honestly I was a bit bummed when the suffix has been changed from api to service. All in all, it would make our lifes a bit easier and let us concentrate on the real work ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me, although I haven't tested it
Yeah you are right in thinking we changed the generator from API to service
in order to be more confirming to angular standards.
It is unfortunate, that you have the situation on your hands and we
appreciate the PR!
I'll look into this more when I am at a computer but if you are solely
changing names I should be able to approve this pretty quickly
…On Mon, Jun 18, 2018, 8:42 AM tomvangreen ***@***.***> wrote:
We are doing aliasing now, but we have a lot of services that exist in the
api and have a counter part that we have written ourselves, which uses the
same name (I know, this is not optimal, but we inherited this code base).
Aliasing comes with some disadvantages. Auto import in IDE's does not work
so well, as you anyway need to manually alias it after the import (and not
aliasing it comes with the danger that you see you have a FooService, but
you don't know if it comes from the api or is a service we built).
Additionally we can never be sure by just looking at the class, if it is
now a service or an api, because it might be that somebody forgot to alias
the service.
Additionally, I really like to have the distinction between generated and
self written serviecs. Having this api suffix makes it clear (without
having to consult the import statement) on what exactly we are looking at.
Honestly I was a bit bummed when the suffix has been changed from api to
service.
All in all, it would make our lifes a bit easier and let us concentrate on
the real work ;)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#341 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMPLtfvQkCZvJ4TpN_f6Spfg_VKdbyK5ks5t9640gaJpZM4Urvsk>
.
|
@tomvangreen did you regenerate the samples and got no changes? |
You're welcome for the pull request, wasn't too much work. I would be happy if you could check that I did not break anything. I tried to implement the change in a non breaking manner (meaning you should have an identical output when you don't supply the new config parameters), but I would feel better if you could validate that before merging back. Edit: I regeneretad them, but I made a small change since then. Let me try again to make sure. |
I reran the angular tests (on windows with the script typescript-angular-petstore-all.bat ) and the only thing that has changed is the VERSION file in the .openapi-generator folder. |
As long as you have generated it using another rname for your own personal
uses that should be enough of a test .
…On Mon, Jun 18, 2018, 9:08 AM tomvangreen ***@***.***> wrote:
I reran the angular tests (on windows with the script
typescript-angular-petstore-all.bat ) and the only thing that has changed
is the VERSION file in the .openapi-generator folder.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#341 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMPLtaCSjB2q7M7NMQkPsBA7gc5YfKQTks5t97RBgaJpZM4Urvsk>
.
|
@tomvangreen could you please merge the most recent master into your branch to re-trigger the CircleCI tests? |
…uffixes of generated class and file names
…viceSuffix and serviceFileSuffix parameters
@macjohnny : I did that but now the shippable build is failing. I looked at the logs and it looks like it is unrelated to my changes.
|
@tomvangreen absolutely, it usually is due to some rate-limits for artifact downloads from other locations. Usually re-triggering the CircleCI build solves the issue. You can also manually do that by closing and re-opening your PR |
@tomvangreen now it was the Shippable build that ran into the same issue... |
@macjohnny What can I do about that? Should I wait a day and close and reopen again? |
@tomvangreen yes, so far I don't know of a better solution |
other PRs face the same problem, see e.g. #289 (comment) |
The
|
@kenisteward @macjohnny thanks for reviewing the change. @tomvangreen thanks for the PR. For your upcoming PRs, I would suggest creating a branch as per git best practices. |
@wing328 You're welcome, in the end the change should make my live easier in multiple projects, so I'm happy to help. I messed up with the branch. I did the change first for swagger codegen and then I wanted to port the changes to openapi codegen and forgot to create the branch in this repo. I try to keep that in mind for future pull requests. |
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.master
,3.1.x
,4.0.x
. Default:master
.Description of the PR
In earlier versions of the typescript-angular (2) swagger-codegen / openapi-generator, the suffix of the generated api servies was Api. This has been changed to Service in order to conform to angular naming guidelines.
For our project it makes sense that we can chose a different prefix in order to avoid naming collisions. For this I introduced 2 configuration parameters.
serviceSuffix
andserviceFileSuffix
.Service suffix is used as a suffix in the generated class name. Service file suffix is used as suffix in the file name (before the .ts extensions).
Technical comitee typescript: @TiFu, @taxpon, @sebastianhaas, @kenisteward, @Vrolijkx, @macjohnny
#234