alloy.StructurePattern.scala Maven / Gradle / Ivy
package alloy
import smithy4s.Hints
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.ShapeTag
import smithy4s.schema.Schema.recursive
import smithy4s.schema.Schema.string
import smithy4s.schema.Schema.struct
final case class StructurePattern(pattern: String, target: ShapeId)
object StructurePattern extends ShapeTag.Companion[StructurePattern] {
val id: ShapeId = ShapeId("alloy", "structurePattern")
val hints: Hints = Hints(
smithy.api.Trait(selector = Some("string"), structurallyExclusive = None, conflicts = None, breakingChanges = None),
).lazily
// constructor using the original order from the spec
private def make(pattern: String, target: ShapeId): StructurePattern = StructurePattern(pattern, target)
implicit val schema: Schema[StructurePattern] = recursive(struct(
string.required[StructurePattern]("pattern", _.pattern),
string.refined[ShapeId](smithy.api.IdRef(selector = "structure", failWhenMissing = None, errorMessage = None)).required[StructurePattern]("target", _.target),
)(make).withId(id).addHints(hints))
}