Skip to content

Constraint Traits

Juli Tera edited this page Apr 25, 2024 · 8 revisions

This wiki contains a mapping between Smithy Constraint traits and generated Ruby code.

To prevent forwards incompatibility, these constraints are not validated on the client side.

idRef trait

Indicates that a string value MUST contain a valid absolute shape ID. The @idRef trait is used primarily when declaring trait shapes in a model. This trait does not influence code generation.

See Smithy Documentation for more details.

length trait

Constrains a shape to minimum and maximum number of elements or size. This constraint is not validated.

@length(min: 1, max: 10)
string MyString

See Smithy Documentation for more details.

pattern trait

Restricts string shape values to a specified regular expression. This constraint is not validated.

@pattern("\\w+")
string MyString

See Smithy Documentation for more details.

private trait

Prevents models defined in a different namespace from referencing the targeted shape.

@private
string PrivateString

See Smithy Documentation for more details.

range trait

Restricts allowed values of byte, short, integer, long, float, double, bigDecimal, and bigInteger shapes within an acceptable lower and upper bound. This constraint is not validated.

@range(min: 1, max: 10)
integer MyInt

See Smithy Documentation for more details.

uniqueItems trait

Indicates that the items in a list MUST be unique based on Value equality. This constraint is not validated.

@uniqueItems
list MyList {
    member: String
}

See Smithy Documentation for more details.