Skip to content
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

Implement multipart body support in sttp stub #3902

Open
urieli opened this issue Jul 4, 2024 · 9 comments
Open

Implement multipart body support in sttp stub #3902

urieli opened this issue Jul 4, 2024 · 9 comments

Comments

@urieli
Copy link

urieli commented Jul 4, 2024

Multipart support was never added to the stub:

throw new IllegalArgumentException("Stub cannot handle multipart bodies")

This makes it impossible to test endpoints with multipart bodies.

Originally posted by @adamw in #3895 (comment)

@adamw
Copy link
Member

adamw commented Oct 16, 2024

/bounty $500

Copy link

algora-pbc bot commented Oct 16, 2024

💎 $500 bounty • SoftwareMill

Steps to solve:

  1. Start working: Comment /attempt #3902 with your implementation plan
  2. Submit work: Create a pull request including /claim #3902 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to softwaremill/tapir!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🟢 @asr2003 Oct 16, 2024, 12:59:11 PM WIP
🟢 @rathi-dev Oct 17, 2024, 8:45:21 AM WIP
🟢 @abdelfetah18 Oct 24, 2024, 1:15:25 PM #4117

@asr2003
Copy link

asr2003 commented Oct 16, 2024

Hey @adamw! I’d love to take a crack at adding multipart body support to the sttp stub. Here’s what I am thinking for the approach:

Right now, the code throws an exception for MultipartBody. My idea is to properly parse multipart bodies instead of the exception. I will iterate over the parts, handling text and files and convert them into something Tapir can understand like RawBodyType.MultipartBody.Part. Once we can parse the multipart, I think we can update toRaw to return the proper raw value. So when the body type is RawBodyType.MultipartBody, it will grab the parsed parts and wrap them in RawValue[Seq[RawBodyType.MultipartBody.Part]]

I will also create some test cases that include multipart bodies with both text and file parts.

Does this sound good? I will get started and push a PR soon if all looks good to you! With this,
/attempt #3902

Algora profile Completed bounties Tech Active attempts Options
@asr2003 6 bounties from 3 projects
Go, Scala,
Java & more
Cancel attempt

@adamw
Copy link
Member

adamw commented Oct 16, 2024

@asr2003 Hey, great to see your interest in the issue! :) I'm not sure doing full multipart serialisation & parsing will be necessary (unless I'm missing something), but maybe it will be enough to remain on a higher level. I think a great start would be to create (failing) tests which would demonstrate how people might use the feature: either directly via sttp-client, or by interpreting the endpoint as a client. This should probably be an extension to the existing testsuite. Then we might work out what exactly is missing to make this work.

@rathi-dev
Copy link

rathi-dev commented Oct 17, 2024

/attempt #3902

@adamw
Copy link
Member

adamw commented Oct 21, 2024

As we are getting first PRs for the bounties, I've published our "How to prepare a good PR" guide. I should have probably done this right away, sorry! :)

@abdelfetah18
Copy link
Contributor

abdelfetah18 commented Oct 24, 2024

/attempt #3902

Copy link

algora-pbc bot commented Oct 24, 2024

💡 @abdelfetah18 submitted a pull request that claims the bounty. You can visit your bounty board to reward.

Copy link

algora-pbc bot commented Nov 4, 2024

@abdelfetah18: You've been awarded a $500 bounty by softwaremill! 👉 Complete your Algora onboarding to collect the bounty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants