Skip to content

Scalars

Built-in scalars

TypeSpectypeformat
stringstring
booleanboolean
integerinteger— (abstract, width unspecified)
numeric, floatnumber— (abstract, width unspecified)
int8 / int16 / int32 / int64integerint8 / int16 / int32 / int64
safeintintegerint64
uint8 / uint16 / uint32 / uint64integeruint8 / uint16 / uint32 / uint64
float32numberfloat
float64numberdouble
decimalnumberdecimal
decimal128numberdecimal128
bytesstringbyte
plainDatestringdate
plainTimestringtime
utcDateTime, offsetDateTimestringdate-time
durationstringduration
urlstringuri

Intrinsic types: null{ type: "null" }; never and void{ not: {} } (no value is valid); unknown{} (any value is valid).

User-declared scalars

A scalar declared with extends inherits the base's shape and layers its own documentation and validation keywords on top. The scalar's constraints follow it to every use site:

typespec
@doc("An RFC 5321 mailbox address.")
@maxLength(254)
scalar Email extends string;

model Account {
  email: Email;
}
yaml
components:
  schemas:
    Account:
      type: object
      properties:
        email:
          type: string
          description: An RFC 5321 mailbox address.
          maxLength: 254
      required:
        - email

If a property re-declares a keyword its scalar already carries (say, @minLength(2) on a property whose scalar has @minLength(5)), the two constraints are combined with allOf so both hold — a use site can never silently weaken a scalar's constraint.