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

smithy.api.TraitValidator.scala Maven / Gradle / Ivy

There is a newer version: 0.19.0-41-91762fb
Show newest version
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)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy