Skip to main content

Primitives

String

String is byte sequence primitive type represent by Go string or []byte.

Supported formats

caution

duration is a Go time.Duration format, but JSON Schema defines it as RFC 3339 duration.

FormatTypeDescription
byte[]byteBase64-encoded string as defined in RFC4648
date-timetime.TimeDate and time notation as defined by RFC 3339, section 5.6, for example, 2022-02-22T11:22:33Z
datetime.TimeDate only notation as defined by RFC 3339, section 5.6, for example, 2022-02-22
timetime.TimeTime only notation as defined by RFC 3339, section 5.6, for example, 11:22:33
durationtime.DurationGo duration format
uuiduuid.UUIDUUID
ipnet.IPAny IP (IPv4, IPv6)
ipv4net.IPIPv4, for example, 1.1.1.1
ipv6net.IPIPv6, for example, 2001:db8:85a3::8a2e:370:7334
uriurl.URLURL as defined by RFC 3986
emailstringEmail, for example, foo@example.com
binarystringBinary string
hostnamestringHostname as defined by RFC 1034, section 3.1

Non-standard formats

FormatTypeDescription
unix/unix-secondstime.TimeTime.Unix(), encoded as string. See issue #307
unix-nanotime.TimeTime.UnixNano(), encoded as string. See issue #307
unix-microtime.TimeTime.UnixMicro(), encoded as string. See issue #307
unix-millitime.TimeTime.UnixMilli(), encoded as string. See issue #307
int32int3232-bit signed integer, encoded as string. See issue #307
int64int6464-bit signed integer, encoded as string. See issue #307

Validation

note

Note that length validation uses utf8.RuneCountInString to count string length.

ValidatorDescription
minLengthMinimum length in Unicode code points
maxLengthMaximum length in Unicode code points
patternGo regexp pattern

Numbers

OpenAPI/JSON schema has two numeric types, number and integer, where number includes both integer and floating-point numbers.

typeformatGo typeDescription
numberfloat64Any numbers
numberfloatfloat32Floating-point numbers
numberdoublefloat64Floating-point numbers with double precision
integerintInteger numbers
integerint32int32Signed 32-bit integers
integerint64int64Signed 64-bit integers