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

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

/** An enum definition for the enum trait.
  * @param name
  *   Defines the name that is used in code to represent this variant.
  * @param tags
  *   Applies a list of tags to the enum constant.
  * @param documentation
  *   Provides optional documentation about the enum constant value.
  * @param deprecated
  *   Whether the enum value should be considered deprecated.
  * @param value
  *   Defines the enum value that is sent over the wire.
  */
final case class EnumDefinition(value: NonEmptyString, name: Option[EnumConstantBodyName] = None, documentation: Option[String] = None, tags: Option[List[NonEmptyString]] = None, deprecated: Option[Boolean] = None)

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

  val hints: Hints = Hints(
    smithy.api.Documentation("An enum definition for the enum trait."),
    smithy.api.Private(),
  ).lazily

  // constructor using the original order from the spec
  private def make(value: NonEmptyString, name: Option[EnumConstantBodyName], documentation: Option[String], tags: Option[List[NonEmptyString]], deprecated: Option[Boolean]): EnumDefinition = EnumDefinition(value, name, documentation, tags, deprecated)

  implicit val schema: Schema[EnumDefinition] = struct(
    NonEmptyString.schema.required[EnumDefinition]("value", _.value).addHints(smithy.api.Documentation("Defines the enum value that is sent over the wire.")),
    EnumConstantBodyName.schema.optional[EnumDefinition]("name", _.name).addHints(smithy.api.Documentation("Defines the name that is used in code to represent this variant.")),
    string.optional[EnumDefinition]("documentation", _.documentation).addHints(smithy.api.Documentation("Provides optional documentation about the enum constant value.")),
    NonEmptyStringList.underlyingSchema.optional[EnumDefinition]("tags", _.tags).addHints(smithy.api.Documentation("Applies a list of tags to the enum constant.")),
    boolean.optional[EnumDefinition]("deprecated", _.deprecated).addHints(smithy.api.Documentation("Whether the enum value should be considered deprecated.")),
  )(make).withId(id).addHints(hints)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy