Skip to content

Prevent using request body before cloning it #1364

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

Merged
merged 2 commits into from
Oct 5, 2023

Conversation

alexdotpink
Copy link
Contributor

Changes

This PR aims to fix a bug where the library would read the response's body before cloning it, which would result in the cloned response having an empty body after being cloned (at least in Bun).

How to Review

This is a pretty minor fix, so I don't think there's any specific things to keep in mind when reviewing the changes.

Checklist

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

@changeset-bot
Copy link

changeset-bot bot commented Oct 5, 2023

⚠️ No Changeset found

Latest commit: 486188f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@drwpow
Copy link
Contributor

drwpow commented Oct 5, 2023

I’m in favor of this fix, but if this behavior is testable would it be possible to add a test (not actually loading Bun; just testing the desired behavior)? Or if not, maybe add a comment in the code explaining what to be aware of

@alexdotpink
Copy link
Contributor Author

i didn't think this would require tests or comments since it seems like a pretty trivial fix, but it being an edge case (if its really an issue with bun only) might warrant a comment. if you'd like, i can add a comment explaining why this is necessary.

@drwpow
Copy link
Contributor

drwpow commented Oct 5, 2023

The major reasons for tests or comments is preventing regressions, and this change is the type of change that probably wouldn’t last long because there’s no clear intent why a variable would be initialized without a value without any explanation. It almost seems like a fault of style than an intentional line of code. A comment could go a long way.

But that said, the more I think about this, the more I think having Bun tests (even just basic “does this work” tests) would be valuable in general, so I’ll probably set that up either way, which makes the request somewhat moot. But until then, yes, a comment would help immensely 🙏

@alexdotpink
Copy link
Contributor Author

let me know if this looks good to you!

@drwpow drwpow merged commit 27969ed into openapi-ts:main Oct 5, 2023
@drwpow
Copy link
Contributor

drwpow commented Oct 5, 2023

Looks great, thanks! Just the tip-off that this logic exists for Bun would prevent a future PR of someone unfamiliar with the code to change it without trying it in Bun first (hopefully). But again, will look into adding Bun tests.

@drwpow drwpow mentioned this pull request Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants