← all lessons

Lesson 3

Structures

Structures

A structure is Smithy’s basic record type — a named bag of typed members. It’s the shape you’ll reach for most often: request bodies, response bodies, and nested data are all structures.

structure City {
    @required
    name: String

    population: Integer
}

Each member has a name and a target — the shape it points at (String, Integer, or another shape you’ve defined). The @required trait marks a member the model must always provide; without it, a member is optional.

Every model also needs two things at the top:

  • a $version control statement ($version: "2.0"), and
  • a namespace — a dotted prefix that scopes the shapes you define.

Your turn

The editor below talks to the real Smithy compiler. Write your model, hit Check, and you’ll see the same diagnostics the assembler produces — inline, at the exact line and column.