openapi-typescript icon indicating copy to clipboard operation
openapi-typescript copied to clipboard

fix(#1977): refactor handling for empty responses

Open DjordyKoert opened this issue 1 year ago • 7 comments

Changes

This PR includes a couple of different changes for openapi-fetch:

  • A refactor (Breaking change?) to ensure the behaviour of data and error are the same to reduce complexity. As an example, this means that whenever a user uses the parseAs: 'stream' both the data and error property will return a ReadableStream from response.body
  • The logic for empty response bodies has been changed:
    • It no longer explicity checks for 204 status to determine if a response is empty
    • It now follows the spec by checking if response.body is null
      • Backwards compatibality with browsers: empty string ('') get converted to undefined after failing to parse it as json (fixes https://github.com/openapi-ts/openapi-typescript/issues/1977)

How to Review

See changes & tests

Checklist

  • [x] Unit tests updated
  • [ ] docs/ updated (if necessary)
  • [ ] pnpm run update:examples run (only applicable for openapi-typescript)

DjordyKoert avatar Nov 05 '24 13:11 DjordyKoert