-
-
Notifications
You must be signed in to change notification settings - Fork 519
fix(mock,angular): Different response types causes issues #2674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(mock,angular): Different response types causes issues #2674
Conversation
65069ba to
f750262
Compare
|
PRs for fixing Axios and fetch and others would be awesome! |
|
The thing is i don't know if there are scenarios where it is breaking for fetch/axios. |
|
No worries this fix is great for Angular. |
…esponse content types
f750262 to
270e646
Compare
|
@melloware Than i would say i make it open for Review (atleast when this is the route we want to go). We still need to create Issues for the other generators (if you think that we need it there). :) |
|
@snebjorn if you want to review |
|
I am going to merge this so it can be in RC5 |
Summary
DRAFT
Fixes_partially #2243 - Angular client now properly handles OpenAPI endpoints with multiple response content types using function overloading.
Problem
When an OpenAPI endpoint defines multiple response content types (e.g.,
application/json,text/plain,application/xml), the Angular client generated a single method with a union return type but no way to specify which content type to request. Angular'sHttpClientrequiresresponseTypeto be set correctly at request time, causing runtime failures when non-JSON responses were returned.Additionally, MSW mock imports were incorrectly dropped when
text/plainwas present among content types.Solution
Angular Generator (
@orval/angular)acceptparameter typed to a specific content type literalresponseTypeis dynamically set based on theAcceptheader:jsonfor JSON content typestextfor text/* and XML content typesblobfor binary content typesapplication/json> any+jsontype > first in listMSW Mock Generator (
@orval/mock)text/plainis among content typesCore Utilities (
@orval/core)getDefaultContentType()utility for consistent default selection across generatorsGenerated Code Example
Breaking Changes
None. This is additive - existing code using singular content type endpoints works unchanged.
Future Work
( I can try also to do this if you want )
@orval/axios)@orval/fetch)AcceptheaderTesting
angular-appregenerated and buildsAcceptheaders and response parsing