OpenAPI generators break generic API responses

1 pointsposted 9 hours ago
by barissayli

1 Comments

barissayli

9 hours ago

I kept running into the same issue with OpenAPI-generated clients.

You define a simple generic response:

ServiceResponse<T>

But after client generation, generics are gone.

You get this instead:

ServiceResponseCustomerDto ServiceResponsePageCustomerDto ServiceResponseOrderDto

Each one duplicates the same fields, only changing the inner type.

After digging through Swagger/OpenAPI issues, this appears to be a structural limitation of the current tooling — OpenAPI describes schemas, not type systems.

I ended up treating OpenAPI as a projection layer and keeping a canonical generic contract outside of it.

How are you dealing with this in your clients?