openapi-typescript
openapi-typescript copied to clipboard
fix(#1977): refactor handling for empty responses
Changes
This PR includes a couple of different changes for openapi-fetch:
- A refactor (Breaking change?) to ensure the behaviour of
dataanderrorare the same to reduce complexity. As an example, this means that whenever a user uses theparseAs: 'stream'both thedataanderrorproperty will return aReadableStreamfromresponse.body - The logic for empty response bodies has been changed:
- It no longer explicity checks for
204status to determine if a response is empty - It now follows the spec by checking if
response.bodyis null- Backwards compatibality with browsers: empty string (
'') get converted toundefinedafter failing to parse it asjson(fixes https://github.com/openapi-ts/openapi-typescript/issues/1977)
- Backwards compatibality with browsers: empty string (
- It no longer explicity checks for
How to Review
See changes & tests
Checklist
- [x] Unit tests updated
- [ ]
docs/updated (if necessary) - [ ]
pnpm run update:examplesrun (only applicable for openapi-typescript)