Skip to content

Commit

Permalink
Simpler optic implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
danslapman committed Mar 10, 2024
1 parent b64cd38 commit e0a3cc6
Showing 1 changed file with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,13 @@ object HttpStubResponse {
TapirConfig.default.withDiscriminator("mode").copy(toEncodedName = modes)

val headers: Property[HttpStubResponse, Map[String, String]] =
new Property[HttpStubResponse, Map[String, String]] {
private val properties: Vector[Property[HttpStubResponse, Map[String, String]]] = Vector(
EmptyResponse.prism >> EmptyResponse.headers,
RawResponse.prism >> RawResponse.headers,
JsonResponse.prism >> JsonResponse.headers,
XmlResponse.prism >> XmlResponse.headers,
BinaryResponse.prism >> BinaryResponse.headers
)

override def set(s: HttpStubResponse, b: Map[String, String]): HttpStubResponse =
properties.map(_.setF(b)).reduce(_ andThen _).apply(s)

override def narrow(s: HttpStubResponse): Either[HttpStubResponse, Map[String, String]] =
properties.map(_.narrow(s)).foldLeft(s.asLeft[Map[String, String]])(_ orElse _)
}
Vector(
EmptyResponse.prism >> EmptyResponse.headers,
RawResponse.prism >> RawResponse.headers,
JsonResponse.prism >> JsonResponse.headers,
XmlResponse.prism >> XmlResponse.headers,
BinaryResponse.prism >> BinaryResponse.headers
).reduce[Property[HttpStubResponse, Map[String, String]]](_ orElse _)

val jsonBody: Property[HttpStubResponse, Json] = JsonResponse.prism >> JsonResponse.body

Expand Down

0 comments on commit e0a3cc6

Please sign in to comment.