Skip to content

Commit

Permalink
fallback to raw binary if no other input type is recognized
Browse files Browse the repository at this point in the history
  • Loading branch information
daghct committed Sep 27, 2024
1 parent 9a3d46b commit 6f0fc6b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/scala/scraml/libs/TapirSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,10 @@ final class TapirSupport(endpointsObjectName: String) extends LibrarySupport {
q"""
jsonBody[${context.anyTypeName}]
"""
case other =>
throw new IllegalArgumentException(s"unsupported input media type: $other")
case _ =>
q"""
rawBinaryBody[Any]
"""
}

q"""
Expand Down
5 changes: 5 additions & 0 deletions src/sbt-test/sbt-scraml/tapir/api/tapir-complex.raml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ types: !include types.raml
preamble:
description: Discrete selector for text to prefix greeting.
type: Preamble

get: # HTTP method declaration
queryParameters:
name?:
Expand All @@ -35,3 +36,7 @@ types: !include types.raml
200: # HTTP status code
body: # declare content of response
type: DataType
/upload:
post:
body:
image/png:
1 change: 1 addition & 0 deletions src/test/scala/scraml/libs/TapirSupportSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ final class TapirSupportSpec
| final case class GetGreetingByPreambleAndDelayParams(preamble: Preamble, delay: Int, name: Option[String] = None, repeat: Option[Int] = None, uppercase: Option[Boolean] = None)
| lazy val getGreetingByPreambleAndDelay = endpoint.get.in("greeting" / path[Preamble]("preamble") / path[Int]("delay")).in(query[Option[String]]("name") and query[Option[Int]]("repeat") and query[Option[Boolean]]("uppercase")).mapInTo[GetGreetingByPreambleAndDelayParams].out(jsonBody[DataType])
| }
| object Upload { lazy val postUpload = endpoint.post.in("upload").in(rawBinaryBody[Any]) }
| }
|}""".stripMargin.stripTrailingSpaces
)
Expand Down

0 comments on commit 6f0fc6b

Please sign in to comment.