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

smithy.api.IdRef.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.boolean
import smithy4s.schema.Schema.recursive
import smithy4s.schema.Schema.string
import smithy4s.schema.Schema.struct

/** Indicates that a string value MUST contain a valid shape ID.
  * 
  * The provided shape ID MAY be absolute or relative to the shape to which
  * the trait is applied. A relative shape ID that does not resolve to a
  * shape defined in the same namespace resolves to a shape defined in the
  * prelude if the prelude shape is not marked with the private trait.
  * @param selector
  *   Defines the selector that the resolved shape, if found, MUST match.
  * @param failWhenMissing
  *   When set to `true`, the shape ID MUST target a shape that can be
  *   found in the model.
  * @param errorMessage
  *   Defines a custom error message to use when the shape ID cannot be
  *   found or does not match the selector.
  *   
  *   A default message is generated when errorMessage is not defined.
  */
final case class IdRef(selector: String = "*", failWhenMissing: Option[Boolean] = None, errorMessage: Option[String] = None)

object IdRef extends ShapeTag.Companion[IdRef] {
  val id: ShapeId = ShapeId("smithy.api", "idRef")

  val hints: Hints = Hints(
    smithy.api.Documentation("Indicates that a string value MUST contain a valid shape ID.\n\nThe provided shape ID MAY be absolute or relative to the shape to which\nthe trait is applied. A relative shape ID that does not resolve to a\nshape defined in the same namespace resolves to a shape defined in the\nprelude if the prelude shape is not marked with the private trait."),
    smithy.api.Trait(selector = Some(":test(string, member > string)"), structurallyExclusive = None, conflicts = None, breakingChanges = None),
  ).lazily

  // constructor using the original order from the spec
  private def make(selector: String, failWhenMissing: Option[Boolean], errorMessage: Option[String]): IdRef = IdRef(selector, failWhenMissing, errorMessage)

  implicit val schema: Schema[IdRef] = recursive(struct(
    string.field[IdRef]("selector", _.selector).addHints(smithy.api.Documentation("Defines the selector that the resolved shape, if found, MUST match."), smithy.api.Default(smithy4s.Document.fromString("*"))),
    boolean.optional[IdRef]("failWhenMissing", _.failWhenMissing).addHints(smithy.api.Documentation("When set to `true`, the shape ID MUST target a shape that can be\nfound in the model.")),
    string.optional[IdRef]("errorMessage", _.errorMessage).addHints(smithy.api.Documentation("Defines a custom error message to use when the shape ID cannot be\nfound or does not match the selector.\n\nA default message is generated when errorMessage is not defined.")),
  )(make).withId(id).addHints(hints))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy