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
{{ message }}
Repository navigation
Support endpoint with different responses for different status codes #328
This is from a large public sector project where we implement an api.
The open api yaml specifies different response types for response status 200 and 202 (either a search result or a notification that result is not yet available).
When generating rest controller interface for Spring, the openapi-processior blindly uses the model class for the 202 response.
I managed to get it somehow working by configuring the endpoint to use ResponseEntity as return type, but that needs a pretty hacky workaround:
BTW: OpenApiTools/openapi-generator handles this by using Object as generic type parameter.
That is fine, I think, even though I wish Java had TypeScript's union types.
yes, that is not so nice. Returning Object shouldn't be hard to do. Maybe a marker interface, like one-of, would be nice.
I played around a bit with result-style: all.
The idea behind this option was to use the success response type and ignore the error responses (which can throw). With all it will return Object as result type from the endpoint method.
This helps in this case too as long as any error response is described....
Unfortunately result-style: all is not fully implemented on the path level which breaks this workaround.
map:
result-style: allpaths:
/foo/{fooType}/search:
# unfortunately this does not work currentlyresult-style: all
The fallback workaround is to exclude the endpoint until I have fixed this.
It is still generating an interface ...ExcludedApi for reference. You can use it as template for manually creating an interface with a working method signature.
Activity
eekboom commentedon Mar 20, 2025
BTW: OpenApiTools/openapi-generator handles this by using
Objectas generic type parameter.That is fine, I think, even though I wish Java had TypeScript's union types.
hauner commentedon Mar 20, 2025
yes, that is not so nice. Returning
Objectshouldn't be hard to do. Maybe a marker interface, like one-of, would be nice.I played around a bit with
result-style: all.The idea behind this option was to use the success response type and ignore the error responses (which can throw). With
allit will returnObjectas result type from the endpoint method.This helps in this case too as long as any error response is described....
Unfortunately
result-style: allis not fully implemented on the path level which breaks this workaround.The fallback workaround is to
excludethe endpoint until I have fixed this.It is still generating an interface
...ExcludedApifor reference. You can use it as template for manually creating an interface with a working method signature.add test case (openapi-processor/openapi-processor-spring#328)
improve handling of different response types (openapi-processor/opena…
enable test case (openapi-processor/openapi-processor-spring#328)
hauner commentedon Apr 21, 2025
fixed in 2025.2, it can also generate marker interfaces for the result object if enabled.
Thanks for reporting!