smithy.api.Pattern.scala Maven / Gradle / Ivy
package smithy.api
import smithy4s.Hints
import smithy4s.Newtype
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.schema.Schema.bijection
import smithy4s.schema.Schema.recursive
import smithy4s.schema.Schema.string
/** Restricts string shape values to a specified regular expression. */
object Pattern extends Newtype[String] {
val id: ShapeId = ShapeId("smithy.api", "pattern")
val hints: Hints = Hints(
smithy.api.Documentation("Restricts string shape values to a specified regular expression."),
smithy.api.Trait(selector = Some(":test(string, member > string)"), structurallyExclusive = None, conflicts = None, breakingChanges = Some(List(smithy.api.TraitDiffRule(change = smithy.api.TraitChangeType.ADD.widen, severity = smithy.api.Severity.WARNING.widen, path = None, message = Some("The @pattern trait should only be added if the string already had adhered to the pattern.")), smithy.api.TraitDiffRule(change = smithy.api.TraitChangeType.UPDATE.widen, severity = smithy.api.Severity.NOTE.widen, path = None, message = Some("Changes to the @pattern trait should generally make the string more permissive, not less."))))),
).lazily
val underlyingSchema: Schema[String] = string.withId(id).addHints(hints)
implicit val schema: Schema[Pattern] = recursive(bijection(underlyingSchema, asBijection))
}