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

Add Scala 3 support to sttp-mock-server #3478

Merged
merged 3 commits into from
Jan 24, 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
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ lazy val sttpMockServer: ProjectMatrix = (projectMatrix in file("server/sttp-moc
"org.mock-server" % "mockserver-netty" % Versions.mockServer % Test
)
)
.jvmPlatform(scalaVersions = scala2Versions)
.jvmPlatform(scalaVersions = scala2And3Versions)
.dependsOn(serverCore, serverTests % "test", sttpClient)

lazy val finatraServer: ProjectMatrix = (projectMatrix in file("server/finatra-server"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package sttp.tapir.server.mockserver.impl

import io.circe.generic.codec.DerivedAsObjectCodec
import io.circe.{Codec, CursorOp, Decoder, DecodingFailure, Encoder, Json, JsonObject}
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.syntax._
import shapeless.Lazy
import io.circe.{CursorOp, Decoder, DecodingFailure, Encoder, Json, JsonObject}
import sttp.model.{MediaType, Method, StatusCode, Uri}
import sttp.tapir.server.mockserver.ExpectationBodyDefinition.JsonMatchType
import sttp.tapir.server.mockserver.{
Expand Down Expand Up @@ -83,19 +81,21 @@ private[mockserver] object JsonCodecs {
}
}

private def deriveCodecDropNull[A](implicit codec: Lazy[DerivedAsObjectCodec[A]]): Codec[A] =
Codec.from(codec.value, codec.value.mapJson(_.dropNullValues))

private implicit val expectationRequestDefinitionCodec: Codec[ExpectationRequestDefinition] =
deriveCodecDropNull[ExpectationRequestDefinition]
private implicit val expectationResponseDefinitionCodec: Codec[ExpectationResponseDefinition] =
deriveCodecDropNull[ExpectationResponseDefinition]
private implicit val expectationTimesCodec: Codec[ExpectationTimes] = deriveCodecDropNull[ExpectationTimes]
private implicit val expectationTimeToLiveCodec: Codec[ExpectationTimeToLive] = deriveCodecDropNull[ExpectationTimeToLive]
private implicit val verificationTimesDefinitionCodec: Codec[VerificationTimesDefinition] =
deriveCodecDropNull[VerificationTimesDefinition]
private implicit val expectationRequestDefinitionEncoder: Encoder[ExpectationRequestDefinition] =
deriveEncoder[ExpectationRequestDefinition].mapJson(_.dropNullValues)
private implicit val expectationResponseDefinitionEncoder: Encoder[ExpectationResponseDefinition] =
deriveEncoder[ExpectationResponseDefinition].mapJson(_.dropNullValues)
private implicit val verificationTimesDefinitionEncoder: Encoder[VerificationTimesDefinition] =
deriveEncoder[VerificationTimesDefinition].mapJson(_.dropNullValues)

implicit val createExpectationRequestEncoder: Encoder[CreateExpectationRequest] = deriveEncoder[CreateExpectationRequest]
implicit val verifyExpectationRequestEncoder: Encoder[VerifyExpectationRequest] = deriveEncoder[VerifyExpectationRequest]

private implicit val expectationRequestDefinitionDecoder: Decoder[ExpectationRequestDefinition] =
deriveDecoder[ExpectationRequestDefinition]
private implicit val expectationResponseDefinitionDecoder: Decoder[ExpectationResponseDefinition] =
deriveDecoder[ExpectationResponseDefinition]
private implicit val expectationTimesDecoder: Decoder[ExpectationTimes] = deriveDecoder[ExpectationTimes]
private implicit val expectationTimeToLiveDecoder: Decoder[ExpectationTimeToLive] = deriveDecoder[ExpectationTimeToLive]
implicit val expectationDecoder: Decoder[Expectation] = deriveDecoder[Expectation]
}
Loading