Skip to content

Commit 952c8c7

Browse files
committed
docs: enhance README with badges, Quick Start, screenshots (Swagger + client wrapper) and feedback section
1 parent 4dd8cd1 commit 952c8c7

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

README.md

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# spring-boot-openapi-generics-clients
22

3+
![Java](https://img.shields.io/badge/Java-21-red)
4+
![Spring Boot](https://img.shields.io/badge/Spring%20Boot-3.4-green)
5+
![OpenAPI](https://img.shields.io/badge/OpenAPI-Generator-blue)
6+
![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
7+
38
**Type-safe client generation with Spring Boot & OpenAPI using generics.**
49
This repository demonstrates how to teach OpenAPI Generator to work with generics in order to avoid boilerplate, reduce duplicated wrappers, and keep client code clean.
510

@@ -9,6 +14,7 @@ This repository demonstrates how to teach OpenAPI Generator to work with generic
914

1015
Most backend teams standardize responses with a generic wrapper like `ApiResponse<T>`.
1116
However, **OpenAPI Generator does not natively support generics** — instead, it generates one wrapper per endpoint (duplicating fields like `status`, `message`, and `errors`).
17+
1218
This creates:
1319

1420
* ❌ Dozens of almost-identical classes
@@ -22,11 +28,57 @@ This creates:
2228
This project shows how to:
2329

2430
* Customize **Springdoc** to mark wrapper schemas in OpenAPI
25-
* Add a **tiny Mustache partial** to make the generator emit thin shells extending a reusable generic base
31+
* Add a **tiny Mustache partial** so the generator emits thin shells extending a reusable generic base
2632
* Keep **compile-time type safety** without repetitive mappers
2733

2834
---
2935

36+
## ⚡ Quick Start
37+
38+
Run the sample service:
39+
40+
```bash
41+
cd customer-service
42+
mvn spring-boot:run
43+
```
44+
45+
Generate and build the client:
46+
47+
```bash
48+
cd customer-service-client
49+
mvn clean install
50+
```
51+
52+
Use the generated API:
53+
54+
```java
55+
ApiClientResponse<CustomerCreateResponse> response =
56+
customerControllerApi.create(request);
57+
```
58+
59+
### 🖼 Demo Swagger Screenshot
60+
61+
Here’s what the `create customer` endpoint looks like in Swagger UI after running the service:
62+
63+
![Customer create demo](docs/images/swagger-customer-create.png)
64+
65+
### 🖼 Generated Client Wrapper
66+
67+
And here’s the corresponding generated client class showing the generic wrapper:
68+
69+
![Generated client wrapper](docs/images/generated-client-wrapper.png)
70+
71+
## 🛠 Tech Stack & Features
72+
73+
* 🚀 **Java 21** — modern language features
74+
* 🍃 **Spring Boot 3.4** — microservice foundation
75+
* 📖 **Springdoc OpenAPI** — API documentation
76+
* 🔧 **OpenAPI Generator 7.x** — client code generation
77+
* 🧩 **Custom Mustache templates** — generics-aware wrappers
78+
* 🧪 **JUnit 5 + MockWebServer** — integration testing
79+
80+
---
81+
3082
## 📂 Project Structure
3183

3284
```text
@@ -48,6 +100,28 @@ spring-boot-openapi-generics-clients/
48100

49101
---
50102

103+
## 🔍 Why This Matters
104+
105+
Without generics support, OpenAPI client generation creates bloated and repetitive code.
106+
By applying this approach:
107+
108+
* Development teams **save time** maintaining response models
109+
* Client libraries become **cleaner and smaller**
110+
* Easier for **new developers** to understand the contract
111+
* Code stays **future-proof** when envelope fields evolve
112+
113+
---
114+
115+
## 💼 Use Cases
116+
117+
This pattern is useful when:
118+
119+
* You have **multiple microservices** with a shared response structure
120+
* You need to **evolve response envelopes** without breaking dozens of generated classes
121+
* You want **type safety** in generated clients but without boilerplate
122+
123+
---
124+
51125
## 🔧 How to Run
52126

53127
1. **Start the sample service**
@@ -83,3 +157,15 @@ This repository is based on my article:
83157
## 🛡 License
84158

85159
MIT
160+
161+
---
162+
163+
**Note:** CLI examples should always be provided **on a single line**.
164+
If parameters include spaces or special characters, wrap them in quotes `"..."`.
165+
166+
---
167+
168+
## 💬 Feedback
169+
170+
If you spot any mistakes in this README or have questions about the project, feel free to open an issue or start a discussion.
171+
I’m happy to improve the documentation and clarify concepts further!
517 KB
Loading
318 KB
Loading

0 commit comments

Comments
 (0)