Show HN: Spring Boot and OpenAPI Generator – type-safe clients with generics

1 barissayli 0 9/15/2025, 4:22:17 AM github.com ↗
Many backend teams wrap API responses in a generic envelope (status, message, errors, data). However, OpenAPI Generator doesn’t natively support generics — it usually generates one wrapper class per endpoint, duplicating the same fields dozens of times.

I built a demo Spring Boot 3.4 microservice + OpenAPI 3.1 project that shows how to solve this with:

• A small Springdoc OpenApiCustomizer that tags wrapper schemas with vendor extensions • A tiny Mustache template override that generates thin shells extending a reusable generic base • Full CRUD example (create, get, update, delete) with type-safe client code • Integration tests using MockWebServer • HttpClient5 support for connection pooling and timeouts

Result: instead of dozens of duplicated wrappers, the generator emits a single reusable `ServiceClientResponse<T>` base + thin endpoint-specific shells. Client code stays clean, type-safe, and much easier to maintain.

GitHub repo (demo code): https://github.com/bsayli/spring-boot-openapi-generics-clien...

Detailed write-up (Medium article): https://medium.com/@baris.sayli/type-safe-generic-api-respon...

Would love feedback from the HN community

Comments (0)

No comments yet