All Downloads are FREE. Search and download functionalities are using the official Maven repository.

smithy4s.smithy.rules.EndpointTestExpectation.scala Maven / Gradle / Ivy

The newest version!
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(),
  ).lazily

  /** 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."),
    ).lazily
    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."),
    ).lazily
    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)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy