Implement multipart body support in sttp stub
Multipart support was never added to the stub: https://github.com/softwaremill/tapir/blob/abeb5d72e4e7a16c4da3830a59eb58862dfda69b/server/sttp-stub-server/src/main/scala/sttp/tapir/server/stub/SttpRequestBody.scala#L49
This makes it impossible to test endpoints with multipart bodies.
Originally posted by @adamw in https://github.com/softwaremill/tapir/issues/3895#issuecomment-2208480834
/bounty $500
~~## π $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 bounty β’ Share 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 |
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 |
@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.
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 submitted a pull request that claims the bounty. You can visit your bounty board to reward.
@abdelfetah18: You've been awarded a $500 bounty by softwaremill! π Complete your Algora onboarding to collect the bounty.