Skip to content

Commit 2b5306f

Browse files
openapi-generator: update article for 2026 (#41)
- BookMonkey 6 → BookManager 1, api6 → api1 - Remove provideHttpClient() (no longer required) - Remove provideApi() snapshot warning (stable since 7.14.0) - Remove importProvidersFrom workaround section - Remove NgModule from feature list, standalone: true - Update generator version 7.13.0 → 7.19.0 - Update rxResource experimental status to Angular 21 - Add bio sections for Angular book and workshops - Add lastModified date
1 parent 2a9dc77 commit 2b5306f

1 file changed

Lines changed: 28 additions & 58 deletions

File tree

blog/2025-06-openapi-generator/README.md

Lines changed: 28 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
title: "Generating Angular API clients with OpenAPI Generator"
33
author: Johannes Hoppe
44
mail: johannes.hoppe@haushoppe-its.de
5+
bio: '<a href="https://angular-buch.com"><img src="https://angular-buch.com/assets/img/book-cover-v1m.png" alt="Angular-Buch Cover" style="float: right; margin-top: -60px; margin-right: 30px; max-width: 250px;"></a>This article complements the HTTP chapter of our new <b>Angular book</b> (in German language) by Ferdinand Malcher, Danny Koppenhagen and Johannes Hoppe, where we cover everything you need to know about HTTP communication with Angular. After four successful editions, we have rewritten the book from scratch – with modern syntax, compact and covering many new topics. The new book will be released in May 2026. More info at <a href="https://angular-buch.com" style="text-decoration: underline;"><b>angular-buch.com</b></a>'
6+
bioHeading: About the Angular book
7+
author2: Angular.Schule Team
8+
mail2: team@angular.schule
9+
bio2: '<a href="https://angular.schule"><img src="/img/logo-angular-schule-gradient-550.png" alt="Angular.Schule Logo" style="float: right; margin-left: 30px; margin-top: -10px; margin-right: 30px; max-width: 250px;"></a>Want to integrate OpenAPI into your Angular workflow? Join Ferdinand Malcher and Johannes Hoppe in our workshops, where you learn Angular the practical way – including API integration with OpenAPI Generator. More at <a href="https://angular.schule" style="text-decoration: underline;"><b>angular.schule</b></a>'
10+
bio2Heading: About our Angular workshops
511
published: 2025-06-18
12+
lastModified: 2026-02-15
613
keywords:
714
- OpenAPI
815
- OpenAPI Generator
@@ -75,16 +82,16 @@ That's exactly what we want for a clean and reliable workflow.
7582
### Switching Code Generator Versions
7683

7784
To ensure consistent output across your team and avoid accidental diffs, it's a good idea to lock your project to a specific version of the OpenAPI Generator.
78-
Suppose you want to lock your project to version `7.13.0`.
85+
Suppose you want to lock your project to version `7.19.0`.
7986
You can do this by running:
8087

8188
```bash
82-
npx openapi-generator-cli version-manager set 7.13.0
89+
npx openapi-generator-cli version-manager set 7.19.0
8390
```
8491

8592
This will:
8693

87-
1. Download the `openapi-generator-cli-7.13.0.jar` file into your `node_modules` folder – so it shouldn't be under version control, since typically the local NPM files are never checked in.
94+
1. Download the `openapi-generator-cli-7.19.0.jar` file into your `node_modules` folder – so it shouldn't be under version control, since typically the local NPM files are never checked in.
8895
2. Record the version into the `openapitools.json` file.
8996

9097
To verify which version is currently active, run:
@@ -99,22 +106,19 @@ You can also use this mechanism to test new versions or roll back safely.
99106

100107
## Generating Your First Angular API Client
101108

102-
Before we take a look at the code, take a moment to explore [api6.angular-buch.com](https://api6.angular-buch.com/).
109+
Before we take a look at the code, take a moment to explore [api1.angular-buch.com](https://api1.angular-buch.com/).
103110

104-
This public REST API is part of the **BookMonkey 6** demo application, the updated companion project for the upcoming **5th edition** of our German Angular book.
105-
106-
107-
> 📘 Save the date!
108-
> The new edition is scheduled for **early 2026**.
109-
> Follow us on [angular.schule](https://www.angular.schule/) and our social media channels for updates!
111+
This public REST API is part of the **BookManager 1** demo application, the companion project for our new **Angular book** (in German language).
112+
After four successful editions, we have rewritten the book from scratch – with modern syntax, compact and covering many new topics.
113+
The new book will be released in **May 2026**. More info at [angular-buch.com](https://angular-buch.com).
110114

111115
To explore the API definition, simply open:
112116

113-
[OpenAPI Spec Viewer (Swagger UI)](https://api6.angular-buch.com/swagger-ui/)
117+
[OpenAPI Spec Viewer (Swagger UI)](https://api1.angular-buch.com/swagger-ui/)
114118

115119
This graphical interface is fully generated from the OpenAPI specification, located at:
116120

117-
`https://api6.angular-buch.com/openapi.json`
121+
`https://api1.angular-buch.com/openapi.json`
118122

119123
If this metadata is rich enough to render a complete admin UI, then it's clearly powerful enough to generate a fully functional Angular API client.
120124

@@ -128,9 +132,9 @@ We start with the most minimal setup:
128132

129133
```bash
130134
npx openapi-generator-cli generate \
131-
-i https://api6.angular-buch.com/openapi.json \
135+
-i https://api1.angular-buch.com/openapi.json \
132136
-g typescript-angular \
133-
-o ./src/app/shared/book-monkey-api
137+
-o ./src/app/shared/book-manager-api
134138
```
135139

136140
**Hint:** 💡 On Windows (Command Prompt), remove the backslashes and write the command in a single line.
@@ -150,11 +154,10 @@ These are the bare minimum arguments required.
150154
With this, you'll get:
151155

152156
- Typed Angular services for each REST resource
153-
- A full NgModule (`ApiModule`)
154157
- Models for all schemas (for example `book`, `author`, etc...)
155158
- `HttpClient`-based methods for every endpoint
156159

157-
> 🛠️ Pro Tip: Place the output directory somewhere inside your app's structure, but outside of actual components or routing. We suggest a path like `src/app/shared/book-monkey-api/`.
160+
> 🛠️ Pro Tip: Place the output directory somewhere inside your app's structure, but outside of actual components or routing. We suggest a path like `src/app/shared/book-manager-api/`.
158161
159162

160163
The CLI supports many more options.
@@ -176,34 +179,24 @@ This setup is fully compatible with Angular's standalone application structure:
176179
```ts
177180
// app.config.ts
178181
import { ApplicationConfig } from '@angular/core';
179-
import { provideHttpClient } from '@angular/common/http';
180-
import { provideApi } from './shared/book-monkey-api';
182+
import { provideApi } from './shared/book-manager-api';
181183

182184
export const appConfig: ApplicationConfig = {
183185
providers: [
184186
// [...]
185-
provideHttpClient(),
186187
provideApi()
187188
]
188189
};
189190
```
190191

191-
Don't forget to include `provideHttpClient()` to register Angular's `HttpClient` for injection.
192-
This is required, because the generated client uses `HttpClient` internally for every request.
193-
194-
> **IMPORTANT:** The `provideApi()` function is currently available only in the latest snapshot builds of OpenAPI Generator.
195-
It will become officially available with version **7.14.0**.
196-
197-
<!-- merken: https://raw.githubusercontent.com/jase88/openapi-generator/907ac1297454541107bc5e02442567eae3adee2b/modules/openapi-generator/src/main/resources/typescript-angular/README.mustache -->
198-
199192

200193
### Custom Base Path
201194

202195
If your API lives under a different domain or base path, you can pass a custom string.
203196
This is very helpful if you have different domains or paths for different development stages.
204197

205198
```ts
206-
provideApi('https://api6.angular-buch.com')
199+
provideApi('https://api1.angular-buch.com')
207200
```
208201

209202
### Full Configuration
@@ -223,17 +216,16 @@ provideApi({
223216
For dynamic configuration (e.g. based on an injected service), use Angular's `useFactory` syntax:
224217

225218
```ts
226-
import { Configuration } from './shared/book-monkey-api';
219+
import { Configuration } from './shared/book-manager-api';
227220

228221
export const appConfig: ApplicationConfig = {
229222
providers: [
230-
provideHttpClient(),
231223
{
232224
provide: Configuration,
233225
useFactory: () => {
234226
const authService = inject(AuthService);
235227
return new Configuration({
236-
basePath: 'https://api6.angular-buch.com',
228+
basePath: 'https://api1.angular-buch.com',
237229
username: authService.getUsername(),
238230
password: authService.getPassword()
239231
});
@@ -256,7 +248,7 @@ However, that approach is outside the scope of this article.
256248
If your project hasn't migrated to standalone yet, you can still use the traditional approach by importing the generated `ApiModule`:
257249

258250
```ts
259-
import { ApiModule } from './shared/book-monkey-api';
251+
import { ApiModule } from './shared/book-manager-api';
260252

261253
@NgModule({
262254
imports: [ApiModule.forRoot(() => new Configuration())]
@@ -267,27 +259,6 @@ export class AppModule {}
267259
That said, we highly recommend switching to `provideApi()` for all modern Angular projects.
268260

269261

270-
### Using the stable API until the next release
271-
272-
If you feel uncomfortable relying on a snapshot version, you can use the current stable API until version `7.14.0` is released.
273-
The function `importProvidersFrom()` extracts providers from an NgModule declaration so that we can pass them into our `providers` array.
274-
275-
```ts
276-
providers: [
277-
importProvidersFrom(
278-
ApiModule.forRoot(() =>
279-
new Configuration({
280-
basePath: 'https://api6.angular-buch.com'
281-
})
282-
)
283-
),
284-
// ...
285-
]
286-
```
287-
288-
This approach works reliably and only requires a one-time configuration in your `app.config.ts`.
289-
It can easily be replaced later on by `provideApi()`.
290-
291262

292263
## Integrating the generated service in your component
293264

@@ -299,7 +270,7 @@ import { JsonPipe } from '@angular/common';
299270
import { Component, inject } from '@angular/core';
300271
import { toSignal } from '@angular/core/rxjs-interop';
301272

302-
import { BooksService } from './shared/book-monkey-api';
273+
import { BooksService } from './shared/book-manager-api';
303274

304275
@Component({
305276
selector: 'app-root',
@@ -328,7 +299,7 @@ This modern pattern keeps your components fully reactive and simplifies state ha
328299

329300
## Modern Data Loading with `rxResource()`
330301

331-
Angular 19 introduced a new reactive primitive: `rxResource()` (still marked as *experimental* as of Angular 20).
302+
Angular 19 introduced a new reactive primitive: `rxResource()` (still marked as *experimental* as of Angular 21).
332303
It's designed to simplify the way we work with asynchronous data streams, especially when fetching data from an API.
333304

334305
Instead of manual subscription handling or conversion to signals (via `toSignal()` for example), `rxResource()` wraps our observable-based data source into a signal-friendly API.
@@ -343,11 +314,10 @@ import { JsonPipe } from '@angular/common';
343314
import { Component, inject } from '@angular/core';
344315
import { rxResource } from '@angular/core/rxjs-interop';
345316

346-
import { BooksService } from './shared/book-monkey-api';
317+
import { BooksService } from './shared/book-manager-api';
347318

348319
@Component({
349320
selector: 'app-root',
350-
standalone: true,
351321
imports: [JsonPipe],
352322
template: `<pre>{{ booksResource.value() | json }}</pre>`
353323
})
@@ -400,7 +370,7 @@ You've seen how to:
400370

401371
* install and lock the OpenAPI Generator for consistent output
402372
* generate TypeScript code directly from your OpenAPI spec,
403-
* set up the application using the new `provideApi()` syntax,
373+
* set up the application using the `provideApi()` syntax,
404374
* and consume your API with powerful Angular features like `toSignal()` and `rxResource()`.
405375

406376
With this setup, your API becomes a living contract, which automatically produces the client-side code you need.

0 commit comments

Comments
 (0)