alloy.DefaultValue.scala Maven / Gradle / Ivy
package alloy
import smithy4s.Document
import smithy4s.Hints
import smithy4s.Newtype
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.schema.Schema.bijection
import smithy4s.schema.Schema.document
import smithy4s.schema.Schema.recursive
/** Use this trait to give a default value to a structure member. This
* is not the same as smithy.api#default which is more constrained.
* You can use `defaultValue` to specify a default that does not align
* with the target's shape constraints, where as Smithy's `default` trait
* prevents that. For example:
*
* ```smithy
* {@literal @}length(min:5)
* string MyString
* structure MyStruct {
* {@literal @}defaultValue("N/A") // that's valid
* s1: MyString
* s2: MyString = "N/A" // that's invalid
* }
* ```
*/
object DefaultValue extends Newtype[Document] {
val id: ShapeId = ShapeId("alloy", "defaultValue")
val hints: Hints = Hints(
smithy.api.Documentation("Use this trait to give a default value to a structure member. This\nis not the same as smithy.api#default which is more constrained.\nYou can use `defaultValue` to specify a default that does not align\nwith the target\'s shape constraints, where as Smithy\'s `default` trait\nprevents that. For example:\n\n```smithy\n@length(min:5)\nstring MyString\nstructure MyStruct {\n @defaultValue(\"N/A\") // that\'s valid\n s1: MyString\n s2: MyString = \"N/A\" // that\'s invalid\n}\n```"),
smithy.api.Trait(selector = Some("structure > member :test(> :is(simpleType, list, map))"), structurallyExclusive = None, conflicts = Some(List(smithy.api.NonEmptyString("smithy.api#required"))), breakingChanges = None),
).lazily
val underlyingSchema: Schema[Document] = document.withId(id).addHints(hints)
implicit val schema: Schema[DefaultValue] = recursive(bijection(underlyingSchema, asBijection))
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy