You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(typescript-angular): add util "provideApi" and update docs to standalone applications (#21173)
* feat(angular): add util "provideApi" for standalone applications (Angular 17 and above)
* feat(angular): update README with new provideApi usage examples for Angular applications
* feat(angular): update README to reflect new provideApi import path and usage examples
* feat(angular): add support for README_beforeV17 and update provideApi return type
* feat(angular): add support for README_beforeV17 and update provideApi return type
* feat(angular): add support for README_beforeV17 and update provideApi return type
* fix: correct casing in DuplicateTest and FooDuplicateTest headers
* feat(angular): add provideApi function and update README with usage examples
Copy file name to clipboardExpand all lines: modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java
+22-9Lines changed: 22 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -176,30 +176,42 @@ public String getHelp() {
176
176
@Override
177
177
publicvoidprocessOpts() {
178
178
super.processOpts();
179
+
180
+
// determine NG version
181
+
SemVerngVersion;
182
+
if (additionalProperties.containsKey(NG_VERSION)) {
If you're still using `AppModule` and haven't [migrated](https://angular.dev/reference/migrations/standalone) yet, you can still import an Angular module:
124
77
```typescript
125
-
import { DefaultApi } from '{{npmName}}';
126
-
127
-
export class AppComponent {
128
-
constructor(private apiGateway: DefaultApi) { }
129
-
}
78
+
import { {{apiModuleClassName}} } from '{{npmName}}';
130
79
```
131
80
132
-
Note: The {{apiModuleClassName}} is restricted to being instantiated once app wide.
133
-
This is to ensure that all services are treated as singletons.
134
-
135
-
### Using multiple OpenAPI files / APIs / {{apiModuleClassName}}s
136
-
137
-
In order to use multiple `{{apiModuleClassName}}s` generated from different OpenAPI files,
138
-
you can create an alias name when importing the modules
139
-
in order to avoid naming conflicts:
81
+
If different from the generated base path, during app bootstrap, you can provide the base path to your service.
140
82
141
83
```typescript
142
-
import { {{apiModuleClassName}} } from 'my-api-path';
143
-
import { {{apiModuleClassName}} as OtherApiModule } from 'my-other-api-path';
144
-
import { HttpClientModule } from '@angular/common/http';
145
-
146
-
@NgModule({
147
-
imports: [
148
-
{{apiModuleClassName}},
149
-
OtherApiModule,
150
-
// make sure to import the HttpClientModule in the AppModule only,
151
-
// see https://github.com/angular/angular/issues/20575
152
-
HttpClientModule
153
-
]
154
-
})
155
-
export class AppModule {
84
+
import { ApplicationConfig } from '@angular/core';
85
+
import { provideHttpClient } from '@angular/common/http';
86
+
import { provideApi } from '{{npmName}}';
156
87
157
-
}
88
+
export const appConfig: ApplicationConfig = {
89
+
providers: [
90
+
// ...
91
+
provideHttpClient(),
92
+
provideApi('http://localhost:9999')
93
+
],
94
+
};
158
95
```
159
96
160
-
### Set service base path
161
-
162
-
If different than the generated base path, during app bootstrap, you can provide the base path to your service.
163
-
164
97
```typescript
165
-
import { BASE_PATH } from '{{npmName}}';
98
+
// with a custom configuration
99
+
import { ApplicationConfig } from '@angular/core';
100
+
import { provideHttpClient } from '@angular/common/http';
0 commit comments