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

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

/** Constrains a shape to minimum and maximum number of elements or size.
  * @param min
  *   Integer value that represents the minimum inclusive length of a shape.
  * @param max
  *   Integer value that represents the maximum inclusive length of a shape.
  */
final case class Length(min: Option[Long] = None, max: Option[Long] = None)

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

  val hints: Hints = Hints(
    smithy.api.Documentation("Constrains a shape to minimum and maximum number of elements or size."),
    smithy.api.Trait(selector = Some(":test(list, map, string, blob, member > :is(list, map, string, blob))"), structurallyExclusive = None, conflicts = None, breakingChanges = None),
  ).lazily

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

  implicit val schema: Schema[Length] = recursive(struct(
    long.optional[Length]("min", _.min).addHints(smithy.api.Documentation("Integer value that represents the minimum inclusive length of a shape.")),
    long.optional[Length]("max", _.max).addHints(smithy.api.Documentation("Integer value that represents the maximum inclusive length of a shape.")),
  )(make).withId(id).addHints(hints))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy