← all lessons

Lesson 4

Lists & maps

Lists & maps

Once you have simple shapes, you’ll want collections of them. Smithy has two aggregate collection shapes: list and map.

Lists

A list has exactly one member, targeting the element type:

list CityNames {
    member: String
}

Maps

A map has a key and a value. The key must be a string:

map PopulationByCity {
    key: String
    value: Integer
}

Where did set go?

Smithy 1.0 had a set shape. Smithy 2.0 removed it. To model a collection of unique items, use a normal list with the @uniqueItems trait:

@uniqueItems
list UniqueTags {
    member: String
}

(Writing set Tags { ... } in a 2.0 model is a parse error.)

Your turn