alloy.DataExample.scala Maven / Gradle / Ivy
package alloy
import smithy4s.Document
import smithy4s.Hints
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.ShapeTag
import smithy4s.schema.Schema.bijection
import smithy4s.schema.Schema.document
import smithy4s.schema.Schema.union
sealed trait DataExample extends scala.Product with scala.Serializable { self =>
@inline final def widen: DataExample = this
def $ordinal: Int
object project {
def smithy: Option[Document] = DataExample.SmithyCase.alt.project.lift(self).map(_.smithy)
def json: Option[Document] = DataExample.JsonCase.alt.project.lift(self).map(_.json)
def string: Option[String] = DataExample.StringCase.alt.project.lift(self).map(_.string)
}
def accept[A](visitor: DataExample.Visitor[A]): A = this match {
case value: DataExample.SmithyCase => visitor.smithy(value.smithy)
case value: DataExample.JsonCase => visitor.json(value.json)
case value: DataExample.StringCase => visitor.string(value.string)
}
}
object DataExample extends ShapeTag.Companion[DataExample] {
def smithy(smithy: Document): DataExample = SmithyCase(smithy)
def json(json: Document): DataExample = JsonCase(json)
def string(string: String): DataExample = StringCase(string)
val id: ShapeId = ShapeId("alloy", "DataExample")
val hints: Hints = Hints.empty
final case class SmithyCase(smithy: Document) extends DataExample { final def $ordinal: Int = 0 }
final case class JsonCase(json: Document) extends DataExample { final def $ordinal: Int = 1 }
final case class StringCase(string: String) extends DataExample { final def $ordinal: Int = 2 }
object SmithyCase {
val hints: Hints = Hints.empty
val schema: Schema[DataExample.SmithyCase] = bijection(document.addHints(hints), DataExample.SmithyCase(_), _.smithy)
val alt = schema.oneOf[DataExample]("smithy")
}
object JsonCase {
val hints: Hints = Hints.empty
val schema: Schema[DataExample.JsonCase] = bijection(document.addHints(hints), DataExample.JsonCase(_), _.json)
val alt = schema.oneOf[DataExample]("json")
}
object StringCase {
val hints: Hints = Hints.empty
val schema: Schema[DataExample.StringCase] = bijection(smithy4s.schema.Schema.string.addHints(hints), DataExample.StringCase(_), _.string)
val alt = schema.oneOf[DataExample]("string")
}
trait Visitor[A] {
def smithy(value: Document): A
def json(value: Document): A
def string(value: String): A
}
object Visitor {
trait Default[A] extends Visitor[A] {
def default: A
def smithy(value: Document): A = default
def json(value: Document): A = default
def string(value: String): A = default
}
}
implicit val schema: Schema[DataExample] = union(
DataExample.SmithyCase.alt,
DataExample.JsonCase.alt,
DataExample.StringCase.alt,
){
_.$ordinal
}.withId(id).addHints(hints)
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy