Angular 10 Swagger Codegen: Generic type ModuleWithProviders<T> requires 1 type argument(s)
this error tells you that, the ModuleWithProviders
class has 1 generic paramter. so you sould use it like ModuleWithProviders<T>
where T is a type.
EDIT:
The class is defined like this:
interface ModuleWithProviders<T> {
ngModule: Type<T>
providers?: Provider[]
}
.
export class ApiModule {
public static forRoot(configurationFactory: () => Configuration) : ModuleWithProviders<ApiModule> {
return {
ngModule: ApiModule,
providers: [ { provide: Configuration, useFactory: configurationFactory } ]
};
}
See Resource:
https://angular.io/guide/migration-module-with-providers
We stumbled over the same issue. Luckily you can provide custom *.mustache templates to the swagger-codegen-cli using the -t
switch (see the swagger doc).
Our adapted api.module.mustache looks like this:
import { NgModule, ModuleWithProviders, SkipSelf, Optional } from '@angular/core';
import { Configuration } from './configuration';
{{#useHttpClient}}import { HttpClient } from '@angular/common/http';{{/useHttpClient}}
{{^useHttpClient}}import { Http } from '@angular/http';{{/useHttpClient}}
{{#apiInfo}}
{{#apis}}
import { {{classname}} } from './{{importPath}}';
{{/apis}}
{{/apiInfo}}
@NgModule({
imports: [],
declarations: [],
exports: [],
providers: [
{{#apiInfo}}{{#apis}}{{classname}}{{#hasMore}},
{{/hasMore}}{{/apis}}{{/apiInfo}} ]
})
export class ApiModule {
public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders<ApiModule> {
return {
ngModule: ApiModule,
providers: [ { provide: Configuration, useFactory: configurationFactory } ]
};
}
constructor( @Optional() @SkipSelf() parentModule: ApiModule,
@Optional() http: {{#useHttpClient}}HttpClient{{/useHttpClient}}{{^useHttpClient}}Http{{/useHttpClient}}) {
if (parentModule) {
throw new Error('ApiModule is already loaded. Import in your base AppModule only.');
}
if (!http) {
throw new Error('You need to import the {{#useHttpClient}}HttpClientModule{{/useHttpClient}}{{^useHttpClient}}HttpModule{{/useHttpClient}} in your AppModule! \n' +
'See also https://github.com/angular/angular/issues/20575');
}
}
}
The only change needed is to replace ModuleWithProviders
by ModuleWithProviders<ApiModule>
.
Afterwards the generated api.module.ts will work with Angular 10.