Lesson 2
Simple shapes
Simple shapes
Simple shapes are Smithy’s primitives — the atoms everything else is built from:
| Category | Shapes |
|---|---|
| Text | string, blob (binary) |
| Numbers | byte, short, integer, long, float, double, bigInteger, bigDecimal |
| Other | boolean, timestamp, document |
The prelude vs. your own names
You can use a primitive directly — the built-in String, Integer, and friends
live in the prelude (the smithy.api namespace, always in scope). But you
can also give a primitive your own name, creating a distinct, referenceable
type:
$version: "2.0"
namespace example
string CityName
integer Population
boolean IsCapital
timestamp FoundedAt
blob FlagImage
A named shape like CityName is its own type even though it’s “just a string” —
later you can attach constraints to it (see the Traits lesson), and codegen can
treat it distinctly.
Two rules to remember
- One
namespaceper file, declared right after$version. - Shape names start with an uppercase letter (
CityName, notcityName).