-
-
Notifications
You must be signed in to change notification settings - Fork 529
feat: allow form data through default body serializer #1762
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
drwpow
merged 6 commits into
openapi-ts:main
from
thatsprettyfaroutman:feat-body-serializer-allow-formdata
Aug 1, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
59d3240
feat: allow form data through default body serializer
thatsprettyfaroutman 2d3418b
chore: lint
thatsprettyfaroutman 2a96476
test: send multipart/form-data with file
thatsprettyfaroutman f9b5657
docs: openapi-fetch changeset patch
thatsprettyfaroutman 724cd67
test: cast FormData to string instead of ts-ignore
thatsprettyfaroutman 0abd93c
chore: lint
thatsprettyfaroutman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"openapi-fetch": patch | ||
--- | ||
|
||
Allow FormData through defaultBodySerializer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How to get this to accept FormData?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh hm do we need to adjust the types here? Is there an improvement we could make in
packages/openapi-fetch/index.d.ts
forbody
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this will be tricky. This library’s whole purpose is to assert types for
body
based on your OpenAPI schema. https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-fetch/src/index.d.ts#L90We don’t want to always allow FormData as that would mess up some people’s code. So we want to conditionally allow FormData in some instances where it’s possible (e.g. not for GET). So we’ll need to surgically add FormData as a union into request bodies, but only when it may be possible/desired.
Given the complexity, I’m OK with merging this PR without that just to unblock the runtime, and the types can be tackled separately (sidenote: that’s why the runtime and types are separated—the type complexity isn’t possible to express with normal runtime code)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are your thoughts? Do you want to try and solve the type errors? Or merge by requiring manual overrides?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with merging now. I think letting FormData through the body serializer is a nice little addition in itself. Oh, I was wondering why the types are separated, that's very cool to know 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! Will merge.