An endpoint with a raw multipart body input (.in(multipartBody)) provides a faulty parts list to the server logic. Accessing the part's body throws an exception:
java.lang.ClassCastException: class scala.collection.immutable.$colon$colon cannot be cast to class [B (scala.collection.immutable.$colon$colon is in unnamed module of loader sbt.internal.ScalaLibraryClassLoader @6a40987d; [B is in module java.base of loader 'bootstrap')
How to reproduce?
I have implemented a test that reproduces this issue here:
I believe this is caused by incorrect typing of MultipartCodec.Default codec' higher-level value.
The parts are typed as Seq[Part[Array[Byte]]] but the value in runtime is Seq[Part[Seq[Array[Byte]]]], because the codec is implemented with Codec.list(Codec.byteArray). Perhaps just adjusting the type of the codec would fix this.
Tapir version: 0.17.0-M10, 0.16.16
Scala version: 2.13.3
Describe the bug
An endpoint with a raw multipart body input (
.in(multipartBody)
) provides a faultyparts
list to the server logic. Accessing the part's body throws an exception:How to reproduce?
I have implemented a test that reproduces this issue here:
https://github.com/softwaremill/tapir/compare/bugfix/multipart-body?expand=1
Additional information
I believe this is caused by incorrect typing of
MultipartCodec.Default
codec' higher-level value. The parts are typed asSeq[Part[Array[Byte]]]
but the value in runtime isSeq[Part[Seq[Array[Byte]]]]
, because the codec is implemented withCodec.list(Codec.byteArray)
. Perhaps just adjusting the type of the codec would fix this.https://github.com/softwaremill/tapir/blob/master/core/src/main/scala/sttp/tapir/Codec.scala#L503-L506