Skip to content

Commit

Permalink
Rewrite givens to get rid of compatibility mode
Browse files Browse the repository at this point in the history
  • Loading branch information
danslapman committed Jan 6, 2025
1 parent ea7b51d commit 5637079
Show file tree
Hide file tree
Showing 21 changed files with 45 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import ru.tinkoff.tcb.mockingbird.model.BinaryResponse
import ru.tinkoff.tcb.mockingbird.model.ByteArray
import ru.tinkoff.tcb.mockingbird.model.HttpMethod
import ru.tinkoff.tcb.mockingbird.model.HttpStatusCodeRange
import ru.tinkoff.tcb.mockingbird.model.HttpStub
import ru.tinkoff.tcb.mockingbird.model.HttpStubResponse
import ru.tinkoff.tcb.mockingbird.model.JsonProxyResponse
import ru.tinkoff.tcb.mockingbird.model.MultipartRequestBody
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.tinkoff.tcb.mockingbird.api.request

import eu.timepit.refined.*
import eu.timepit.refined.auto.*
import eu.timepit.refined.numeric.*
import eu.timepit.refined.types.numeric.*
import eu.timepit.refined.types.string.NonEmptyString
Expand All @@ -18,7 +17,6 @@ import ru.tinkoff.tcb.mockingbird.model.GrpcStubResponse
import ru.tinkoff.tcb.mockingbird.model.Scope
import ru.tinkoff.tcb.predicatedsl.Keyword
import ru.tinkoff.tcb.predicatedsl.json.JsonPredicate
import ru.tinkoff.tcb.protocol.json.*
import ru.tinkoff.tcb.protocol.json.given
import ru.tinkoff.tcb.protocol.schema.*
import ru.tinkoff.tcb.utils.circe.optics.JsonOptic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.tinkoff.tcb.mockingbird.api.request

import eu.timepit.refined.*
import eu.timepit.refined.auto.*
import eu.timepit.refined.numeric.*
import eu.timepit.refined.types.numeric.*
import eu.timepit.refined.types.string.NonEmptyString
Expand All @@ -18,7 +17,6 @@ import ru.tinkoff.tcb.mockingbird.model.GrpcStubResponse
import ru.tinkoff.tcb.mockingbird.model.Scope
import ru.tinkoff.tcb.predicatedsl.Keyword
import ru.tinkoff.tcb.predicatedsl.json.JsonPredicate
import ru.tinkoff.tcb.protocol.json.*
import ru.tinkoff.tcb.protocol.json.given
import ru.tinkoff.tcb.protocol.schema.*
import ru.tinkoff.tcb.utils.circe.optics.JsonOptic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import ru.tinkoff.tcb.mockingbird.model.ScenarioOutput
import ru.tinkoff.tcb.mockingbird.model.Scope
import ru.tinkoff.tcb.mockingbird.model.SourceConfiguration
import ru.tinkoff.tcb.predicatedsl.Keyword
import ru.tinkoff.tcb.protocol.json.*
import ru.tinkoff.tcb.protocol.json.given
import ru.tinkoff.tcb.protocol.schema.*
import ru.tinkoff.tcb.utils.circe.optics.JsonOptic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import ru.tinkoff.tcb.mockingbird.model.HttpStubRequest
import ru.tinkoff.tcb.mockingbird.model.HttpStubResponse
import ru.tinkoff.tcb.mockingbird.model.Scope
import ru.tinkoff.tcb.predicatedsl.Keyword
import ru.tinkoff.tcb.protocol.json.*
import ru.tinkoff.tcb.protocol.json.given
import ru.tinkoff.tcb.protocol.schema.*
import ru.tinkoff.tcb.utils.circe.optics.JsonOptic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import ru.tinkoff.tcb.mockingbird.model.Scope
import ru.tinkoff.tcb.predicatedsl.Keyword
import ru.tinkoff.tcb.predicatedsl.json.JsonPredicate
import ru.tinkoff.tcb.protocol.bson.*
import ru.tinkoff.tcb.protocol.json.*
import ru.tinkoff.tcb.protocol.json.given
import ru.tinkoff.tcb.protocol.schema.*
import ru.tinkoff.tcb.utils.circe.optics.JsonOptic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import ru.tinkoff.tcb.mockingbird.model.Scope
import ru.tinkoff.tcb.mockingbird.model.SourceConfiguration
import ru.tinkoff.tcb.predicatedsl.Keyword
import ru.tinkoff.tcb.protocol.bson.*
import ru.tinkoff.tcb.protocol.json.*
import ru.tinkoff.tcb.protocol.json.given
import ru.tinkoff.tcb.protocol.schema.*
import ru.tinkoff.tcb.utils.circe.optics.JsonOptic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import ru.tinkoff.tcb.mockingbird.model.HttpStubResponse
import ru.tinkoff.tcb.mockingbird.model.Scope
import ru.tinkoff.tcb.predicatedsl.Keyword
import ru.tinkoff.tcb.protocol.bson.*
import ru.tinkoff.tcb.protocol.json.*
import ru.tinkoff.tcb.protocol.json.given
import ru.tinkoff.tcb.protocol.schema.*
import ru.tinkoff.tcb.utils.circe.optics.JsonOptic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package ru.tinkoff.tcb.mockingbird.grpc

import com.google.protobuf.InvalidProtocolBufferException
import eu.timepit.refined.*
import eu.timepit.refined.numeric.*
import io.circe.Json
import io.circe.ParsingFailure
import mouse.option.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import io.circe.Decoder
import io.circe.Encoder
import io.circe.Json
import io.circe.derivation.Configuration as CirceConfig
import io.circe.derivation.ConfiguredDecoder
import io.circe.derivation.ConfiguredEncoder
import io.circe.refined.*
import neotype.*
import oolong.bson.*
Expand All @@ -21,12 +19,11 @@ import sttp.tapir.codec.refined.*
import sttp.tapir.generic.Configuration as TapirConfig

import ru.tinkoff.tcb.circe.bson.*
import ru.tinkoff.tcb.protocol.bson.*
import ru.tinkoff.tcb.protocol.schema.*
import ru.tinkoff.tcb.utils.xml.XMLString

@BsonDiscriminator("mode")
sealed trait CallbackRequest derives BsonDecoder, BsonEncoder, ConfiguredDecoder, ConfiguredEncoder, Schema {
sealed trait CallbackRequest derives BsonDecoder, BsonEncoder {
def url: NonEmptyString
def method: HttpMethod
def headers: Map[String, String]
Expand All @@ -47,6 +44,10 @@ object CallbackRequest {
useDefaults = true,
discriminator = Some("mode")
)

given Encoder[CallbackRequest] = Encoder.AsObject.derivedConfigured
given Decoder[CallbackRequest] = Decoder.derivedConfigured
given Schema[CallbackRequest] = Schema.derived
}

final case class CallbackRequestWithoutBody(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import io.circe.Decoder
import io.circe.Encoder
import io.circe.Json
import io.circe.derivation.Configuration as CirceConfig
import io.circe.derivation.ConfiguredDecoder
import io.circe.derivation.ConfiguredEncoder
import io.circe.parser.parse
import oolong.bson.*
import oolong.bson.annotation.BsonDiscriminator
Expand All @@ -22,7 +20,7 @@ import ru.tinkoff.tcb.utils.circe.optics.JsonOptic
import ru.tinkoff.tcb.xpath.SXpath

@BsonDiscriminator("type")
sealed trait XmlExtractor derives BsonDecoder, BsonEncoder, ConfiguredDecoder, ConfiguredEncoder, Schema {
sealed trait XmlExtractor derives BsonDecoder, BsonEncoder {
def apply(node: NodeSeq): Option[Json]
}
object XmlExtractor {
Expand All @@ -37,6 +35,10 @@ object XmlExtractor {
useDefaults = true,
discriminator = Some("type")
)

given Encoder[XmlExtractor] = Encoder.AsObject.derivedConfigured
given Decoder[XmlExtractor] = Decoder.derivedConfigured
given Schema[XmlExtractor] = Schema.derived
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import io.circe.Decoder
import io.circe.Encoder
import io.circe.Json
import io.circe.derivation.Configuration as CirceConfig
import io.circe.derivation.ConfiguredDecoder
import io.circe.derivation.ConfiguredEncoder
import io.circe.refined.*
import oolong.bson.*
import oolong.bson.annotation.BsonDiscriminator
Expand All @@ -30,7 +28,7 @@ import ru.tinkoff.tcb.protocol.schema.*
import ru.tinkoff.tcb.utils.circe.optics.JsonOptic

@BsonDiscriminator("mode")
sealed trait GrpcStubResponse derives BsonDecoder, BsonEncoder, ConfiguredDecoder, ConfiguredEncoder, Schema {
sealed trait GrpcStubResponse derives BsonDecoder, BsonEncoder {
def delay: Option[FiniteDuration]
}

Expand All @@ -50,6 +48,10 @@ object GrpcStubResponse {
useDefaults = true,
discriminator = Some("mode")
)

given Encoder[GrpcStubResponse] = Encoder.AsObject.derivedConfigured
given Decoder[GrpcStubResponse] = Decoder.derivedConfigured
given Schema[GrpcStubResponse] = Schema.derived
}

final case class FillResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import io.circe.Encoder
import io.circe.Json
import io.circe.JsonObject
import io.circe.derivation.Configuration as CirceConfig
import io.circe.derivation.ConfiguredDecoder
import io.circe.derivation.ConfiguredEncoder
import io.circe.parser.parse
import neotype.*
import oolong.bson.*
Expand All @@ -36,7 +34,7 @@ import ru.tinkoff.tcb.utils.xml.SafeXML
import ru.tinkoff.tcb.utils.xml.XMLString

@BsonDiscriminator("mode")
sealed trait HttpStubRequest derives BsonDecoder, BsonEncoder, ConfiguredDecoder, ConfiguredEncoder, Schema {
sealed trait HttpStubRequest derives BsonDecoder, BsonEncoder {
def headers: Map[String, String]

def query: Map[JsonOptic, Map[Keyword.Json, Json]]
Expand Down Expand Up @@ -80,6 +78,10 @@ object HttpStubRequest {
useDefaults = true,
discriminator = Some("mode")
)

given Encoder[HttpStubRequest] = Encoder.AsObject.derivedConfigured
given Decoder[HttpStubRequest] = Decoder.derivedConfigured
given Schema[HttpStubRequest] = Schema.derived
}

final case class JsonRequest(
Expand Down Expand Up @@ -228,7 +230,7 @@ final case class RequestWithAnyBody(
}

@BsonDiscriminator("mode")
sealed trait RequestPart derives BsonDecoder, BsonEncoder, ConfiguredDecoder, ConfiguredEncoder, Schema {
sealed trait RequestPart derives BsonDecoder, BsonEncoder {
def headers: Map[String, String]

def checkHeaders(hs: Map[String, String]): Boolean =
Expand Down Expand Up @@ -266,6 +268,10 @@ object RequestPart {
useDefaults = true,
discriminator = Some("mode")
)

given Encoder[RequestPart] = Encoder.AsObject.derivedConfigured
given Decoder[RequestPart] = Decoder.derivedConfigured
given Schema[RequestPart] = Schema.derived
}

final case class AnyContentPart(headers: Map[String, String]) extends RequestPart {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import io.circe.Decoder
import io.circe.Encoder
import io.circe.Json
import io.circe.derivation.Configuration as CirceConfig
import io.circe.derivation.ConfiguredDecoder
import io.circe.derivation.ConfiguredEncoder
import io.circe.refined.*
import neotype.*
import oolong.bson.*
Expand All @@ -36,7 +34,7 @@ import ru.tinkoff.tcb.utils.xml.XMLString
import ru.tinkoff.tcb.xpath.SXpath

@BsonDiscriminator("mode")
sealed trait HttpStubResponse derives BsonDecoder, BsonEncoder, ConfiguredDecoder, ConfiguredEncoder, Schema {
sealed trait HttpStubResponse derives BsonDecoder, BsonEncoder {
def delay: Option[FiniteDuration]
def isTemplate: Boolean
}
Expand All @@ -61,6 +59,10 @@ object HttpStubResponse {
discriminator = Some("mode")
)

given Encoder[HttpStubResponse] = Encoder.AsObject.derivedConfigured
given Decoder[HttpStubResponse] = Decoder.derivedConfigured
given Schema[HttpStubResponse] = Schema.derived

val headers: Property[HttpStubResponse, Map[String, String]] =
Vector(
EmptyResponse.prism >> EmptyResponse.headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import ru.tinkoff.tcb.protocol.schema.*
import ru.tinkoff.tcb.utils.xml.SafeXML
import ru.tinkoff.tcb.utils.xml.XMLString

sealed trait ResponseSpec derives BsonDecoder, BsonEncoder, ConfiguredDecoder, ConfiguredEncoder, Schema {
sealed trait ResponseSpec derives BsonDecoder, BsonEncoder {
val code: Option[Int]
def checkBody(data: String): Boolean
}
Expand All @@ -44,6 +44,10 @@ object ResponseSpec {
useDefaults = true,
discriminator = Some("mode")
)

given Encoder[ResponseSpec] = Encoder.AsObject.derivedConfigured
given Decoder[ResponseSpec] = Decoder.derivedConfigured
given Schema[ResponseSpec] = Schema.derived
}

final case class RawResponseSpec(code: Option[Int], body: Option[String]) extends ResponseSpec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import io.circe.Decoder
import io.circe.Encoder
import io.circe.Json
import io.circe.derivation.Configuration as CirceConfig
import io.circe.derivation.ConfiguredDecoder
import io.circe.derivation.ConfiguredEncoder
import io.circe.parser.parse
import neotype.*
import oolong.bson.*
Expand All @@ -26,7 +24,7 @@ import ru.tinkoff.tcb.utils.xml.SafeXML
import ru.tinkoff.tcb.utils.xml.XMLString

@BsonDiscriminator("mode")
sealed trait ScenarioInput derives BsonDecoder, BsonEncoder, ConfiguredDecoder, ConfiguredEncoder, Schema {
sealed trait ScenarioInput derives BsonDecoder, BsonEncoder {
def checkMessage(message: String): Boolean

def extractJson(message: String): Option[Json]
Expand All @@ -50,6 +48,10 @@ object ScenarioInput {
useDefaults = true,
discriminator = Some("mode")
)

given Encoder[ScenarioInput] = Encoder.AsObject.derivedConfigured
given Decoder[ScenarioInput] = Decoder.derivedConfigured
given Schema[ScenarioInput] = Schema.derived
}

final case class RawInput(payload: String) extends ScenarioInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import io.circe.Decoder
import io.circe.Encoder
import io.circe.Json
import io.circe.derivation.Configuration as CirceConfig
import io.circe.derivation.ConfiguredDecoder
import io.circe.derivation.ConfiguredEncoder
import neotype.*
import oolong.bson.*
import oolong.bson.annotation.BsonDiscriminator
Expand All @@ -24,7 +22,7 @@ import ru.tinkoff.tcb.utils.transformation.xml.XmlTransformation
import ru.tinkoff.tcb.utils.xml.XMLString

@BsonDiscriminator("mode")
sealed trait ScenarioOutput derives BsonDecoder, BsonEncoder, ConfiguredDecoder, ConfiguredEncoder, Schema {
sealed trait ScenarioOutput derives BsonDecoder, BsonEncoder {
def delay: Option[FiniteDuration]
def isTemplate: Boolean
}
Expand All @@ -43,6 +41,10 @@ object ScenarioOutput {
useDefaults = true,
discriminator = Some("mode")
)

given Encoder[ScenarioOutput] = Encoder.AsObject.derivedConfigured
given Decoder[ScenarioOutput] = Decoder.derivedConfigured
given Schema[ScenarioOutput] = Schema.derived
}

final case class RawOutput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import ru.tinkoff.tcb.mockingbird.model.JsonOutput
import ru.tinkoff.tcb.mockingbird.model.MessageCallback
import ru.tinkoff.tcb.mockingbird.model.PersistentState
import ru.tinkoff.tcb.mockingbird.model.RawOutput
import ru.tinkoff.tcb.mockingbird.model.Scenario
import ru.tinkoff.tcb.mockingbird.model.ScenarioOutput
import ru.tinkoff.tcb.mockingbird.model.Scope
import ru.tinkoff.tcb.mockingbird.model.SourceConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package ru.tinkoff.tcb.mockingbird.scenario

import scala.xml.Node

import eu.timepit.refined.*
import eu.timepit.refined.numeric.*
import io.circe.Json
import mouse.option.*
import oolong.bson.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import ru.tinkoff.tcb.generic.RootOptionFields
import ru.tinkoff.tcb.predicatedsl.Keyword
import ru.tinkoff.tcb.predicatedsl.PredicateConstructionError
import ru.tinkoff.tcb.predicatedsl.json.JsonPredicate
import ru.tinkoff.tcb.protocol.bson.*
import ru.tinkoff.tcb.protocol.schema.*
import ru.tinkoff.tcb.utils.circe.optics.JLens
import ru.tinkoff.tcb.utils.webform.toJson
Expand Down
1 change: 0 additions & 1 deletion backend/project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ object Settings {
"-language:higherKinds",
"-language:implicitConversions",
"-release:11",
"-source:3.4",
"-unchecked",
"-Xmax-inlines", "64",
"-Ybackend-parallelism",
Expand Down

0 comments on commit 5637079

Please sign in to comment.