tapir icon indicating copy to clipboard operation
tapir copied to clipboard

Implement multipart body support in sttp stub

Open urieli opened this issue 1 year ago β€’ 5 comments

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

urieli avatar Jul 04 '24 09:07 urieli

/bounty $500

adamw avatar Oct 16 '24 10:10 adamw

~~## πŸ’Ž $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

algora-pbc[bot] avatar Oct 16 '24 10:10 algora-pbc[bot]

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 avatar Oct 16 '24 12:10 asr2003

@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.

adamw avatar Oct 16 '24 19:10 adamw

/attempt #3902

Options

rathi-dev avatar Oct 17 '24 08:10 rathi-dev

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! :)

adamw avatar Oct 21 '24 10:10 adamw

/attempt #3902

Options

abdelfetah18 avatar Oct 24 '24 13:10 abdelfetah18

πŸ’‘ @abdelfetah18 submitted a pull request that claims the bounty. You can visit your bounty board to reward.

algora-pbc[bot] avatar Oct 24 '24 13:10 algora-pbc[bot]

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

algora-pbc[bot] avatar Nov 04 '24 09:11 algora-pbc[bot]

πŸŽ‰πŸŽˆ @abdelfetah18 has been awarded $500! 🎈🎊

algora-pbc[bot] avatar Nov 11 '24 11:11 algora-pbc[bot]