File tree Expand file tree Collapse file tree 6 files changed +52
-12
lines changed
modules/openapi-generator/src/main/resources/typescript-nestjs-server
samples/server/petstore/typescript-nestjs-server Expand file tree Collapse file tree 6 files changed +52
-12
lines changed Original file line number Diff line number Diff line change @@ -7,18 +7,30 @@ import { {{classname}}Controller } from './controllers';
77{ {/apis} }
88{ {/apiInfo} }
99
10+ export type ApiModuleConfiguration = {
11+ /**
12+ * your Api implementations
13+ */
14+ apiImplementations: ApiImplementations,
15+ /**
16+ * additional Providers that may be used by your implementations
17+ */
18+ providers?: Provider[],
19+ }
20+
1021@Module({ } )
1122export class ApiModule {
12- static forRoot(apiImplementations: ApiImplementations ): DynamicModule {
23+ static forRoot(configuration: ApiModuleConfiguration ): DynamicModule {
1324 const providers: Provider[] = [
1425{{#apiInfo} }
1526{ {#apis} }
1627 {
1728 provide: {{classname} },
18- useClass: apiImplementations.{ {#lambda.camelcase} }{ {classname} }{ {/lambda.camelcase} }
29+ useClass: configuration. apiImplementations.{ {#lambda.camelcase} }{ {classname} }{ {/lambda.camelcase} }
1930 },
2031{ {/apis} }
2132{ {/apiInfo} }
33+ ...(configuration.providers || []),
2234 ];
2335
2436 return {
Original file line number Diff line number Diff line change @@ -7,22 +7,34 @@ import { StoreApiController } from './controllers';
77import { UserApi } from './api' ;
88import { UserApiController } from './controllers' ;
99
10+ export type ApiModuleConfiguration = {
11+ /**
12+ * your Api implementations
13+ */
14+ apiImplementations : ApiImplementations ,
15+ /**
16+ * additional Providers that may be used by your implementations
17+ */
18+ providers ?: Provider [ ] ,
19+ }
20+
1021@Module ( { } )
1122export class ApiModule {
12- static forRoot ( apiImplementations : ApiImplementations ) : DynamicModule {
23+ static forRoot ( configuration : ApiModuleConfiguration ) : DynamicModule {
1324 const providers : Provider [ ] = [
1425 {
1526 provide : PetApi ,
16- useClass : apiImplementations . petApi
27+ useClass : configuration . apiImplementations . petApi
1728 } ,
1829 {
1930 provide : StoreApi ,
20- useClass : apiImplementations . storeApi
31+ useClass : configuration . apiImplementations . storeApi
2132 } ,
2233 {
2334 provide : UserApi ,
24- useClass : apiImplementations . userApi
35+ useClass : configuration . apiImplementations . userApi
2536 } ,
37+ ...( configuration . providers || [ ] ) ,
2638 ] ;
2739
2840 return {
Original file line number Diff line number Diff line change 1+ import { Injectable } from '@nestjs/common' ;
2+
3+ @Injectable ( )
4+ export class TestService {
5+ hello ( ) : string {
6+ return "Hello World" ;
7+ }
8+ }
Original file line number Diff line number Diff line change @@ -3,14 +3,18 @@ import { PetService } from './handlers/PetService';
33import { UserService } from './handlers/UserService' ;
44import { StoreService } from './handlers/StoreService' ;
55import { ApiModule } from '../builds/default' ;
6+ import { TestService } from './TestService' ;
67
78@Module ( {
89 imports : [
910 ApiModule . forRoot ( {
10- petApi : PetService ,
11- userApi : UserService ,
12- storeApi : StoreService ,
13- } ) ,
11+ apiImplementations : {
12+ petApi : PetService ,
13+ userApi : UserService ,
14+ storeApi : StoreService ,
15+ } ,
16+ providers : [ TestService ]
17+ } ) ,
1418 ] ,
1519 controllers : [ ] ,
1620 providers : [ ] ,
Original file line number Diff line number Diff line change @@ -3,9 +3,13 @@ import { Observable } from 'rxjs';
33import { Injectable } from '@nestjs/common' ;
44import { PetApi } from '../../builds/default/api' ;
55import { ApiResponse , Pet } from '../../builds/default/models' ;
6+ import { TestService } from '../TestService'
67
78@Injectable ( )
89export class PetService implements PetApi {
10+
11+ constructor ( private readonly testService : TestService ) { }
12+
913 addPet ( pet : Pet , request : Request ) : Pet | Promise < Pet > | Observable < Pet > {
1014 console . log ( JSON . stringify ( pet ) ) ;
1115 return pet ;
You can’t perform that action at this time.
0 commit comments