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] Bug ModuleWithProviders missing generic type for Angular 10 #10417

Closed
LeanderG opened this issue Aug 2, 2020 · 4 comments · Fixed by #10464
Closed

[typescript-angular] Bug ModuleWithProviders missing generic type for Angular 10 #10417

LeanderG opened this issue Aug 2, 2020 · 4 comments · Fixed by #10464

Comments

@LeanderG
Copy link

LeanderG commented Aug 2, 2020

Description

ModuleWithProviders without a generic type is deprecated since Angular 9 and mandatory since Angular 10:
See: angular/angular@20cc3ab

Swagger-codegen version

3.0.21

Steps to reproduce

Using the generated code (without npm) in an Angular 10 project leads to a TypeScript error and the application not compiling.

Suggest a fix/enhancement

Change ModuleWithProviders to ModuleWithProviders<ApiModule> to:

public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders {
.

Edit:
Looks like the option to add a generic type was added in Angular 6.1.0, so my solution breaks earlier versions.
angular/angular@60aeee7#diff-968ca8dead1eca4223cb534b9f0b9c02R79

@bosco688
Copy link

Hey,

do we really need to support Angular < 6.1.x? Your solution seems to work, so push it please.
I have the same Problem with Angular 10 and swagger-codegen.

@LeanderG
Copy link
Author

The typescript-angular generator maintenance could be better. There are only samples up to Angular 6. Version 7 was released almost 2 years ago. There is a fork of this project called OpenAPI Generator which has samples up to Angular 9. I'm using it with Angular 10 and it is working great.

@twopelu
Copy link

twopelu commented Sep 14, 2020

Same problem here, just migrated to Angular 10 and found that we have to change the auto-generated code to make it work :-(

Edit: I have tried the OpenAPITools generator 5.0 0-beta2 and it looks like working, still have to make further tests but the code generated compiles in Angular 10.

@netrounds-guillaume
Copy link

netrounds-guillaume commented Sep 16, 2020

As a workaround, I am running the following command after generating the typescript-angular client:

sed -i 's/ModuleWithProviders {/ModuleWithProviders<ApiModule> {/' <path_to_generated_folder>/api.module.ts

This is the same approach as a workaround for #8836

derkoe added a commit to derkoe/swagger-codegen that referenced this issue Sep 17, 2020
Make ModuleWithProviders generic for all Angular version >= 10 because it is mandatory.

Fixes swagger-api#10417

Signed-off-by: Christian Köberl <christian.koeberl@porscheinformatik.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants