1- 1+ 22
3- ### Building
3+ This is a test spec
4+
5+ The version of the OpenAPI document: 1.0.0
6+
7+ ## Building
48
59To install the required dependencies and to build the typescript sources run:
6- ```
10+
11+ ``` console
712npm install
813npm run build
914```
1015
11- ### publishing
16+ ## Publishing
1217
13- First build the package then run ``` npm publish dist `` ` (don't forget to specify the ` dist ` folder!)
18+ First build the package then run ` npm publish dist ` (don't forget to specify the ` dist ` folder!)
1419
15- ### consuming
20+ ## Consuming
1621
1722Navigate to the folder of your consuming project and run one of next commands.
1823
1924_ published:_
2025
21- ```
26+ ``` console
2227npm install [email protected] --save 2328```
2429
2530_ without publishing (not recommended):_
2631
27- ```
32+ ``` console
2833npm install PATH_TO_GENERATED_PACKAGE/dist.tgz --save
2934```
3035
@@ -33,173 +38,126 @@ _It's important to take the tgz file, otherwise you'll get trouble with links on
3338_ using ` npm link ` :_
3439
3540In PATH_TO_GENERATED_PACKAGE/dist:
36- ```
41+
42+ ``` console
3743npm link
3844```
3945
4046In your project:
41- ```
47+
48+ ``` console
4249npm link additionalPropertiesTest
4350```
4451
4552__ Note for Windows users:__ The Angular CLI has troubles to use linked npm packages.
46- Please refer to this issue https://github.com/angular/angular-cli/issues/8284 for a solution / workaround.
53+ Please refer to this issue < https://github.com/angular/angular-cli/issues/8284 > for a solution / workaround.
4754Published packages are not effected by this issue.
4855
49-
50- #### General usage
56+ ### General usage
5157
5258In your Angular project:
5359
60+ ``` typescript
5461
55- ```
56- // without configuring providers
57- import { ApiModule } from 'additionalPropertiesTest';
58- import { HttpClientModule } from '@angular/common/http';
59-
60- @NgModule({
61- imports: [
62- ApiModule,
63- // make sure to import the HttpClientModule in the AppModule only,
64- // see https://github.com/angular/angular/issues/20575
65- HttpClientModule
66- ],
67- declarations: [ AppComponent ],
68- providers: [],
69- bootstrap: [ AppComponent ]
70- })
71- export class AppModule {}
72- ```
73-
74- ```
75- // configuring providers
76- import { ApiModule, Configuration, ConfigurationParameters } from 'additionalPropertiesTest';
77-
78- export function apiConfigFactory (): Configuration {
79- const params: ConfigurationParameters = {
80- // set configuration parameters here.
81- }
82- return new Configuration(params);
83- }
84-
85- @NgModule({
86- imports: [ ApiModule.forRoot(apiConfigFactory) ],
87- declarations: [ AppComponent ],
88- providers: [],
89- bootstrap: [ AppComponent ]
90- })
91- export class AppModule {}
92- ```
93-
94- ```
95- // configuring providers with an authentication service that manages your access tokens
96- import { ApiModule, Configuration } from 'additionalPropertiesTest';
62+ import { ApplicationConfig } from ' @angular/core' ;
63+ import { provideHttpClient } from ' @angular/common/http' ;
64+ import { provideApi } from ' additionalPropertiesTest' ;
9765
98- @NgModule({
99- imports: [ ApiModule ],
100- declarations: [ AppComponent ],
66+ export const appConfig: ApplicationConfig = {
10167 providers: [
102- {
103- provide: Configuration,
104- useFactory: (authService: AuthService) => new Configuration(
105- {
106- basePath: environment.apiUrl,
107- accessToken: authService.getAccessToken.bind(authService)
108- }
109- ),
110- deps: [AuthService],
111- multi: false
112- }
68+ // ...
69+ provideHttpClient (),
70+ provideApi ()
11371 ],
114- bootstrap: [ AppComponent ]
115- })
116- export class AppModule {}
117- ```
118-
72+ };
11973```
120- import { DefaultApi } from 'additionalPropertiesTest';
12174
122- export class AppComponent {
123- constructor(private apiGateway: DefaultApi) { }
124- }
75+ ** NOTE**
76+ If you're still using ` AppModule ` and haven't [ migrated] ( https://angular.dev/reference/migrations/standalone ) yet, you can still import an Angular module:
77+ ``` typescript
78+ import { ApiModule } from ' additionalPropertiesTest' ;
12579```
12680
127- Note: The ApiModule is restricted to being instantiated once app wide.
128- This is to ensure that all services are treated as singletons.
129-
130- #### Using multiple OpenAPI files / APIs / ApiModules
131- In order to use multiple ` ApiModules ` generated from different OpenAPI files,
132- you can create an alias name when importing the modules
133- in order to avoid naming conflicts:
134- ```
135- import { ApiModule } from 'my-api-path';
136- import { ApiModule as OtherApiModule } from 'my-other-api-path';
137- import { HttpClientModule } from '@angular/common/http';
81+ If different from the generated base path, during app bootstrap, you can provide the base path to your service.
13882
139- @NgModule({
140- imports: [
141- ApiModule,
142- OtherApiModule,
143- // make sure to import the HttpClientModule in the AppModule only,
144- // see https://github.com/angular/angular/issues/20575
145- HttpClientModule
146- ]
147- })
148- export class AppModule {
83+ ``` typescript
84+ import { ApplicationConfig } from ' @angular/core' ;
85+ import { provideHttpClient } from ' @angular/common/http' ;
86+ import { provideApi } from ' additionalPropertiesTest' ;
14987
150- }
88+ export const appConfig: ApplicationConfig = {
89+ providers: [
90+ // ...
91+ provideHttpClient (),
92+ provideApi (' http://localhost:9999' )
93+ ],
94+ };
15195```
15296
97+ ``` typescript
98+ // with a custom configuration
99+ import { ApplicationConfig } from ' @angular/core' ;
100+ import { provideHttpClient } from ' @angular/common/http' ;
101+ import { provideApi } from ' additionalPropertiesTest' ;
153102
154- ### Set service base path
155- If different than the generated base path, during app bootstrap, you can provide the base path to your service.
156-
157- ```
158- import { BASE_PATH } from 'additionalPropertiesTest';
159-
160- bootstrap(AppComponent, [
161- { provide: BASE_PATH, useValue: 'https://your-web-service.com' },
162- ]);
103+ export const appConfig: ApplicationConfig = {
104+ providers: [
105+ // ...
106+ provideHttpClient (),
107+ provideApi ({
108+ withCredentials: true ,
109+ username: ' user' ,
110+ password: ' password'
111+ })
112+ ],
113+ };
163114```
164- or
165115
166- ```
167- import { BASE_PATH } from 'additionalPropertiesTest';
116+ ``` typescript
117+ // with factory building a custom configuration
118+ import { ApplicationConfig } from ' @angular/core' ;
119+ import { provideHttpClient } from ' @angular/common/http' ;
120+ import { provideApi , Configuration } from ' additionalPropertiesTest' ;
168121
169- @NgModule({
170- imports: [],
171- declarations: [ AppComponent ],
172- providers: [ provide: BASE_PATH, useValue: 'https://your-web-service.com' ],
173- bootstrap: [ AppComponent ]
174- })
175- export class AppModule {}
122+ export const appConfig: ApplicationConfig = {
123+ providers: [
124+ // ...
125+ provideHttpClient (),
126+ {
127+ provide: Configuration ,
128+ useFactory : (authService : AuthService ) => new Configuration ({
129+ basePath: ' http://localhost:9999' ,
130+ withCredentials: true ,
131+ username: authService .getUsername (),
132+ password: authService .getPassword (),
133+ }),
134+ deps: [AuthService ],
135+ multi: false
136+ }
137+ ],
138+ };
176139```
177140
141+ ### Using multiple OpenAPI files / APIs
178142
179- #### Using @angular/cli
180- First extend your ` src/environments/*.ts ` files by adding the corresponding base path:
181-
182- ```
183- export const environment = {
184- production: false,
185- API_BASE_PATH: 'http://127.0.0.1:8080'
186- };
187- ```
143+ In order to use multiple APIs generated from different OpenAPI files,
144+ you can create an alias name when importing the modules
145+ in order to avoid naming conflicts:
188146
189- In the src/app/app.module.ts:
190- ```
191- import { BASE_PATH } from 'additionalPropertiesTest';
147+ ``` typescript
148+ import { provideApi as provideUserApi } from ' my-user-api-path' ;
149+ import { provideApi as provideAdminApi } from ' my-admin-api-path' ;
150+ import { HttpClientModule } from ' @angular/common/http' ;
192151import { environment } from ' ../environments/environment' ;
193152
194- @NgModule({
195- declarations: [
196- AppComponent
197- ],
198- imports: [ ],
199- providers: [{ provide: BASE_PATH, useValue: environment.API_BASE_PATH }],
200- bootstrap: [ AppComponent ]
201- })
202- export class AppModule { }
153+ export const appConfig: ApplicationConfig = {
154+ providers: [
155+ // ...
156+ provideHttpClient (),
157+ provideUserApi (environment .basePath ),
158+ provideAdminApi (environment .basePath ),
159+ ],
160+ };
203161```
204162
205163### Customizing path parameter encoding
@@ -215,6 +173,7 @@ pass an arrow-function or method-reference to the `encodeParam` property of the
215173(see [ General Usage] ( #general-usage ) above).
216174
217175Example value for use in your Configuration-Provider:
176+
218177``` typescript
219178new Configuration ({
220179 encodeParam : (param : Param ) => myFancyParamEncoder (param ),
0 commit comments