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

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

/** Makes a shape a trait.
  * @param selector
  *   The valid places in a model that the trait can be applied.
  * @param structurallyExclusive
  *   Whether or not only a single member in a shape can have this trait.
  * @param conflicts
  *   The traits that this trait conflicts with.
  * @param breakingChanges
  *   Defines the backward compatibility rules of the trait.
  */
final case class Trait(selector: Option[String] = None, structurallyExclusive: Option[StructurallyExclusive] = None, conflicts: Option[List[NonEmptyString]] = None, breakingChanges: Option[List[TraitDiffRule]] = None)

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

  val hints: Hints = Hints(
    smithy.api.Documentation("Makes a shape a trait."),
    smithy.api.Trait(selector = Some(":is(simpleType, list, map, structure, union)"), structurallyExclusive = None, conflicts = None, breakingChanges = Some(List(smithy.api.TraitDiffRule(change = smithy.api.TraitChangeType.PRESENCE.widen, severity = smithy.api.Severity.ERROR.widen, path = None, message = None), smithy.api.TraitDiffRule(change = smithy.api.TraitChangeType.ANY.widen, severity = smithy.api.Severity.ERROR.widen, path = Some("/structurallyExclusive"), message = None), smithy.api.TraitDiffRule(change = smithy.api.TraitChangeType.UPDATE.widen, severity = smithy.api.Severity.NOTE.widen, path = Some("/conflicts"), message = Some("Adding more conflicts to a trait could cause previously written models to fail validation."))))),
  ).lazily

  // constructor using the original order from the spec
  private def make(selector: Option[String], structurallyExclusive: Option[StructurallyExclusive], conflicts: Option[List[NonEmptyString]], breakingChanges: Option[List[TraitDiffRule]]): Trait = Trait(selector, structurallyExclusive, conflicts, breakingChanges)

  implicit val schema: Schema[Trait] = recursive(struct(
    string.optional[Trait]("selector", _.selector).addHints(smithy.api.Documentation("The valid places in a model that the trait can be applied.")),
    StructurallyExclusive.schema.optional[Trait]("structurallyExclusive", _.structurallyExclusive).addHints(smithy.api.Documentation("Whether or not only a single member in a shape can have this trait.")),
    NonEmptyStringList.underlyingSchema.optional[Trait]("conflicts", _.conflicts).addHints(smithy.api.Documentation("The traits that this trait conflicts with.")),
    TraitDiffRules.underlyingSchema.optional[Trait]("breakingChanges", _.breakingChanges).addHints(smithy.api.Documentation("Defines the backward compatibility rules of the trait.")),
  )(make).withId(id).addHints(hints))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy