Type mapping
The value that a schema accepts for each proto type.
The mapping follows the types that protoc-gen-es generates.
| proto | Validated value |
|---|---|
string | string |
int32 and other 32-bit integers | integer number within the range |
int64 and other 64-bit integers | bigint within the range |
64-bit integer with jstype = JS_STRING | decimal integer string |
float, double | number |
bool | boolean |
bytes | Uint8Array |
| enum | integer number, or one of the defined values with defined_only |
| message | the schema of the message |
repeated | array |
map | record 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, ListValue | any value |
wrapper types such as StringValue | the wrapped type |
Presence
- A field with presence is an optional key. This covers
optionalfields 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.
requiredmakes 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.