Skip to Content

Type mapping

The value that a schema accepts for each proto type.

The mapping follows the types that protoc-gen-es generates.

protoValidated value
stringstring
int32 and other 32-bit integersinteger number within the range
int64 and other 64-bit integersbigint within the range
64-bit integer with jstype = JS_STRINGdecimal integer string
float, doublenumber
boolboolean
bytesUint8Array
enuminteger number, or one of the defined values with defined_only
messagethe schema of the message
repeatedarray
maprecord with string keys
oneof{ case: "name", value } or { case: undefined }
Timestamp, Duration{ seconds: bigint, nanos: number }
FieldMask{ paths: string[] }
Any{ typeUrl: string, value: Uint8Array }
Struct, Value, ListValueany value
wrapper types such as StringValuethe wrapped type

Presence

  • A field with presence is an optional key. This covers optional fields and message fields.
  • A field without presence is a required key. protovalidate evaluates the rules of such a field even when the value is zero.
  • required makes the key required. On a field without presence, it also rejects the zero value.

To validate only part of a message, use v.pick or z.pick in the application.

oneof

A oneof without required defaults to { case: undefined }, so the form can leave out the key. With (buf.validate.oneof).required, the schema rejects { case: undefined }.

Wrapper types

A singular wrapper field accepts the wrapped type. Inside repeated, map, and oneof, the value is { value }.

Recursive messages

A reference that closes a cycle between messages uses v.lazy or z.lazy. The schema validates the value, and the output type of that field is any.