scala.smithy.rules.EndpointTestExpectation.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kinesis4cats-smithy4s-client_3 Show documentation
Show all versions of kinesis4cats-smithy4s-client_3 Show documentation
Cats tooling for the Smithy4s Kinesis Client
package smithy.rules
import smithy4s.Hints
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.ShapeTag
import smithy4s.schema.Schema.bijection
import smithy4s.schema.Schema.string
import smithy4s.schema.Schema.union
/** An endpoint rule-set test expectation describing an expected endpoint or error. */
sealed trait EndpointTestExpectation extends scala.Product with scala.Serializable { self =>
@inline final def widen: EndpointTestExpectation = this
def $ordinal: Int
object project {
def error: Option[String] = EndpointTestExpectation.ErrorCase.alt.project.lift(self).map(_.error)
def endpoint: Option[EndpointExpectation] = EndpointTestExpectation.EndpointCase.alt.project.lift(self).map(_.endpoint)
}
def accept[A](visitor: EndpointTestExpectation.Visitor[A]): A = this match {
case value: EndpointTestExpectation.ErrorCase => visitor.error(value.error)
case value: EndpointTestExpectation.EndpointCase => visitor.endpoint(value.endpoint)
}
}
object EndpointTestExpectation extends ShapeTag.Companion[EndpointTestExpectation] {
/** A test case expectation resulting in an error. */
def error(error: String): EndpointTestExpectation = ErrorCase(error)
/** A test case expectation resulting in an endpoint. */
def endpoint(endpoint: EndpointExpectation): EndpointTestExpectation = EndpointCase(endpoint)
val id: ShapeId = ShapeId("smithy.rules", "EndpointTestExpectation")
val hints: Hints = Hints(
smithy.api.Documentation("An endpoint rule-set test expectation describing an expected endpoint or error."),
smithy.api.Unstable(),
smithy.api.Private(),
)
/** A test case expectation resulting in an error. */
final case class ErrorCase(error: String) extends EndpointTestExpectation { final def $ordinal: Int = 0 }
/** A test case expectation resulting in an endpoint. */
final case class EndpointCase(endpoint: EndpointExpectation) extends EndpointTestExpectation { final def $ordinal: Int = 1 }
object ErrorCase {
val hints: Hints = Hints(
smithy.api.Documentation("A test case expectation resulting in an error."),
)
val schema: Schema[EndpointTestExpectation.ErrorCase] = bijection(string.addHints(hints), EndpointTestExpectation.ErrorCase(_), _.error)
val alt = schema.oneOf[EndpointTestExpectation]("error")
}
object EndpointCase {
val hints: Hints = Hints(
smithy.api.Documentation("A test case expectation resulting in an endpoint."),
)
val schema: Schema[EndpointTestExpectation.EndpointCase] = bijection(EndpointExpectation.schema.addHints(hints), EndpointTestExpectation.EndpointCase(_), _.endpoint)
val alt = schema.oneOf[EndpointTestExpectation]("endpoint")
}
trait Visitor[A] {
def error(value: String): A
def endpoint(value: EndpointExpectation): A
}
object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def error(value: String): A = default
def endpoint(value: EndpointExpectation): A = default
}
}
implicit val schema: Schema[EndpointTestExpectation] = union(
EndpointTestExpectation.ErrorCase.alt,
EndpointTestExpectation.EndpointCase.alt,
){
_.$ordinal
}.withId(id).addHints(hints)
}