Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove validation on body for NoContent/NotModified #3785

Merged
merged 3 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading