-
-
Notifications
You must be signed in to change notification settings - Fork 529
Add client option to pass custom RequestInit object into fetch requests for supported implementations #2020
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
Conversation
…ts for supported implementations
🦋 Changeset detectedLatest commit: f5a3b41 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…ts for supported implementations - formatting
…ts for supported implementations - formatting
…ts for supported implementations - fix e2e test failures
I’m on board with trying that. Currently the problem with using the 2nd parameter approach is we found out that the Fortunately we added tests to catch this that does catch some gamebreaking regressions from happening again, but taking a 2nd look over everything I’m not confident we have all the tests in place (will work on adding that). All that said, for now, we’re somewhat stuck with the single-param fetch API of Sorry for the extra context; this just overlaps several other APIs/behavior, and past regressions, so I wanted to spend a little more thought on it.
To previous point, the CustomRequest type extends the built-in Request class, and though it does allow for additional properties, is still a valid implementation of the fetch spec that works in Node.js and all browsers, and is tested and working. So any changes to the Originally posted by @drwpow in #1837 (comment) Thanks for the context. Correct me if I'm wrong, in the JS runtime calling fetch(Request, undefined) is essentially the same as calling fetch(Request) - so it should never break anything. This PR adds a check trying to do its best to determine we are running in a recent enough node version and otherwise resets the RequestInit object to undefined, assuming running within node.js account for 99% of use cases for this option. This check can be extended via contributions to accept other implementations as well. |
I noticed the tests have all been switched to passing in mocked responses, so the added real-world test may not pass muster. Any guidance on next steps to bring this closer to completion (if this feature is still desired) would be helpful - thanks! |
You have a very good point! I think you’re right. Thanks for taking the time to talk this over. Again, if we hadn’t shipped this bug in a previous version of openapi-fetch, I wouldn’t sweat it as much.
Hm yeah we do have a import express from 'express'
import { beforeAll, describe, expect, test } from 'vitest'
const API_PORT = process.env.API_PORT || 4578
const app = express();
app.get('/v1/my-endpoint', (req, res) => {
res.send(foo);
});
test('my test', async () => {
const client = createClient({ baseUrl: `http://localhost:${API_PORT}` });
// rest of test
}); That way it’s making actual |
As an aside, we were using Mock Service Worker for the longest time, but that was overkill, slowed tests down, and when we wanted to run performance benchmarks, MSW would cause them to flake. So we removed it. Again, not a requirement for this PR but after talking, I would like to improve our testing setup to test the surface area of native Node.js |
…ts for supported implementations - refactor test to use own server/endpoint
Done (thanks for the pointers!) - do we need a changeset and/or docs update or are we good? |
…ts for supported implementations - refactor test to use own server/endpoint
…ts for supported implementations - refactor test to use own server/endpoint
…ts for supported implementations - refactor test to use own server/endpoint
Yes a |
…ts for supported implementations - fix lockfile
…ts for supported implementations - add changeset
…ts for supported implementations - add changeset
Done. It's now complaining about a missing github token when building, I'm assuming this is to be fixed on the CI side, not related to this PR. Thanks! |
Oh shoot yes that was a change I made last night that needs to be fixed. Yes ignore that; that’s unrelated to this PR. |
Changes
What does this PR change? Link to any related issue(s).
#1837
#1631
How to Review
How can a reviewer review your changes? What should be kept in mind for this review?
Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)