Skip to content

Commit

Permalink
remove validation on body for NoContent/NotModified (#3785)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahOdin authored May 26, 2024
1 parent d70cbec commit a5cd50d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ class ServerInterpreter[R, F[_], B, S](

val headers = outputValues.headers
(statusCode, outputValues.body) match {
case (StatusCode.NoContent | StatusCode.NotModified, Some(_)) =>
monad.error(new IllegalStateException(s"Unexpected response body when status code == $statusCode"))
case (_, Some(bodyFromHeaders)) => ServerResponse(statusCode, headers, Some(bodyFromHeaders(Headers(headers))), Some(output)).unit
case (_, None) => ServerResponse(statusCode, headers, None: Option[B], Some(output)).unit
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,41 +844,6 @@ class ServerBasicTests[F[_], OPTIONS, ROUTE](
r.code shouldBe StatusCode.InternalServerError
r.body shouldBe Symbol("left")
}
},
testServer(
"fail when status is 204 or 304, but there's a body",
NonEmptyList.of(
route(
List(
endpoint.in("no_content").out(jsonBody[Unit]).out(statusCode(StatusCode.NoContent)).serverLogicSuccess[F](_ => pureResult(())),
endpoint
.in("not_modified")
.out(jsonBody[Unit])
.out(statusCode(StatusCode.NotModified))
.serverLogicSuccess[F](_ => pureResult(())),
endpoint
.in("one_of")
.in(query[String]("select_err"))
.errorOut(
sttp.tapir.oneOf[ErrorInfo](
oneOfVariant(statusCode(StatusCode.NotFound).and(jsonBody[NotFound])),
oneOfVariant(statusCode(StatusCode.NoContent).and(jsonBody[NoContentData]))
)
)
.serverLogic[F] { selectErr =>
if (selectErr == "no_content")
pureResult[F, Either[ErrorInfo, Unit]](Left(NoContentData("error")))
else
pureResult[F, Either[ErrorInfo, Unit]](Left(NotFound("error")))
}
)
)
)
) { (backend, baseUri) =>
basicRequest.get(uri"$baseUri/no_content").send(backend).map(_.code shouldBe StatusCode.InternalServerError) >>
basicRequest.get(uri"$baseUri/not_modified").send(backend).map(_.code shouldBe StatusCode.InternalServerError) >>
basicRequest.get(uri"$baseUri/one_of?select_err=no_content").send(backend).map(_.code shouldBe StatusCode.InternalServerError) >>
basicRequest.get(uri"$baseUri/one_of?select_err=not_found").send(backend).map(_.code shouldBe StatusCode.NotFound)
}
)

Expand Down

0 comments on commit a5cd50d

Please sign in to comment.