source: src/mapservice-webclient/src-gen/gnuboat-mapservice/README.md@ 9d40068

debian/bullseye
Last change on this file since 9d40068 was d660d75, checked in by Joachim Langenbach <joachim.langenbach@…>, 6 years ago

Added all generated code to the soruce tree, to avoid generation during package build time

  • Property mode set to 100644
File size: 4.4 KB
Line 
1## @
2
3### Building
4
5To install the required dependencies and to build the typescript sources run:
6```
7npm install
8npm run build
9```
10
11### publishing
12
13First build the package then run ```npm publish```
14
15### consuming
16
17Navigate to the folder of your consuming project and run one of next commands.
18
19_published:_
20
21```
22npm install @ --save
23```
24
25_without publishing (not recommended):_
26
27```
28npm install PATH_TO_GENERATED_PACKAGE/-.tgz --save
29```
30
31_It's important to take the tgz file, otherwise you'll get trouble with links on windows_
32
33_using `npm link`:_
34
35In PATH_TO_GENERATED_PACKAGE:
36```
37npm link
38```
39
40In your project:
41```
42npm link
43```
44
45__Note for Windows users:__ The Angular CLI has troubles to use linked npm packages.
46Please refer to this issue https://github.com/angular/angular-cli/issues/8284 for a solution / workaround.
47Published packages are not effected by this issue.
48
49
50#### General usage
51
52In your Angular project:
53
54
55```
56// without configuring providers
57import { ApiModule } from '';
58import { HttpClientModule } from '@angular/common/http';
59
60
61@NgModule({
62 imports: [
63 ApiModule,
64 // make sure to import the HttpClientModule in the AppModule only,
65 // see https://github.com/angular/angular/issues/20575
66 HttpClientModule
67 ],
68 declarations: [ AppComponent ],
69 providers: [],
70 bootstrap: [ AppComponent ]
71})
72export class AppModule {}
73```
74
75```
76// configuring providers
77import { ApiModule, Configuration, ConfigurationParameters } from '';
78
79export function apiConfigFactory (): Configuration => {
80 const params: ConfigurationParameters = {
81 // set configuration parameters here.
82 }
83 return new Configuration(params);
84}
85
86@NgModule({
87 imports: [ ApiModule.forRoot(apiConfigFactory) ],
88 declarations: [ AppComponent ],
89 providers: [],
90 bootstrap: [ AppComponent ]
91})
92export class AppModule {}
93```
94
95```
96// configuring providers with an authentication service that manages your access tokens
97import { ApiModule, Configuration } from '';
98
99@NgModule({
100 imports: [ ApiModule ],
101 declarations: [ AppComponent ],
102 providers: [
103 {
104 provide: Configuration,
105 useFactory: (authService: AuthService) => new Configuration(
106 {
107 basePath: environment.apiUrl,
108 accessToken: authService.getAccessToken.bind(authService)
109 }
110 ),
111 deps: [AuthService],
112 multi: false
113 }
114 ],
115 bootstrap: [ AppComponent ]
116})
117export class AppModule {}
118```
119
120```
121import { DefaultApi } from '';
122
123export class AppComponent {
124 constructor(private apiGateway: DefaultApi) { }
125}
126```
127
128Note: The ApiModule is restricted to being instantiated once app wide.
129This is to ensure that all services are treated as singletons.
130
131#### Using multiple OpenAPI files / APIs / ApiModules
132In order to use multiple `ApiModules` generated from different OpenAPI files,
133you can create an alias name when importing the modules
134in order to avoid naming conflicts:
135```
136import { ApiModule } from 'my-api-path';
137import { ApiModule as OtherApiModule } from 'my-other-api-path';
138import { HttpClientModule } from '@angular/common/http';
139
140
141@NgModule({
142 imports: [
143 ApiModule,
144 OtherApiModule,
145 // make sure to import the HttpClientModule in the AppModule only,
146 // see https://github.com/angular/angular/issues/20575
147 HttpClientModule
148 ]
149})
150export class AppModule {
151
152}
153```
154
155
156### Set service base path
157If different than the generated base path, during app bootstrap, you can provide the base path to your service.
158
159```
160import { BASE_PATH } from '';
161
162bootstrap(AppComponent, [
163 { provide: BASE_PATH, useValue: 'https://your-web-service.com' },
164]);
165```
166or
167
168```
169import { BASE_PATH } from '';
170
171@NgModule({
172 imports: [],
173 declarations: [ AppComponent ],
174 providers: [ provide: BASE_PATH, useValue: 'https://your-web-service.com' ],
175 bootstrap: [ AppComponent ]
176})
177export class AppModule {}
178```
179
180
181#### Using @angular/cli
182First extend your `src/environments/*.ts` files by adding the corresponding base path:
183
184```
185export const environment = {
186 production: false,
187 API_BASE_PATH: 'http://127.0.0.1:8080'
188};
189```
190
191In the src/app/app.module.ts:
192```
193import { BASE_PATH } from '';
194import { environment } from '../environments/environment';
195
196@NgModule({
197 declarations: [
198 AppComponent
199 ],
200 imports: [ ],
201 providers: [{ provide: BASE_PATH, useValue: environment.API_BASE_PATH }],
202 bootstrap: [ AppComponent ]
203})
204export class AppModule { }
205```
Note: See TracBrowser for help on using the repository browser.