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

smithy.api.Range.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.bigdecimal
import smithy4s.schema.Schema.recursive
import smithy4s.schema.Schema.struct

/** Restricts allowed values of byte, short, integer, long, float, double,
  * bigDecimal, and bigInteger shapes within an acceptable lower and upper
  * bound.
  * @param min
  *   Specifies the allowed inclusive minimum value.
  * @param max
  *   Specifies the allowed inclusive maximum value.
  */
final case class Range(min: Option[BigDecimal] = None, max: Option[BigDecimal] = None)

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

  val hints: Hints = Hints(
    smithy.api.Documentation("Restricts allowed values of byte, short, integer, long, float, double,\nbigDecimal, and bigInteger shapes within an acceptable lower and upper\nbound."),
    smithy.api.Trait(selector = Some(":test(number, member > number)"), structurallyExclusive = None, conflicts = None, breakingChanges = None),
  ).lazily

  // constructor using the original order from the spec
  private def make(min: Option[BigDecimal], max: Option[BigDecimal]): Range = Range(min, max)

  implicit val schema: Schema[Range] = recursive(struct(
    bigdecimal.optional[Range]("min", _.min).addHints(smithy.api.Documentation("Specifies the allowed inclusive minimum value.")),
    bigdecimal.optional[Range]("max", _.max).addHints(smithy.api.Documentation("Specifies the allowed inclusive maximum value.")),
  )(make).withId(id).addHints(hints))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy