smithy.api.TraitValidator.scala Maven / Gradle / Ivy
package smithy.api
import smithy4s.Hints
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.ShapeTag
import smithy4s.schema.Schema.string
import smithy4s.schema.Schema.struct
/** @param selector
* A Smithy selector that receives only the shape to which the `traitValidators` trait is applied.
* Any shape yielded by the selector is considered incompatible with the trait.
* @param message
* A message to use when a matching shape is found.
* @param severity
* The severity to use when a matching shape is found.
*/
final case class TraitValidator(selector: String, severity: Severity = smithy.api.Severity.ERROR.widen, message: Option[String] = None)
object TraitValidator extends ShapeTag.Companion[TraitValidator] {
val id: ShapeId = ShapeId("smithy.api", "TraitValidator")
val hints: Hints = Hints(
smithy.api.Private(),
).lazily
// constructor using the original order from the spec
private def make(selector: String, message: Option[String], severity: Severity): TraitValidator = TraitValidator(selector, severity, message)
implicit val schema: Schema[TraitValidator] = struct(
string.required[TraitValidator]("selector", _.selector).addHints(smithy.api.Documentation("A Smithy selector that receives only the shape to which the `traitValidators` trait is applied.\nAny shape yielded by the selector is considered incompatible with the trait.")),
string.optional[TraitValidator]("message", _.message).addHints(smithy.api.Documentation("A message to use when a matching shape is found.")),
Severity.schema.field[TraitValidator]("severity", _.severity).addHints(smithy.api.Documentation("The severity to use when a matching shape is found."), smithy.api.Default(smithy4s.Document.fromString("ERROR"))),
)(make).withId(id).addHints(hints)
}