A custom pattern is used for defining custom HTTP verb.
| Field | Type | Label | Description |
| kind | string | The name of this custom HTTP verb. |
|
| path | string | The path matched by this custom verb. |
Defines the HTTP configuration for an API service. It contains a list of
[HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method
to one or more HTTP REST API methods.
| Field | Type | Label | Description |
| rules | HttpRule | repeated | A list of HTTP configuration rules that apply to individual API methods. **NOTE:** All service configuration rules follow "last one wins" order. |
| fully_decode_reserved_expansion | bool | When set to true, URL path parameters will be fully URI-decoded except in cases of single segment matches in reserved expansion, where "%2F" will be left encoded. The default behavior is to not decode RFC 6570 reserved characters in multi segment matches. |
# gRPC Transcoding
gRPC Transcoding is a feature for mapping between a gRPC method and one or
more HTTP REST endpoints. It allows developers to build a single API service
that supports both gRPC APIs and REST APIs. Many systems, including [Google
APIs](https://github.com/googleapis/googleapis),
[Cloud Endpoints](https://cloud.google.com/endpoints), [gRPC
Gateway](https://github.com/grpc-ecosystem/grpc-gateway),
and [Envoy](https://github.com/envoyproxy/envoy) proxy support this feature
and use it for large scale production services.
`HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies
how different portions of the gRPC request message are mapped to the URL
path, URL query parameters, and HTTP request body. It also controls how the
gRPC response message is mapped to the HTTP response body. `HttpRule` is
typically specified as an `google.api.http` annotation on the gRPC method.
Each mapping specifies a URL path template and an HTTP method. The path
template may refer to one or more fields in the gRPC request message, as long
as each field is a non-repeated field with a primitive (non-message) type.
The path template controls how fields of the request message are mapped to
the URL path.
Example:
service Messaging {
rpc GetMessage(GetMessageRequest) returns (Message) {
option (google.api.http) = {
get: "/v1/{name=messages/*}"
};
}
}
message GetMessageRequest {
string name = 1; // Mapped to URL path.
}
message Message {
string text = 1; // The resource content.
}
This enables an HTTP REST to gRPC mapping as below:
HTTP | gRPC
-----|-----
`GET /v1/messages/123456` | `GetMessage(name: "messages/123456")`
Any fields in the request message which are not bound by the path template
automatically become HTTP query parameters if there is no HTTP request body.
For example:
service Messaging {
rpc GetMessage(GetMessageRequest) returns (Message) {
option (google.api.http) = {
get:"/v1/messages/{message_id}"
};
}
}
message GetMessageRequest {
message SubMessage {
string subfield = 1;
}
string message_id = 1; // Mapped to URL path.
int64 revision = 2; // Mapped to URL query parameter `revision`.
SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`.
}
This enables a HTTP JSON to RPC mapping as below:
HTTP | gRPC
-----|-----
`GET /v1/messages/123456?revision=2&sub.subfield=foo` |
`GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield:
"foo"))`
Note that fields which are mapped to URL query parameters must have a
primitive type or a repeated primitive type or a non-repeated message type.
In the case of a repeated type, the parameter can be repeated in the URL
as `...?param=A¶m=B`. In the case of a message type, each field of the
message is mapped to a separate parameter, such as
`...?foo.a=A&foo.b=B&foo.c=C`.
For HTTP methods that allow a request body, the `body` field
specifies the mapping. Consider a REST update method on the
message resource collection:
service Messaging {
rpc UpdateMessage(UpdateMessageRequest) returns (Message) {
option (google.api.http) = {
patch: "/v1/messages/{message_id}"
body: "message"
};
}
}
message UpdateMessageRequest {
string message_id = 1; // mapped to the URL
Message message = 2; // mapped to the body
}
The following HTTP JSON to RPC mapping is enabled, where the
representation of the JSON in the request body is determined by
protos JSON encoding:
HTTP | gRPC
-----|-----
`PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id:
"123456" message { text: "Hi!" })`
The special name `*` can be used in the body mapping to define that
every field not bound by the path template should be mapped to the
request body. This enables the following alternative definition of
the update method:
service Messaging {
rpc UpdateMessage(Message) returns (Message) {
option (google.api.http) = {
patch: "/v1/messages/{message_id}"
body: "*"
};
}
}
message Message {
string message_id = 1;
string text = 2;
}
The following HTTP JSON to RPC mapping is enabled:
HTTP | gRPC
-----|-----
`PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id:
"123456" text: "Hi!")`
Note that when using `*` in the body mapping, it is not possible to
have HTTP parameters, as all fields not bound by the path end in
the body. This makes this option more rarely used in practice when
defining REST APIs. The common usage of `*` is in custom methods
which don't use the URL at all for transferring data.
It is possible to define multiple HTTP methods for one RPC by using
the `additional_bindings` option. Example:
service Messaging {
rpc GetMessage(GetMessageRequest) returns (Message) {
option (google.api.http) = {
get: "/v1/messages/{message_id}"
additional_bindings {
get: "/v1/users/{user_id}/messages/{message_id}"
}
};
}
}
message GetMessageRequest {
string message_id = 1;
string user_id = 2;
}
This enables the following two alternative HTTP JSON to RPC mappings:
HTTP | gRPC
-----|-----
`GET /v1/messages/123456` | `GetMessage(message_id: "123456")`
`GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id:
"123456")`
## Rules for HTTP mapping
1. Leaf request fields (recursive expansion nested messages in the request
message) are classified into three categories:
- Fields referred by the path template. They are passed via the URL path.
- Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They
are passed via the HTTP
request body.
- All other fields are passed via the URL query parameters, and the
parameter name is the field path in the request message. A repeated
field can be represented as multiple query parameters under the same
name.
2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL
query parameter, all fields
are passed via URL path and HTTP request body.
3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP
request body, all
fields are passed via URL path and URL query parameters.
### Path template syntax
Template = "/" Segments [ Verb ] ;
Segments = Segment { "/" Segment } ;
Segment = "*" | "**" | LITERAL | Variable ;
Variable = "{" FieldPath [ "=" Segments ] "}" ;
FieldPath = IDENT { "." IDENT } ;
Verb = ":" LITERAL ;
The syntax `*` matches a single URL path segment. The syntax `**` matches
zero or more URL path segments, which must be the last part of the URL path
except the `Verb`.
The syntax `Variable` matches part of the URL path as specified by its
template. A variable template must not contain other variables. If a variable
matches a single path segment, its template may be omitted, e.g. `{var}`
is equivalent to `{var=*}`.
The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL`
contains any reserved character, such characters should be percent-encoded
before the matching.
If a variable contains exactly one path segment, such as `"{var}"` or
`"{var=*}"`, when such a variable is expanded into a URL path on the client
side, all characters except `[-_.~0-9a-zA-Z]` are percent-encoded. The
server side does the reverse decoding. Such variables show up in the
[Discovery
Document](https://developers.google.com/discovery/v1/reference/apis) as
`{var}`.
If a variable contains multiple path segments, such as `"{var=foo/*}"`
or `"{var=**}"`, when such a variable is expanded into a URL path on the
client side, all characters except `[-_.~/0-9a-zA-Z]` are percent-encoded.
The server side does the reverse decoding, except "%2F" and "%2f" are left
unchanged. Such variables show up in the
[Discovery
Document](https://developers.google.com/discovery/v1/reference/apis) as
`{+var}`.
## Using gRPC API Service Configuration
gRPC API Service Configuration (service config) is a configuration language
for configuring a gRPC service to become a user-facing product. The
service config is simply the YAML representation of the `google.api.Service`
proto message.
As an alternative to annotating your proto file, you can configure gRPC
transcoding in your service config YAML files. You do this by specifying a
`HttpRule` that maps the gRPC method to a REST endpoint, achieving the same
effect as the proto annotation. This can be particularly useful if you
have a proto that is reused in multiple services. Note that any transcoding
specified in the service config will override any matching transcoding
configuration in the proto.
Example:
http:
rules:
# Selects a gRPC method and applies HttpRule to it.
- selector: example.v1.Messaging.GetMessage
get: /v1/messages/{message_id}/{sub.subfield}
## Special notes
When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the
proto to JSON conversion must follow the [proto3
specification](https://developers.google.com/protocol-buffers/docs/proto3#json).
While the single segment variable follows the semantics of
[RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String
Expansion, the multi segment variable **does not** follow RFC 6570 Section
3.2.3 Reserved Expansion. The reason is that the Reserved Expansion
does not expand special characters like `?` and `#`, which would lead
to invalid URLs. As the result, gRPC Transcoding uses a custom encoding
for multi segment variables.
The path variables **must not** refer to any repeated or mapped field,
because client libraries are not capable of handling such variable expansion.
The path variables **must not** capture the leading "/" character. The reason
is that the most common use case "{var}" does not capture the leading "/"
character. For consistency, all path variables must share the same behavior.
Repeated message fields must not be mapped to URL query parameters, because
no client library can support such complicated mapping.
If an API needs to use a JSON array for request or response body, it can map
the request or response body to a repeated field. However, some gRPC
Transcoding implementations may not support this feature.
| Field | Type | Label | Description |
| selector | string | Selects a method to which this rule applies. Refer to [selector][google.api.DocumentationRule.selector] for syntax details. |
|
| get | string | Maps to HTTP GET. Used for listing and getting information about resources. |
|
| put | string | Maps to HTTP PUT. Used for replacing a resource. |
|
| post | string | Maps to HTTP POST. Used for creating a resource or performing an action. |
|
| delete | string | Maps to HTTP DELETE. Used for deleting a resource. |
|
| patch | string | Maps to HTTP PATCH. Used for updating a resource. |
|
| custom | CustomHttpPattern | The custom pattern is used for specifying an HTTP method that is not included in the `pattern` field, such as HEAD, or "*" to leave the HTTP method unspecified for this rule. The wild-card rule is useful for services that provide content to Web (HTML) clients. |
|
| body | string | The name of the request field whose value is mapped to the HTTP request body, or `*` for mapping all request fields not captured by the path pattern to the HTTP body, or omitted for not having any HTTP request body. NOTE: the referred field must be present at the top-level of the request message type. |
|
| response_body | string | Optional. The name of the response field whose value is mapped to the HTTP response body. When omitted, the entire response message will be used as the HTTP response body. NOTE: The referred field must be present at the top-level of the response message type. |
|
| additional_bindings | HttpRule | repeated | Additional HTTP bindings for the selector. Nested bindings must not contain an `additional_bindings` field themselves (that is, the nesting may only be one level deep). |
| Extension | Type | Base | Number | Description |
| http | HttpRule | .google.protobuf.MethodOptions | 72295728 | See `HttpRule`. |
| Name | Number | Description |
| SUCCESS | 0 | |
| INVALID_PARAMS | 1 | |
| INTERVAL | 2 | |
| INTERNAL_SERVER_ERROR | 3 | |
| RATE_LIMIT | 4 | |
| LOCK_FAILED | 5 | |
| UNIMPLEMENTED | 6 | |
| NOT_FOUND | 7 | |
| UNKNOWN | 8 | |
| UNAUTHORIZED | 9 | |
| INVALID_CREDENTIALS | 10 |
| Name | Number | Description |
| Invalid | 0 | |
| 1 | ||
| NoNotify | 2 | |
| AdminNotify | 4 | |
| SmsNotify | 8 | |
| DialingNotify | 16 | |
| WechatMessageNotify | 32 | |
| WechatTemplateNotify | 64 |
`Constraint` represents a validation rule written in the Common Expression
Language (CEL) syntax. Each Constraint includes a unique identifier, an
optional error message, and the CEL expression to evaluate. For more
information on CEL, [see our documentation](https://github.com/bufbuild/protovalidate/blob/main/docs/cel.md).
```proto
message Foo {
option (buf.validate.message).cel = {
id: "foo.bar"
message: "bar must be greater than 0"
expression: "this.bar > 0"
};
int32 bar = 1;
}
```
| Field | Type | Label | Description |
| id | string | `id` is a string that serves as a machine-readable name for this Constraint. It should be unique within its scope, which could be either a message or a field. |
|
| message | string | `message` is an optional field that provides a human-readable error message for this Constraint when the CEL expression evaluates to false. If a non-empty message is provided, any strings resulting from the CEL expression evaluation are ignored. |
|
| expression | string | `expression` is the actual CEL expression that will be evaluated for validation. This string must resolve to either a boolean or a string value. If the expression evaluates to false or a non-empty string, the validation is considered failed, and the message is rejected. |
`Violation` represents a single instance where a validation rule, expressed
as a `Constraint`, was not met. It provides information about the field that
caused the violation, the specific constraint that wasn't fulfilled, and a
human-readable error message.
```json
{
"fieldPath": "bar",
"constraintId": "foo.bar",
"message": "bar must be greater than 0"
}
```
| Field | Type | Label | Description |
| field_path | string | `field_path` is a machine-readable identifier that points to the specific field that failed the validation. This could be a nested field, in which case the path will include all the parent fields leading to the actual field that caused the violation. |
|
| constraint_id | string | `constraint_id` is the unique identifier of the `Constraint` that was not fulfilled. This is the same `id` that was specified in the `Constraint` message, allowing easy tracing of which rule was violated. |
|
| message | string | `message` is a human-readable error message that describes the nature of the violation. This can be the default error message from the violated `Constraint`, or it can be a custom message that gives more context about the violation. |
|
| for_key | bool | `for_key` indicates whether the violation was caused by a map key, rather than a value. |
`Violations` is a collection of `Violation` messages. This message type is returned by
protovalidate when a proto message fails to meet the requirements set by the `Constraint` validation rules.
Each individual violation is represented by a `Violation` message.
| Field | Type | Label | Description |
| violations | Violation | repeated | `violations` is a repeated field that contains all the `Violation` messages corresponding to the violations detected. |
Do not use. Internal to protovalidate library
| Field | Type | Label | Description |
| id | string |
|
|
| message | string |
|
|
| expression | string |
|
Do not use. Internal to protovalidate library
| Field | Type | Label | Description |
| cel | Constraint | repeated |
|
| Extension | Type | Base | Number | Description |
| field | FieldConstraints | .google.protobuf.FieldOptions | 1160 | Do not use. Internal to protovalidate library |
AnyRules describe constraints applied exclusively to the `google.protobuf.Any` well-known type.
| Field | Type | Label | Description |
| in | string | repeated | `in` requires the field's `type_url` to be equal to one of the specified values. If it doesn't match any of the specified values, an error message is generated. ```proto message MyAny { // The `value` field must have a `type_url` equal to one of the specified values. google.protobuf.Any value = 1 [(buf.validate.field).any.in = ["type.googleapis.com/MyType1", "type.googleapis.com/MyType2"]]; } ``` |
| not_in | string | repeated | requires the field's type_url to be not equal to any of the specified values. If it matches any of the specified values, an error message is generated. ```proto message MyAny { // The field `value` must not have a `type_url` equal to any of the specified values. google.protobuf.Any value = 1 [(buf.validate.field).any.not_in = ["type.googleapis.com/ForbiddenType1", "type.googleapis.com/ForbiddenType2"]]; } ``` |
BoolRules describes the constraints applied to `bool` values. These rules
may also be applied to the `google.protobuf.BoolValue` Well-Known-Type.
| Field | Type | Label | Description |
| const | bool | optional | `const` requires the field value to exactly match the specified boolean value. If the field value doesn't match, an error message is generated. ```proto message MyBool { // value must equal true bool value = 1 [(buf.validate.field).bool.const = true]; } ``` |
BytesRules describe the constraints applied to `bytes` values. These rules
may also be applied to the `google.protobuf.BytesValue` Well-Known-Type.
| Field | Type | Label | Description |
| const | bytes | optional | `const` requires the field value to exactly match the specified bytes value. If the field value doesn't match, an error message is generated. ```proto message MyBytes { // value must be "\x01\x02\x03\x04" bytes value = 1 [(buf.validate.field).bytes.const = "\x01\x02\x03\x04"]; } ``` |
| len | uint64 | optional | `len` requires the field value to have the specified length in bytes. If the field value doesn't match, an error message is generated. ```proto message MyBytes { // value length must be 4 bytes. optional bytes value = 1 [(buf.validate.field).bytes.len = 4]; } ``` |
| min_len | uint64 | optional | `min_len` requires the field value to have at least the specified minimum length in bytes. If the field value doesn't meet the requirement, an error message is generated. ```proto message MyBytes { // value length must be at least 2 bytes. optional bytes value = 1 [(buf.validate.field).bytes.min_len = 2]; } ``` |
| max_len | uint64 | optional | `max_len` requires the field value to have at most the specified maximum length in bytes. If the field value exceeds the requirement, an error message is generated. ```proto message MyBytes { // value must be at most 6 bytes. optional bytes value = 1 [(buf.validate.field).bytes.max_len = 6]; } ``` |
| pattern | string | optional | `pattern` requires the field value to match the specified regular expression ([RE2 syntax](https://github.com/google/re2/wiki/Syntax)). The value of the field must be valid UTF-8 or validation will fail with a runtime error. If the field value doesn't match the pattern, an error message is generated. ```proto message MyBytes { // value must match regex pattern "^[a-zA-Z0-9]+$". optional bytes value = 1 [(buf.validate.field).bytes.pattern = "^[a-zA-Z0-9]+$"]; } ``` |
| prefix | bytes | optional | `prefix` requires the field value to have the specified bytes at the beginning of the string. If the field value doesn't meet the requirement, an error message is generated. ```proto message MyBytes { // value does not have prefix \x01\x02 optional bytes value = 1 [(buf.validate.field).bytes.prefix = "\x01\x02"]; } ``` |
| suffix | bytes | optional | `suffix` requires the field value to have the specified bytes at the end of the string. If the field value doesn't meet the requirement, an error message is generated. ```proto message MyBytes { // value does not have suffix \x03\x04 optional bytes value = 1 [(buf.validate.field).bytes.suffix = "\x03\x04"]; } ``` |
| contains | bytes | optional | `contains` requires the field value to have the specified bytes anywhere in the string. If the field value doesn't meet the requirement, an error message is generated. ```protobuf message MyBytes { // value does not contain \x02\x03 optional bytes value = 1 [(buf.validate.field).bytes.contains = "\x02\x03"]; } ``` |
| in | bytes | repeated | `in` requires the field value to be equal to one of the specified values. If the field value doesn't match any of the specified values, an error message is generated. ```protobuf message MyBytes { // value must in ["\x01\x02", "\x02\x03", "\x03\x04"] optional bytes value = 1 [(buf.validate.field).bytes.in = {"\x01\x02", "\x02\x03", "\x03\x04"}]; } ``` |
| not_in | bytes | repeated | `not_in` requires the field value to be not equal to any of the specified values. If the field value matches any of the specified values, an error message is generated. ```proto message MyBytes { // value must not in ["\x01\x02", "\x02\x03", "\x03\x04"] optional bytes value = 1 [(buf.validate.field).bytes.not_in = {"\x01\x02", "\x02\x03", "\x03\x04"}]; } ``` |
| ip | bool | `ip` ensures that the field `value` is a valid IP address (v4 or v6) in byte format. If the field value doesn't meet this constraint, an error message is generated. ```proto message MyBytes { // value must be a valid IP address optional bytes value = 1 [(buf.validate.field).bytes.ip = true]; } ``` |
|
| ipv4 | bool | `ipv4` ensures that the field `value` is a valid IPv4 address in byte format. If the field value doesn't meet this constraint, an error message is generated. ```proto message MyBytes { // value must be a valid IPv4 address optional bytes value = 1 [(buf.validate.field).bytes.ipv4 = true]; } ``` |
|
| ipv6 | bool | `ipv6` ensures that the field `value` is a valid IPv6 address in byte format. If the field value doesn't meet this constraint, an error message is generated. ```proto message MyBytes { // value must be a valid IPv6 address optional bytes value = 1 [(buf.validate.field).bytes.ipv6 = true]; } ``` |
DoubleRules describes the constraints applied to `double` values. These
rules may also be applied to the `google.protobuf.DoubleValue` Well-Known-Type.
| Field | Type | Label | Description |
| const | double | optional | `const` requires the field value to exactly match the specified value. If the field value doesn't match, an error message is generated. ```proto message MyDouble { // value must equal 42.0 double value = 1 [(buf.validate.field).double.const = 42.0]; } ``` |
| lt | double | `lt` requires the field value to be less than the specified value (field < value). If the field value is equal to or greater than the specified value, an error message is generated. ```proto message MyDouble { // value must be less than 10.0 double value = 1 [(buf.validate.field).double.lt = 10.0]; } ``` |
|
| lte | double | `lte` requires the field value to be less than or equal to the specified value (field <= value). If the field value is greater than the specified value, an error message is generated. ```proto message MyDouble { // value must be less than or equal to 10.0 double value = 1 [(buf.validate.field).double.lte = 10.0]; } ``` |
|
| gt | double | `gt` requires the field value to be greater than the specified value (exclusive). If the value of `gt` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyDouble { // value must be greater than 5.0 [double.gt] double value = 1 [(buf.validate.field).double.gt = 5.0]; // value must be greater than 5 and less than 10.0 [double.gt_lt] double other_value = 2 [(buf.validate.field).double = { gt: 5.0, lt: 10.0 }]; // value must be greater than 10 or less than 5.0 [double.gt_lt_exclusive] double another_value = 3 [(buf.validate.field).double = { gt: 10.0, lt: 5.0 }]; } ``` |
|
| gte | double | `gte` requires the field value to be greater than or equal to the specified value (exclusive). If the value of `gte` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyDouble { // value must be greater than or equal to 5.0 [double.gte] double value = 1 [(buf.validate.field).double.gte = 5.0]; // value must be greater than or equal to 5.0 and less than 10.0 [double.gte_lt] double other_value = 2 [(buf.validate.field).double = { gte: 5.0, lt: 10.0 }]; // value must be greater than or equal to 10.0 or less than 5.0 [double.gte_lt_exclusive] double another_value = 3 [(buf.validate.field).double = { gte: 10.0, lt: 5.0 }]; } ``` |
|
| in | double | repeated | `in` requires the field value to be equal to one of the specified values. If the field value isn't one of the specified values, an error message is generated. ```proto message MyDouble { // value must be in list [1.0, 2.0, 3.0] repeated double value = 1 (buf.validate.field).double = { in: [1.0, 2.0, 3.0] }; } ``` |
| not_in | double | repeated | `not_in` requires the field value to not be equal to any of the specified values. If the field value is one of the specified values, an error message is generated. ```proto message MyDouble { // value must not be in list [1.0, 2.0, 3.0] repeated double value = 1 (buf.validate.field).double = { not_in: [1.0, 2.0, 3.0] }; } ``` |
| finite | bool | `finite` requires the field value to be finite. If the field value is infinite or NaN, an error message is generated. |
DurationRules describe the constraints applied exclusively to the `google.protobuf.Duration` well-known type.
| Field | Type | Label | Description |
| const | google.protobuf.Duration | optional | `const` dictates that the field must match the specified value of the `google.protobuf.Duration` type exactly. If the field's value deviates from the specified value, an error message will be generated. ```proto message MyDuration { // value must equal 5s google.protobuf.Duration value = 1 [(buf.validate.field).duration.const = "5s"]; } ``` |
| lt | google.protobuf.Duration | `lt` stipulates that the field must be less than the specified value of the `google.protobuf.Duration` type, exclusive. If the field's value is greater than or equal to the specified value, an error message will be generated. ```proto message MyDuration { // value must be less than 5s google.protobuf.Duration value = 1 [(buf.validate.field).duration.lt = "5s"]; } ``` |
|
| lte | google.protobuf.Duration | `lte` indicates that the field must be less than or equal to the specified value of the `google.protobuf.Duration` type, inclusive. If the field's value is greater than the specified value, an error message will be generated. ```proto message MyDuration { // value must be less than or equal to 10s google.protobuf.Duration value = 1 [(buf.validate.field).duration.lte = "10s"]; } ``` |
|
| gt | google.protobuf.Duration | `gt` requires the duration field value to be greater than the specified value (exclusive). If the value of `gt` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyDuration { // duration must be greater than 5s [duration.gt] google.protobuf.Duration value = 1 [(buf.validate.field).duration.gt = { seconds: 5 }]; // duration must be greater than 5s and less than 10s [duration.gt_lt] google.protobuf.Duration another_value = 2 [(buf.validate.field).duration = { gt: { seconds: 5 }, lt: { seconds: 10 } }]; // duration must be greater than 10s or less than 5s [duration.gt_lt_exclusive] google.protobuf.Duration other_value = 3 [(buf.validate.field).duration = { gt: { seconds: 10 }, lt: { seconds: 5 } }]; } ``` |
|
| gte | google.protobuf.Duration | `gte` requires the duration field value to be greater than or equal to the specified value (exclusive). If the value of `gte` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyDuration { // duration must be greater than or equal to 5s [duration.gte] google.protobuf.Duration value = 1 [(buf.validate.field).duration.gte = { seconds: 5 }]; // duration must be greater than or equal to 5s and less than 10s [duration.gte_lt] google.protobuf.Duration another_value = 2 [(buf.validate.field).duration = { gte: { seconds: 5 }, lt: { seconds: 10 } }]; // duration must be greater than or equal to 10s or less than 5s [duration.gte_lt_exclusive] google.protobuf.Duration other_value = 3 [(buf.validate.field).duration = { gte: { seconds: 10 }, lt: { seconds: 5 } }]; } ``` |
|
| in | google.protobuf.Duration | repeated | `in` asserts that the field must be equal to one of the specified values of the `google.protobuf.Duration` type. If the field's value doesn't correspond to any of the specified values, an error message will be generated. ```proto message MyDuration { // value must be in list [1s, 2s, 3s] google.protobuf.Duration value = 1 [(buf.validate.field).duration.in = ["1s", "2s", "3s"]]; } ``` |
| not_in | google.protobuf.Duration | repeated | `not_in` denotes that the field must not be equal to any of the specified values of the `google.protobuf.Duration` type. If the field's value matches any of these values, an error message will be generated. ```proto message MyDuration { // value must not be in list [1s, 2s, 3s] google.protobuf.Duration value = 1 [(buf.validate.field).duration.not_in = ["1s", "2s", "3s"]]; } ``` |
EnumRules describe the constraints applied to `enum` values.
| Field | Type | Label | Description |
| const | int32 | optional | `const` requires the field value to exactly match the specified enum value. If the field value doesn't match, an error message is generated. ```proto enum MyEnum { MY_ENUM_UNSPECIFIED = 0; MY_ENUM_VALUE1 = 1; MY_ENUM_VALUE2 = 2; } message MyMessage { // The field `value` must be exactly MY_ENUM_VALUE1. MyEnum value = 1 [(buf.validate.field).enum.const = 1]; } ``` |
| defined_only | bool | optional | `defined_only` requires the field value to be one of the defined values for this enum, failing on any undefined value. ```proto enum MyEnum { MY_ENUM_UNSPECIFIED = 0; MY_ENUM_VALUE1 = 1; MY_ENUM_VALUE2 = 2; } message MyMessage { // The field `value` must be a defined value of MyEnum. MyEnum value = 1 [(buf.validate.field).enum.defined_only = true]; } ``` |
| in | int32 | repeated | `in` requires the field value to be equal to one of the specified enum values. If the field value doesn't match any of the specified values, an error message is generated. ```proto enum MyEnum { MY_ENUM_UNSPECIFIED = 0; MY_ENUM_VALUE1 = 1; MY_ENUM_VALUE2 = 2; } message MyMessage { // The field `value` must be equal to one of the specified values. MyEnum value = 1 [(buf.validate.field).enum = { in: [1, 2]}]; } ``` |
| not_in | int32 | repeated | `not_in` requires the field value to be not equal to any of the specified enum values. If the field value matches one of the specified values, an error message is generated. ```proto enum MyEnum { MY_ENUM_UNSPECIFIED = 0; MY_ENUM_VALUE1 = 1; MY_ENUM_VALUE2 = 2; } message MyMessage { // The field `value` must not be equal to any of the specified values. MyEnum value = 1 [(buf.validate.field).enum = { not_in: [1, 2]}]; } ``` |
FieldRules encapsulates the rules for each type of field. Depending on the
field, the correct set should be used to ensure proper validations.
| Field | Type | Label | Description |
| cel | Constraint | repeated | `cel` is a repeated field used to represent a textual expression in the Common Expression Language (CEL) syntax. For more information on CEL, [see our documentation](https://github.com/bufbuild/protovalidate/blob/main/docs/cel.md). ```proto message MyMessage { // The field `value` must be greater than 42. optional int32 value = 1 [(buf.validate.field).cel = { id: "my_message.value", message: "value must be greater than 42", expression: "this > 42", }]; } ``` |
| skipped | bool | `skipped` is an optional boolean attribute that specifies that the validation rules of this field should not be evaluated. If skipped is set to true, any validation rules set for the field will be ignored. ```proto message MyMessage { // The field `value` must not be set. optional MyOtherMessage value = 1 [(buf.validate.field).skipped = true]; } ``` |
|
| required | bool | If `required` is true, the field must be populated. Field presence can be described as "serialized in the wire format," which follows the following rules: - the following "nullable" fields must be explicitly set to be considered present: - singular message fields (may be their empty value) - member fields of a oneof (may be their default value) - proto3 optional fields (may be their default value) - proto2 scalar fields - proto3 scalar fields must be non-zero to be considered present - repeated and map fields must be non-empty to be considered present ```proto message MyMessage { // The field `value` must be set to a non-null value. optional MyOtherMessage value = 1 [(buf.validate.field).required = true]; } ``` |
|
| ignore_empty | bool | If `ignore_empty` is true and applied to a non-nullable field (see `required` for more details), validation is skipped on the field if it is the default or empty value. Adding `ignore_empty` to a "nullable" field is a noop as these unset fields already skip validation (with the exception of `required`). ```proto message MyRepeated { // The field `value` min_len rule is only applied if the field isn't empty. repeated string value = 1 [ (buf.validate.field).ignore_empty = true, (buf.validate.field).min_len = 5 ]; } ``` |
|
| float | FloatRules | Scalar Field Types |
|
| double | DoubleRules |
|
|
| int32 | Int32Rules |
|
|
| int64 | Int64Rules |
|
|
| uint32 | UInt32Rules |
|
|
| uint64 | UInt64Rules |
|
|
| sint32 | SInt32Rules |
|
|
| sint64 | SInt64Rules |
|
|
| fixed32 | Fixed32Rules |
|
|
| fixed64 | Fixed64Rules |
|
|
| sfixed32 | SFixed32Rules |
|
|
| sfixed64 | SFixed64Rules |
|
|
| bool | BoolRules |
|
|
| string | StringRules |
|
|
| bytes | BytesRules |
|
|
| enum | EnumRules | Complex Field Types |
|
| repeated | RepeatedRules |
|
|
| map | MapRules |
|
|
| any | AnyRules | Well-Known Field Types |
|
| duration | DurationRules |
|
|
| timestamp | TimestampRules |
|
Fixed32Rules describes the constraints applied to `fixed32` values.
| Field | Type | Label | Description |
| const | fixed32 | optional | `const` requires the field value to exactly match the specified value. If the field value doesn't match, an error message is generated. ```proto message MyFixed32 { // value must equal 42 fixed32 value = 1 [(buf.validate.field).fixed32.const = 42]; } ``` |
| lt | fixed32 | `lt` requires the field value to be less than the specified value (field < value). If the field value is equal to or greater than the specified value, an error message is generated. ```proto message MyFixed32 { // value must be less than 10 fixed32 value = 1 [(buf.validate.field).fixed32.lt = 10]; } ``` |
|
| lte | fixed32 | `lte` requires the field value to be less than or equal to the specified value (field <= value). If the field value is greater than the specified value, an error message is generated. ```proto message MyFixed32 { // value must be less than or equal to 10 fixed32 value = 1 [(buf.validate.field).fixed32.lte = 10]; } ``` |
|
| gt | fixed32 | `gt` requires the field value to be greater than the specified value (exclusive). If the value of `gt` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyFixed32 { // value must be greater than 5 [fixed32.gt] fixed32 value = 1 [(buf.validate.field).fixed32.gt = 5]; // value must be greater than 5 and less than 10 [fixed32.gt_lt] fixed32 other_value = 2 [(buf.validate.field).fixed32 = { gt: 5, lt: 10 }]; // value must be greater than 10 or less than 5 [fixed32.gt_lt_exclusive] fixed32 another_value = 3 [(buf.validate.field).fixed32 = { gt: 10, lt: 5 }]; } ``` |
|
| gte | fixed32 | `gte` requires the field value to be greater than or equal to the specified value (exclusive). If the value of `gte` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyFixed32 { // value must be greater than or equal to 5 [fixed32.gte] fixed32 value = 1 [(buf.validate.field).fixed32.gte = 5]; // value must be greater than or equal to 5 and less than 10 [fixed32.gte_lt] fixed32 other_value = 2 [(buf.validate.field).fixed32 = { gte: 5, lt: 10 }]; // value must be greater than or equal to 10 or less than 5 [fixed32.gte_lt_exclusive] fixed32 another_value = 3 [(buf.validate.field).fixed32 = { gte: 10, lt: 5 }]; } ``` |
|
| in | fixed32 | repeated | `in` requires the field value to be equal to one of the specified values. If the field value isn't one of the specified values, an error message is generated. ```proto message MyFixed32 { // value must be in list [1, 2, 3] repeated fixed32 value = 1 (buf.validate.field).fixed32 = { in: [1, 2, 3] }; } ``` |
| not_in | fixed32 | repeated | `not_in` requires the field value to not be equal to any of the specified values. If the field value is one of the specified values, an error message is generated. ```proto message MyFixed32 { // value must not be in list [1, 2, 3] repeated fixed32 value = 1 (buf.validate.field).fixed32 = { not_in: [1, 2, 3] }; } ``` |
Fixed64Rules describes the constraints applied to `fixed64` values.
| Field | Type | Label | Description |
| const | fixed64 | optional | `const` requires the field value to exactly match the specified value. If the field value doesn't match, an error message is generated. ```proto message MyFixed64 { // value must equal 42 fixed64 value = 1 [(buf.validate.field).fixed64.const = 42]; } ``` |
| lt | fixed64 | `lt` requires the field value to be less than the specified value (field < value). If the field value is equal to or greater than the specified value, an error message is generated. ```proto message MyFixed64 { // value must be less than 10 fixed64 value = 1 [(buf.validate.field).fixed64.lt = 10]; } ``` |
|
| lte | fixed64 | `lte` requires the field value to be less than or equal to the specified value (field <= value). If the field value is greater than the specified value, an error message is generated. ```proto message MyFixed64 { // value must be less than or equal to 10 fixed64 value = 1 [(buf.validate.field).fixed64.lte = 10]; } ``` |
|
| gt | fixed64 | `gt` requires the field value to be greater than the specified value (exclusive). If the value of `gt` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyFixed64 { // value must be greater than 5 [fixed64.gt] fixed64 value = 1 [(buf.validate.field).fixed64.gt = 5]; // value must be greater than 5 and less than 10 [fixed64.gt_lt] fixed64 other_value = 2 [(buf.validate.field).fixed64 = { gt: 5, lt: 10 }]; // value must be greater than 10 or less than 5 [fixed64.gt_lt_exclusive] fixed64 another_value = 3 [(buf.validate.field).fixed64 = { gt: 10, lt: 5 }]; } ``` |
|
| gte | fixed64 | `gte` requires the field value to be greater than or equal to the specified value (exclusive). If the value of `gte` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyFixed64 { // value must be greater than or equal to 5 [fixed64.gte] fixed64 value = 1 [(buf.validate.field).fixed64.gte = 5]; // value must be greater than or equal to 5 and less than 10 [fixed64.gte_lt] fixed64 other_value = 2 [(buf.validate.field).fixed64 = { gte: 5, lt: 10 }]; // value must be greater than or equal to 10 or less than 5 [fixed64.gte_lt_exclusive] fixed64 another_value = 3 [(buf.validate.field).fixed64 = { gte: 10, lt: 5 }]; } ``` |
|
| in | fixed64 | repeated | `in` requires the field value to be equal to one of the specified values. If the field value isn't one of the specified values, an error message is generated. ```proto message MyFixed64 { // value must be in list [1, 2, 3] repeated fixed64 value = 1 (buf.validate.field).fixed64 = { in: [1, 2, 3] }; } ``` |
| not_in | fixed64 | repeated | `not_in` requires the field value to not be equal to any of the specified values. If the field value is one of the specified values, an error message is generated. ```proto message MyFixed64 { // value must not be in list [1, 2, 3] repeated fixed64 value = 1 (buf.validate.field).fixed64 = { not_in: [1, 2, 3] }; } ``` |
FloatRules describes the constraints applied to `float` values. These
rules may also be applied to the `google.protobuf.FloatValue` Well-Known-Type.
| Field | Type | Label | Description |
| const | float | optional | `const` requires the field value to exactly match the specified value. If the field value doesn't match, an error message is generated. ```proto message MyFloat { // value must equal 42.0 float value = 1 [(buf.validate.field).float.const = 42.0]; } ``` |
| lt | float | `lt` requires the field value to be less than the specified value (field < value). If the field value is equal to or greater than the specified value, an error message is generated. ```proto message MyFloat { // value must be less than 10.0 float value = 1 [(buf.validate.field).float.lt = 10.0]; } ``` |
|
| lte | float | `lte` requires the field value to be less than or equal to the specified value (field <= value). If the field value is greater than the specified value, an error message is generated. ```proto message MyFloat { // value must be less than or equal to 10.0 float value = 1 [(buf.validate.field).float.lte = 10.0]; } ``` |
|
| gt | float | `gt` requires the field value to be greater than the specified value (exclusive). If the value of `gt` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyFloat { // value must be greater than 5.0 [float.gt] float value = 1 [(buf.validate.field).float.gt = 5.0]; // value must be greater than 5 and less than 10.0 [float.gt_lt] float other_value = 2 [(buf.validate.field).float = { gt: 5.0, lt: 10.0 }]; // value must be greater than 10 or less than 5.0 [float.gt_lt_exclusive] float another_value = 3 [(buf.validate.field).float = { gt: 10.0, lt: 5.0 }]; } ``` |
|
| gte | float | `gte` requires the field value to be greater than or equal to the specified value (exclusive). If the value of `gte` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyFloat { // value must be greater than or equal to 5.0 [float.gte] float value = 1 [(buf.validate.field).float.gte = 5.0]; // value must be greater than or equal to 5.0 and less than 10.0 [float.gte_lt] float other_value = 2 [(buf.validate.field).float = { gte: 5.0, lt: 10.0 }]; // value must be greater than or equal to 10.0 or less than 5.0 [float.gte_lt_exclusive] float another_value = 3 [(buf.validate.field).float = { gte: 10.0, lt: 5.0 }]; } ``` |
|
| in | float | repeated | `in` requires the field value to be equal to one of the specified values. If the field value isn't one of the specified values, an error message is generated. ```proto message MyFloat { // value must be in list [1.0, 2.0, 3.0] repeated float value = 1 (buf.validate.field).float = { in: [1.0, 2.0, 3.0] }; } ``` |
| not_in | float | repeated | `in` requires the field value to not be equal to any of the specified values. If the field value is one of the specified values, an error message is generated. ```proto message MyFloat { // value must not be in list [1.0, 2.0, 3.0] repeated float value = 1 (buf.validate.field).float = { not_in: [1.0, 2.0, 3.0] }; } ``` |
| finite | bool | `finite` requires the field value to be finite. If the field value is infinite or NaN, an error message is generated. |
Int32Rules describes the constraints applied to `int32` values. These
rules may also be applied to the `google.protobuf.Int32Value` Well-Known-Type.
| Field | Type | Label | Description |
| const | int32 | optional | `const` requires the field value to exactly match the specified value. If the field value doesn't match, an error message is generated. ```proto message MyInt32 { // value must equal 42 int32 value = 1 [(buf.validate.field).int32.const = 42]; } ``` |
| lt | int32 | `lt` requires the field value to be less than the specified value (field < value). If the field value is equal to or greater than the specified value, an error message is generated. ```proto message MyInt32 { // value must be less than 10 int32 value = 1 [(buf.validate.field).int32.lt = 10]; } ``` |
|
| lte | int32 | `lte` requires the field value to be less than or equal to the specified value (field <= value). If the field value is greater than the specified value, an error message is generated. ```proto message MyInt32 { // value must be less than or equal to 10 int32 value = 1 [(buf.validate.field).int32.lte = 10]; } ``` |
|
| gt | int32 | `gt` requires the field value to be greater than the specified value (exclusive). If the value of `gt` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyInt32 { // value must be greater than 5 [int32.gt] int32 value = 1 [(buf.validate.field).int32.gt = 5]; // value must be greater than 5 and less than 10 [int32.gt_lt] int32 other_value = 2 [(buf.validate.field).int32 = { gt: 5, lt: 10 }]; // value must be greater than 10 or less than 5 [int32.gt_lt_exclusive] int32 another_value = 3 [(buf.validate.field).int32 = { gt: 10, lt: 5 }]; } ``` |
|
| gte | int32 | `gte` requires the field value to be greater than or equal to the specified value (exclusive). If the value of `gte` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyInt32 { // value must be greater than or equal to 5 [int32.gte] int32 value = 1 [(buf.validate.field).int32.gte = 5]; // value must be greater than or equal to 5 and less than 10 [int32.gte_lt] int32 other_value = 2 [(buf.validate.field).int32 = { gte: 5, lt: 10 }]; // value must be greater than or equal to 10 or less than 5 [int32.gte_lt_exclusive] int32 another_value = 3 [(buf.validate.field).int32 = { gte: 10, lt: 5 }]; } ``` |
|
| in | int32 | repeated | `in` requires the field value to be equal to one of the specified values. If the field value isn't one of the specified values, an error message is generated. ```proto message MyInt32 { // value must be in list [1, 2, 3] repeated int32 value = 1 (buf.validate.field).int32 = { in: [1, 2, 3] }; } ``` |
| not_in | int32 | repeated | `not_in` requires the field value to not be equal to any of the specified values. If the field value is one of the specified values, an error message is generated. ```proto message MyInt32 { // value must not be in list [1, 2, 3] repeated int32 value = 1 (buf.validate.field).int32 = { not_in: [1, 2, 3] }; } ``` |
Int64Rules describes the constraints applied to `int64` values. These
rules may also be applied to the `google.protobuf.Int64Value` Well-Known-Type.
| Field | Type | Label | Description |
| const | int64 | optional | `const` requires the field value to exactly match the specified value. If the field value doesn't match, an error message is generated. ```proto message MyInt64 { // value must equal 42 int64 value = 1 [(buf.validate.field).int64.const = 42]; } ``` |
| lt | int64 | `lt` requires the field value to be less than the specified value (field < value). If the field value is equal to or greater than the specified value, an error message is generated. ```proto message MyInt64 { // value must be less than 10 int64 value = 1 [(buf.validate.field).int64.lt = 10]; } ``` |
|
| lte | int64 | `lte` requires the field value to be less than or equal to the specified value (field <= value). If the field value is greater than the specified value, an error message is generated. ```proto message MyInt64 { // value must be less than or equal to 10 int64 value = 1 [(buf.validate.field).int64.lte = 10]; } ``` |
|
| gt | int64 | `gt` requires the field value to be greater than the specified value (exclusive). If the value of `gt` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyInt64 { // value must be greater than 5 [int64.gt] int64 value = 1 [(buf.validate.field).int64.gt = 5]; // value must be greater than 5 and less than 10 [int64.gt_lt] int64 other_value = 2 [(buf.validate.field).int64 = { gt: 5, lt: 10 }]; // value must be greater than 10 or less than 5 [int64.gt_lt_exclusive] int64 another_value = 3 [(buf.validate.field).int64 = { gt: 10, lt: 5 }]; } ``` |
|
| gte | int64 | `gte` requires the field value to be greater than or equal to the specified value (exclusive). If the value of `gte` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyInt64 { // value must be greater than or equal to 5 [int64.gte] int64 value = 1 [(buf.validate.field).int64.gte = 5]; // value must be greater than or equal to 5 and less than 10 [int64.gte_lt] int64 other_value = 2 [(buf.validate.field).int64 = { gte: 5, lt: 10 }]; // value must be greater than or equal to 10 or less than 5 [int64.gte_lt_exclusive] int64 another_value = 3 [(buf.validate.field).int64 = { gte: 10, lt: 5 }]; } ``` |
|
| in | int64 | repeated | `in` requires the field value to be equal to one of the specified values. If the field value isn't one of the specified values, an error message is generated. ```proto message MyInt64 { // value must be in list [1, 2, 3] repeated int64 value = 1 (buf.validate.field).int64 = { in: [1, 2, 3] }; } ``` |
| not_in | int64 | repeated | `not_in` requires the field value to not be equal to any of the specified values. If the field value is one of the specified values, an error message is generated. ```proto message MyInt64 { // value must not be in list [1, 2, 3] repeated int64 value = 1 (buf.validate.field).int64 = { not_in: [1, 2, 3] }; } ``` |
MapRules describe the constraints applied to `map` values.
| Field | Type | Label | Description |
| min_pairs | uint64 | optional | Specifies the minimum number of key-value pairs allowed. If the field has fewer key-value pairs than specified, an error message is generated. ```proto message MyMap { // The field `value` must have at least 2 key-value pairs. map<string, string> value = 1 [(buf.validate.field).map.min_pairs = 2]; } ``` |
| max_pairs | uint64 | optional | Specifies the maximum number of key-value pairs allowed. If the field has more key-value pairs than specified, an error message is generated. ```proto message MyMap { // The field `value` must have at most 3 key-value pairs. map<string, string> value = 1 [(buf.validate.field).map.max_pairs = 3]; } ``` |
| keys | FieldConstraints | optional | Specifies the constraints to be applied to each key in the field. ```proto message MyMap { // The keys in the field `value` must follow the specified constraints. map<string, string> value = 1 [(buf.validate.field).map.keys = { string: { min_len: 3 max_len: 10 } }]; } ``` |
| values | FieldConstraints | optional | Specifies the constraints to be applied to the value of each key in the field. Message values will still have their validations evaluated unless skip is specified here. ```proto message MyMap { // The values in the field `value` must follow the specified constraints. map<string, string> value = 1 [(buf.validate.field).map.values = { string: { min_len: 5 max_len: 20 } }]; } ``` |
MessageConstraints represents validation rules that are applied to the entire message.
It includes disabling options and a list of Constraint messages representing Common Expression Language (CEL) validation rules.
| Field | Type | Label | Description |
| disabled | bool | optional | `disabled` is a boolean flag that, when set to true, nullifies any validation rules for this message. This includes any fields within the message that would otherwise support validation. ```proto message MyMessage { // validation will be bypassed for this message option (buf.validate.message).disabled = true; } ``` |
| cel | Constraint | repeated | `cel` is a repeated field of type Constraint. Each Constraint specifies a validation rule to be applied to this message. These constraints are written in Common Expression Language (CEL) syntax. For more information on CEL, [see our documentation](https://github.com/bufbuild/protovalidate/blob/main/docs/cel.md). ```proto message MyMessage { // The field `foo` must be greater than 42. option (buf.validate.message).cel = { id: "my_message.value", message: "value must be greater than 42", expression: "this.foo > 42", }; optional int32 foo = 1; } ``` |
The `OneofConstraints` message type enables you to manage constraints for
oneof fields in your protobuf messages.
| Field | Type | Label | Description |
| required | bool | optional | If `required` is true, exactly one field of the oneof must be present. A validation error is returned if no fields in the oneof are present. The field itself may still be a default value; further constraints should be placed on the fields themselves to ensure they are valid values, such as `min_len` or `gt`. ```proto message MyMessage { oneof value { // Either `a` or `b` must be set. If `a` is set, it must also be // non-empty; whereas if `b` is set, it can still be an empty string. option (buf.validate.oneof).required = true; string a = 1 [(buf.validate.field).string.min_len = 1]; string b = 2; } } ``` |
RepeatedRules describe the constraints applied to `repeated` values.
| Field | Type | Label | Description |
| min_items | uint64 | optional | `min_items` requires that this field must contain at least the specified minimum number of items. Note that `min_items = 1` is equivalent to setting a field as `required`. ```proto message MyRepeated { // value must contain at least 2 items repeated string value = 1 [(buf.validate.field).repeated.min_items = 2]; } ``` |
| max_items | uint64 | optional | `max_items` denotes that this field must not exceed a certain number of items as the upper limit. If the field contains more items than specified, an error message will be generated, requiring the field to maintain no more than the specified number of items. ```proto message MyRepeated { // value must contain no more than 3 item(s) repeated string value = 1 [(buf.validate.field).repeated.max_items = 3]; } ``` |
| unique | bool | optional | `unique` indicates that all elements in this field must be unique. This constraint is strictly applicable to scalar and enum types, with message types not being supported. ```proto message MyRepeated { // repeated value must contain unique items repeated string value = 1 [(buf.validate.field).repeated.unique = true]; } ``` |
| items | FieldConstraints | optional | `items` details the constraints to be applied to each item in the field. Even for repeated message fields, validation is executed against each item unless skip is explicitly specified. ```proto message MyRepeated { // The items in the field `value` must follow the specified constraints. repeated string value = 1 [(buf.validate.field).repeated.items = { string: { min_len: 3 max_len: 10 } }]; } ``` |
SFixed32Rules describes the constraints applied to `fixed32` values.
| Field | Type | Label | Description |
| const | sfixed32 | optional | `const` requires the field value to exactly match the specified value. If the field value doesn't match, an error message is generated. ```proto message MySFixed32 { // value must equal 42 sfixed32 value = 1 [(buf.validate.field).sfixed32.const = 42]; } ``` |
| lt | sfixed32 | `lt` requires the field value to be less than the specified value (field < value). If the field value is equal to or greater than the specified value, an error message is generated. ```proto message MySFixed32 { // value must be less than 10 sfixed32 value = 1 [(buf.validate.field).sfixed32.lt = 10]; } ``` |
|
| lte | sfixed32 | `lte` requires the field value to be less than or equal to the specified value (field <= value). If the field value is greater than the specified value, an error message is generated. ```proto message MySFixed32 { // value must be less than or equal to 10 sfixed32 value = 1 [(buf.validate.field).sfixed32.lte = 10]; } ``` |
|
| gt | sfixed32 | `gt` requires the field value to be greater than the specified value (exclusive). If the value of `gt` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MySFixed32 { // value must be greater than 5 [sfixed32.gt] sfixed32 value = 1 [(buf.validate.field).sfixed32.gt = 5]; // value must be greater than 5 and less than 10 [sfixed32.gt_lt] sfixed32 other_value = 2 [(buf.validate.field).sfixed32 = { gt: 5, lt: 10 }]; // value must be greater than 10 or less than 5 [sfixed32.gt_lt_exclusive] sfixed32 another_value = 3 [(buf.validate.field).sfixed32 = { gt: 10, lt: 5 }]; } ``` |
|
| gte | sfixed32 | `gte` requires the field value to be greater than or equal to the specified value (exclusive). If the value of `gte` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MySFixed32 { // value must be greater than or equal to 5 [sfixed32.gte] sfixed32 value = 1 [(buf.validate.field).sfixed32.gte = 5]; // value must be greater than or equal to 5 and less than 10 [sfixed32.gte_lt] sfixed32 other_value = 2 [(buf.validate.field).sfixed32 = { gte: 5, lt: 10 }]; // value must be greater than or equal to 10 or less than 5 [sfixed32.gte_lt_exclusive] sfixed32 another_value = 3 [(buf.validate.field).sfixed32 = { gte: 10, lt: 5 }]; } ``` |
|
| in | sfixed32 | repeated | `in` requires the field value to be equal to one of the specified values. If the field value isn't one of the specified values, an error message is generated. ```proto message MySFixed32 { // value must be in list [1, 2, 3] repeated sfixed32 value = 1 (buf.validate.field).sfixed32 = { in: [1, 2, 3] }; } ``` |
| not_in | sfixed32 | repeated | `not_in` requires the field value to not be equal to any of the specified values. If the field value is one of the specified values, an error message is generated. ```proto message MySFixed32 { // value must not be in list [1, 2, 3] repeated sfixed32 value = 1 (buf.validate.field).sfixed32 = { not_in: [1, 2, 3] }; } ``` |
SFixed64Rules describes the constraints applied to `fixed64` values.
| Field | Type | Label | Description |
| const | sfixed64 | optional | `const` requires the field value to exactly match the specified value. If the field value doesn't match, an error message is generated. ```proto message MySFixed64 { // value must equal 42 sfixed64 value = 1 [(buf.validate.field).sfixed64.const = 42]; } ``` |
| lt | sfixed64 | `lt` requires the field value to be less than the specified value (field < value). If the field value is equal to or greater than the specified value, an error message is generated. ```proto message MySFixed64 { // value must be less than 10 sfixed64 value = 1 [(buf.validate.field).sfixed64.lt = 10]; } ``` |
|
| lte | sfixed64 | `lte` requires the field value to be less than or equal to the specified value (field <= value). If the field value is greater than the specified value, an error message is generated. ```proto message MySFixed64 { // value must be less than or equal to 10 sfixed64 value = 1 [(buf.validate.field).sfixed64.lte = 10]; } ``` |
|
| gt | sfixed64 | `gt` requires the field value to be greater than the specified value (exclusive). If the value of `gt` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MySFixed64 { // value must be greater than 5 [sfixed64.gt] sfixed64 value = 1 [(buf.validate.field).sfixed64.gt = 5]; // value must be greater than 5 and less than 10 [sfixed64.gt_lt] sfixed64 other_value = 2 [(buf.validate.field).sfixed64 = { gt: 5, lt: 10 }]; // value must be greater than 10 or less than 5 [sfixed64.gt_lt_exclusive] sfixed64 another_value = 3 [(buf.validate.field).sfixed64 = { gt: 10, lt: 5 }]; } ``` |
|
| gte | sfixed64 | `gte` requires the field value to be greater than or equal to the specified value (exclusive). If the value of `gte` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MySFixed64 { // value must be greater than or equal to 5 [sfixed64.gte] sfixed64 value = 1 [(buf.validate.field).sfixed64.gte = 5]; // value must be greater than or equal to 5 and less than 10 [sfixed64.gte_lt] sfixed64 other_value = 2 [(buf.validate.field).sfixed64 = { gte: 5, lt: 10 }]; // value must be greater than or equal to 10 or less than 5 [sfixed64.gte_lt_exclusive] sfixed64 another_value = 3 [(buf.validate.field).sfixed64 = { gte: 10, lt: 5 }]; } ``` |
|
| in | sfixed64 | repeated | `in` requires the field value to be equal to one of the specified values. If the field value isn't one of the specified values, an error message is generated. ```proto message MySFixed64 { // value must be in list [1, 2, 3] repeated sfixed64 value = 1 (buf.validate.field).sfixed64 = { in: [1, 2, 3] }; } ``` |
| not_in | sfixed64 | repeated | `not_in` requires the field value to not be equal to any of the specified values. If the field value is one of the specified values, an error message is generated. ```proto message MySFixed64 { // value must not be in list [1, 2, 3] repeated sfixed64 value = 1 (buf.validate.field).sfixed64 = { not_in: [1, 2, 3] }; } ``` |
SInt32Rules describes the constraints applied to `sint32` values.
| Field | Type | Label | Description |
| const | sint32 | optional | `const` requires the field value to exactly match the specified value. If the field value doesn't match, an error message is generated. ```proto message MySInt32 { // value must equal 42 sint32 value = 1 [(buf.validate.field).sint32.const = 42]; } ``` |
| lt | sint32 | `lt` requires the field value to be less than the specified value (field < value). If the field value is equal to or greater than the specified value, an error message is generated. ```proto message MySInt32 { // value must be less than 10 sint32 value = 1 [(buf.validate.field).sint32.lt = 10]; } ``` |
|
| lte | sint32 | `lte` requires the field value to be less than or equal to the specified value (field <= value). If the field value is greater than the specified value, an error message is generated. ```proto message MySInt32 { // value must be less than or equal to 10 sint32 value = 1 [(buf.validate.field).sint32.lte = 10]; } ``` |
|
| gt | sint32 | `gt` requires the field value to be greater than the specified value (exclusive). If the value of `gt` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MySInt32 { // value must be greater than 5 [sint32.gt] sint32 value = 1 [(buf.validate.field).sint32.gt = 5]; // value must be greater than 5 and less than 10 [sint32.gt_lt] sint32 other_value = 2 [(buf.validate.field).sint32 = { gt: 5, lt: 10 }]; // value must be greater than 10 or less than 5 [sint32.gt_lt_exclusive] sint32 another_value = 3 [(buf.validate.field).sint32 = { gt: 10, lt: 5 }]; } ``` |
|
| gte | sint32 | `gte` requires the field value to be greater than or equal to the specified value (exclusive). If the value of `gte` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MySInt32 { // value must be greater than or equal to 5 [sint32.gte] sint32 value = 1 [(buf.validate.field).sint32.gte = 5]; // value must be greater than or equal to 5 and less than 10 [sint32.gte_lt] sint32 other_value = 2 [(buf.validate.field).sint32 = { gte: 5, lt: 10 }]; // value must be greater than or equal to 10 or less than 5 [sint32.gte_lt_exclusive] sint32 another_value = 3 [(buf.validate.field).sint32 = { gte: 10, lt: 5 }]; } ``` |
|
| in | sint32 | repeated | `in` requires the field value to be equal to one of the specified values. If the field value isn't one of the specified values, an error message is generated. ```proto message MySInt32 { // value must be in list [1, 2, 3] repeated sint32 value = 1 (buf.validate.field).sint32 = { in: [1, 2, 3] }; } ``` |
| not_in | sint32 | repeated | `not_in` requires the field value to not be equal to any of the specified values. If the field value is one of the specified values, an error message is generated. ```proto message MySInt32 { // value must not be in list [1, 2, 3] repeated sint32 value = 1 (buf.validate.field).sint32 = { not_in: [1, 2, 3] }; } ``` |
SInt64Rules describes the constraints applied to `sint64` values.
| Field | Type | Label | Description |
| const | sint64 | optional | `const` requires the field value to exactly match the specified value. If the field value doesn't match, an error message is generated. ```proto message MySInt64 { // value must equal 42 sint64 value = 1 [(buf.validate.field).sint64.const = 42]; } ``` |
| lt | sint64 | `lt` requires the field value to be less than the specified value (field < value). If the field value is equal to or greater than the specified value, an error message is generated. ```proto message MySInt64 { // value must be less than 10 sint64 value = 1 [(buf.validate.field).sint64.lt = 10]; } ``` |
|
| lte | sint64 | `lte` requires the field value to be less than or equal to the specified value (field <= value). If the field value is greater than the specified value, an error message is generated. ```proto message MySInt64 { // value must be less than or equal to 10 sint64 value = 1 [(buf.validate.field).sint64.lte = 10]; } ``` |
|
| gt | sint64 | `gt` requires the field value to be greater than the specified value (exclusive). If the value of `gt` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MySInt64 { // value must be greater than 5 [sint64.gt] sint64 value = 1 [(buf.validate.field).sint64.gt = 5]; // value must be greater than 5 and less than 10 [sint64.gt_lt] sint64 other_value = 2 [(buf.validate.field).sint64 = { gt: 5, lt: 10 }]; // value must be greater than 10 or less than 5 [sint64.gt_lt_exclusive] sint64 another_value = 3 [(buf.validate.field).sint64 = { gt: 10, lt: 5 }]; } ``` |
|
| gte | sint64 | `gte` requires the field value to be greater than or equal to the specified value (exclusive). If the value of `gte` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MySInt64 { // value must be greater than or equal to 5 [sint64.gte] sint64 value = 1 [(buf.validate.field).sint64.gte = 5]; // value must be greater than or equal to 5 and less than 10 [sint64.gte_lt] sint64 other_value = 2 [(buf.validate.field).sint64 = { gte: 5, lt: 10 }]; // value must be greater than or equal to 10 or less than 5 [sint64.gte_lt_exclusive] sint64 another_value = 3 [(buf.validate.field).sint64 = { gte: 10, lt: 5 }]; } ``` |
|
| in | sint64 | repeated | `in` requires the field value to be equal to one of the specified values. If the field value isn't one of the specified values, an error message is generated. ```proto message MySInt64 { // value must be in list [1, 2, 3] repeated sint64 value = 1 (buf.validate.field).sint64 = { in: [1, 2, 3] }; } ``` |
| not_in | sint64 | repeated | `not_in` requires the field value to not be equal to any of the specified values. If the field value is one of the specified values, an error message is generated. ```proto message MySInt64 { // value must not be in list [1, 2, 3] repeated sint64 value = 1 (buf.validate.field).sint64 = { not_in: [1, 2, 3] }; } ``` |
StringRules describes the constraints applied to `string` values These
rules may also be applied to the `google.protobuf.StringValue` Well-Known-Type.
| Field | Type | Label | Description |
| const | string | optional | `const` requires the field value to exactly match the specified value. If the field value doesn't match, an error message is generated. ```proto message MyString { // value must equal `hello` string value = 1 [(buf.validate.field).string.const = "hello"]; } ``` |
| len | uint64 | optional | `len` dictates that the field value must have the specified number of characters (Unicode code points), which may differ from the number of bytes in the string. If the field value does not meet the specified length, an error message will be generated. ```proto message MyString { // value length must be 5 characters string value = 1 [(buf.validate.field).string.len = 5]; } ``` |
| min_len | uint64 | optional | `min_len` specifies that the field value must have at least the specified number of characters (Unicode code points), which may differ from the number of bytes in the string. If the field value contains fewer characters, an error message will be generated. ```proto message MyString { // value length must be at least 3 characters string value = 1 [(buf.validate.field).string.min_len = 3]; } ``` |
| max_len | uint64 | optional | `max_len` specifies that the field value must have no more than the specified number of characters (Unicode code points), which may differ from the number of bytes in the string. If the field value contains more characters, an error message will be generated. ```proto message MyString { // value length must be at most 10 characters string value = 1 [(buf.validate.field).string.max_len = 10]; } ``` |
| len_bytes | uint64 | optional | `len_bytes` dictates that the field value must have the specified number of bytes. If the field value does not match the specified length in bytes, an error message will be generated. ```proto message MyString { // value length must be 6 bytes string value = 1 [(buf.validate.field).string.len_bytes = 6]; } ``` |
| min_bytes | uint64 | optional | `min_bytes` specifies that the field value must have at least the specified number of bytes. If the field value contains fewer bytes, an error message will be generated. ```proto message MyString { // value length must be at least 4 bytes string value = 1 [(buf.validate.field).string.min_bytes = 4]; } ``` |
| max_bytes | uint64 | optional | `max_bytes` specifies that the field value must have no more than the specified number of bytes. If the field value contains more bytes, an error message will be generated. ```proto message MyString { // value length must be at most 8 bytes string value = 1 [(buf.validate.field).string.max_bytes = 8]; } ``` |
| pattern | string | optional | `pattern` specifies that the field value must match the specified regular expression (RE2 syntax), with the expression provided without any delimiters. If the field value doesn't match the regular expression, an error message will be generated. ```proto message MyString { // value does not match regex pattern `^[a-zA-Z]//$` string value = 1 [(buf.validate.field).string.pattern = "^[a-zA-Z]//$"]; } ``` |
| prefix | string | optional | `prefix` specifies that the field value must have the specified substring at the beginning of the string. If the field value doesn't start with the specified prefix, an error message will be generated. ```proto message MyString { // value does not have prefix `pre` string value = 1 [(buf.validate.field).string.prefix = "pre"]; } ``` |
| suffix | string | optional | `suffix` specifies that the field value must have the specified substring at the end of the string. If the field value doesn't end with the specified suffix, an error message will be generated. ```proto message MyString { // value does not have suffix `post` string value = 1 [(buf.validate.field).string.suffix = "post"]; } ``` |
| contains | string | optional | `contains` specifies that the field value must have the specified substring anywhere in the string. If the field value doesn't contain the specified substring, an error message will be generated. ```proto message MyString { // value does not contain substring `inside`. string value = 1 [(buf.validate.field).string.contains = "inside"]; } ``` |
| not_contains | string | optional | `not_contains` specifies that the field value must not have the specified substring anywhere in the string. If the field value contains the specified substring, an error message will be generated. ```proto message MyString { // value contains substring `inside`. string value = 1 [(buf.validate.field).string.not_contains = "inside"]; } ``` |
| in | string | repeated | `in` specifies that the field value must be equal to one of the specified values. If the field value isn't one of the specified values, an error message will be generated. ```proto message MyString { // value must be in list ["apple", "banana"] repeated string value = 1 [(buf.validate.field).string.in = "apple", (buf.validate.field).string.in = "banana"]; } ``` |
| not_in | string | repeated | `not_in` specifies that the field value cannot be equal to any of the specified values. If the field value is one of the specified values, an error message will be generated. ```proto message MyString { // value must not be in list ["orange", "grape"] repeated string value = 1 [(buf.validate.field).string.not_in = "orange", (buf.validate.field).string.not_in = "grape"]; } ``` |
| bool | `email` specifies that the field value must be a valid email address (addr-spec only) as defined by [RFC 5322](https://tools.ietf.org/html/rfc5322#section-3.4.1). If the field value isn't a valid email address, an error message will be generated. ```proto message MyString { // value must be a valid email address string value = 1 [(buf.validate.field).string.email = true]; } ``` |
||
| hostname | bool | `hostname` specifies that the field value must be a valid hostname as defined by [RFC 1034](https://tools.ietf.org/html/rfc1034#section-3.5). This constraint doesn't support internationalized domain names (IDNs). If the field value isn't a valid hostname, an error message will be generated. ```proto message MyString { // value must be a valid hostname string value = 1 [(buf.validate.field).string.hostname = true]; } ``` |
|
| ip | bool | `ip` specifies that the field value must be a valid IP (v4 or v6) address, without surrounding square brackets for IPv6 addresses. If the field value isn't a valid IP address, an error message will be generated. ```proto message MyString { // value must be a valid IP address string value = 1 [(buf.validate.field).string.ip = true]; } ``` |
|
| ipv4 | bool | `ipv4` specifies that the field value must be a valid IPv4 address. If the field value isn't a valid IPv4 address, an error message will be generated. ```proto message MyString { // value must be a valid IPv4 address string value = 1 [(buf.validate.field).string.ipv4 = true]; } ``` |
|
| ipv6 | bool | `ipv6` specifies that the field value must be a valid IPv6 address, without surrounding square brackets. If the field value is not a valid IPv6 address, an error message will be generated. ```proto message MyString { // value must be a valid IPv6 address string value = 1 [(buf.validate.field).string.ipv6 = true]; } ``` |
|
| uri | bool | `uri` specifies that the field value must be a valid, absolute URI as defined by [RFC 3986](https://tools.ietf.org/html/rfc3986#section-3). If the field value isn't a valid, absolute URI, an error message will be generated. ```proto message MyString { // value must be a valid URI string value = 1 [(buf.validate.field).string.uri = true]; } ``` |
|
| uri_ref | bool | `uri_ref` specifies that the field value must be a valid URI as defined by [RFC 3986](https://tools.ietf.org/html/rfc3986#section-3) and may be either relative or absolute. If the field value isn't a valid URI, an error message will be generated. ```proto message MyString { // value must be a valid URI string value = 1 [(buf.validate.field).string.uri_ref = true]; } ``` |
|
| address | bool | `address` specifies that the field value must be either a valid hostname as defined by [RFC 1034](https://tools.ietf.org/html/rfc1034#section-3.5) (which doesn't support internationalized domain names or IDNs) or a valid IP (v4 or v6). If the field value isn't a valid hostname or IP, an error message will be generated. ```proto message MyString { // value must be a valid hostname, or ip address string value = 1 [(buf.validate.field).string.address = true]; } ``` |
|
| uuid | bool | `uuid` specifies that the field value must be a valid UUID as defined by [RFC 4122](https://tools.ietf.org/html/rfc4122#section-4.1.2). If the field value isn't a valid UUID, an error message will be generated. ```proto message MyString { // value must be a valid UUID string value = 1 [(buf.validate.field).string.uuid = true]; } ``` |
|
| ip_with_prefixlen | bool | `ip_with_prefixlen` specifies that the field value must be a valid IP (v4 or v6) address with prefix length. If the field value isn't a valid IP with prefix length, an error message will be generated. ```proto message MyString { // value must be a valid IP with prefix length string value = 1 [(buf.validate.field).string.ip_with_prefixlen = true]; } ``` |
|
| ipv4_with_prefixlen | bool | `ipv4_with_prefixlen` specifies that the field value must be a valid IPv4 address with prefix. If the field value isn't a valid IPv4 address with prefix length, an error message will be generated. ```proto message MyString { // value must be a valid IPv4 address with prefix lentgh string value = 1 [(buf.validate.field).string.ipv4_with_prefixlen = true]; } ``` |
|
| ipv6_with_prefixlen | bool | `ipv6_with_prefixlen` specifies that the field value must be a valid IPv6 address with prefix length. If the field value is not a valid IPv6 address with prefix length, an error message will be generated. ```proto message MyString { // value must be a valid IPv6 address prefix length string value = 1 [(buf.validate.field).string.ipv6_with_prefixlen = true]; } ``` |
|
| ip_prefix | bool | `ip_prefix` specifies that the field value must be a valid IP (v4 or v6) prefix. If the field value isn't a valid IP prefix, an error message will be generated. The prefix must have all zeros for the masked bits of the prefix (e.g., `127.0.0.0/16`, not `127.0.0.1/16`). ```proto message MyString { // value must be a valid IP prefix string value = 1 [(buf.validate.field).string.ip_prefix = true]; } ``` |
|
| ipv4_prefix | bool | `ipv4_prefix` specifies that the field value must be a valid IPv4 prefix. If the field value isn't a valid IPv4 prefix, an error message will be generated. The prefix must have all zeros for the masked bits of the prefix (e.g., `127.0.0.0/16`, not `127.0.0.1/16`). ```proto message MyString { // value must be a valid IPv4 prefix string value = 1 [(buf.validate.field).string.ipv4_prefix = true]; } ``` |
|
| ipv6_prefix | bool | `ipv6_prefix` specifies that the field value must be a valid IPv6 prefix. If the field value is not a valid IPv6 prefix, an error message will be generated. The prefix must have all zeros for the masked bits of the prefix (e.g., `2001:db8::/48`, not `2001:db8::1/48`). ```proto message MyString { // value must be a valid IPv6 prefix string value = 1 [(buf.validate.field).string.ipv6_prefix = true]; } ``` |
|
| well_known_regex | KnownRegex | `well_known_regex` specifies a common well-known pattern defined as a regex. If the field value doesn't match the well-known regex, an error message will be generated. ```proto message MyString { // value must be a valid HTTP header value string value = 1 [(buf.validate.field).string.well_known_regex = 2]; } ``` #### KnownRegex `well_known_regex` contains some well-known patterns. | Name | Number | Description | |-------------------------------|--------|-------------------------------------------| | KNOWN_REGEX_UNSPECIFIED | 0 | | | KNOWN_REGEX_HTTP_HEADER_NAME | 1 | HTTP header name as defined by [RFC 7230](https://tools.ietf.org/html/rfc7230#section-3.2) | | KNOWN_REGEX_HTTP_HEADER_VALUE | 2 | HTTP header value as defined by [RFC 7230](https://tools.ietf.org/html/rfc7230#section-3.2.4) | |
|
| strict | bool | optional | This applies to regexes `HTTP_HEADER_NAME` and `HTTP_HEADER_VALUE` to enable strict header validation. By default, this is true, and HTTP header validations are [RFC-compliant](https://tools.ietf.org/html/rfc7230#section-3). Setting to false will enable looser validations that only disallow `\r\n\0` characters, which can be used to bypass header matching rules. ```proto message MyString { // The field `value` must have be a valid HTTP headers, but not enforced with strict rules. string value = 1 [(buf.validate.field).string.strict = false]; } ``` |
TimestampRules describe the constraints applied exclusively to the `google.protobuf.Timestamp` well-known type.
| Field | Type | Label | Description |
| const | google.protobuf.Timestamp | optional | `const` dictates that this field, of the `google.protobuf.Timestamp` type, must exactly match the specified value. If the field value doesn't correspond to the specified timestamp, an error message will be generated. ```proto message MyTimestamp { // value must equal 2023-05-03T10:00:00Z google.protobuf.Timestamp created_at = 1 [(buf.validate.field).timestamp.const = {seconds: 1727998800}]; } ``` |
| lt | google.protobuf.Timestamp | requires the duration field value to be less than the specified value (field < value). If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyDuration { // duration must be less than 'P3D' [duration.lt] google.protobuf.Duration value = 1 [(buf.validate.field).duration.lt = { seconds: 259200 }]; } ``` |
|
| lte | google.protobuf.Timestamp | requires the timestamp field value to be less than or equal to the specified value (field <= value). If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyTimestamp { // timestamp must be less than or equal to '2023-05-14T00:00:00Z' [timestamp.lte] google.protobuf.Timestamp value = 1 [(buf.validate.field).timestamp.lte = { seconds: 1678867200 }]; } ``` |
|
| lt_now | bool | `lt_now` specifies that this field, of the `google.protobuf.Timestamp` type, must be less than the current time. `lt_now` can only be used with the `within` rule. ```proto message MyTimestamp { // value must be less than now google.protobuf.Timestamp created_at = 1 [(buf.validate.field).timestamp.lt_now = true]; } ``` |
|
| gt | google.protobuf.Timestamp | `gt` requires the timestamp field value to be greater than the specified value (exclusive). If the value of `gt` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyTimestamp { // timestamp must be greater than '2023-01-01T00:00:00Z' [timestamp.gt] google.protobuf.Timestamp value = 1 [(buf.validate.field).timestamp.gt = { seconds: 1672444800 }]; // timestamp must be greater than '2023-01-01T00:00:00Z' and less than '2023-01-02T00:00:00Z' [timestamp.gt_lt] google.protobuf.Timestamp another_value = 2 [(buf.validate.field).timestamp = { gt: { seconds: 1672444800 }, lt: { seconds: 1672531200 } }]; // timestamp must be greater than '2023-01-02T00:00:00Z' or less than '2023-01-01T00:00:00Z' [timestamp.gt_lt_exclusive] google.protobuf.Timestamp other_value = 3 [(buf.validate.field).timestamp = { gt: { seconds: 1672531200 }, lt: { seconds: 1672444800 } }]; } ``` |
|
| gte | google.protobuf.Timestamp | `gte` requires the timestamp field value to be greater than or equal to the specified value (exclusive). If the value of `gte` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyTimestamp { // timestamp must be greater than or equal to '2023-01-01T00:00:00Z' [timestamp.gte] google.protobuf.Timestamp value = 1 [(buf.validate.field).timestamp.gte = { seconds: 1672444800 }]; // timestamp must be greater than or equal to '2023-01-01T00:00:00Z' and less than '2023-01-02T00:00:00Z' [timestamp.gte_lt] google.protobuf.Timestamp another_value = 2 [(buf.validate.field).timestamp = { gte: { seconds: 1672444800 }, lt: { seconds: 1672531200 } }]; // timestamp must be greater than or equal to '2023-01-02T00:00:00Z' or less than '2023-01-01T00:00:00Z' [timestamp.gte_lt_exclusive] google.protobuf.Timestamp other_value = 3 [(buf.validate.field).timestamp = { gte: { seconds: 1672531200 }, lt: { seconds: 1672444800 } }]; } ``` |
|
| gt_now | bool | `gt_now` specifies that this field, of the `google.protobuf.Timestamp` type, must be greater than the current time. `gt_now` can only be used with the `within` rule. ```proto message MyTimestamp { // value must be greater than now google.protobuf.Timestamp created_at = 1 [(buf.validate.field).timestamp.gt_now = true]; } ``` |
|
| within | google.protobuf.Duration | optional | `within` specifies that this field, of the `google.protobuf.Timestamp` type, must be within the specified duration of the current time. If the field value isn't within the duration, an error message is generated. ```proto message MyTimestamp { // value must be within 1 hour of now google.protobuf.Timestamp created_at = 1 [(buf.validate.field).timestamp.within = {seconds: 3600}]; } ``` |
UInt32Rules describes the constraints applied to `uint32` values. These
rules may also be applied to the `google.protobuf.UInt32Value` Well-Known-Type.
| Field | Type | Label | Description |
| const | uint32 | optional | `const` requires the field value to exactly match the specified value. If the field value doesn't match, an error message is generated. ```proto message MyUInt32 { // value must equal 42 uint32 value = 1 [(buf.validate.field).uint32.const = 42]; } ``` |
| lt | uint32 | `lt` requires the field value to be less than the specified value (field < value). If the field value is equal to or greater than the specified value, an error message is generated. ```proto message MyUInt32 { // value must be less than 10 uint32 value = 1 [(buf.validate.field).uint32.lt = 10]; } ``` |
|
| lte | uint32 | `lte` requires the field value to be less than or equal to the specified value (field <= value). If the field value is greater than the specified value, an error message is generated. ```proto message MyUInt32 { // value must be less than or equal to 10 uint32 value = 1 [(buf.validate.field).uint32.lte = 10]; } ``` |
|
| gt | uint32 | `gt` requires the field value to be greater than the specified value (exclusive). If the value of `gt` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyUInt32 { // value must be greater than 5 [uint32.gt] uint32 value = 1 [(buf.validate.field).uint32.gt = 5]; // value must be greater than 5 and less than 10 [uint32.gt_lt] uint32 other_value = 2 [(buf.validate.field).uint32 = { gt: 5, lt: 10 }]; // value must be greater than 10 or less than 5 [uint32.gt_lt_exclusive] uint32 another_value = 3 [(buf.validate.field).uint32 = { gt: 10, lt: 5 }]; } ``` |
|
| gte | uint32 | `gte` requires the field value to be greater than or equal to the specified value (exclusive). If the value of `gte` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyUInt32 { // value must be greater than or equal to 5 [uint32.gte] uint32 value = 1 [(buf.validate.field).uint32.gte = 5]; // value must be greater than or equal to 5 and less than 10 [uint32.gte_lt] uint32 other_value = 2 [(buf.validate.field).uint32 = { gte: 5, lt: 10 }]; // value must be greater than or equal to 10 or less than 5 [uint32.gte_lt_exclusive] uint32 another_value = 3 [(buf.validate.field).uint32 = { gte: 10, lt: 5 }]; } ``` |
|
| in | uint32 | repeated | `in` requires the field value to be equal to one of the specified values. If the field value isn't one of the specified values, an error message is generated. ```proto message MyUInt32 { // value must be in list [1, 2, 3] repeated uint32 value = 1 (buf.validate.field).uint32 = { in: [1, 2, 3] }; } ``` |
| not_in | uint32 | repeated | `not_in` requires the field value to not be equal to any of the specified values. If the field value is one of the specified values, an error message is generated. ```proto message MyUInt32 { // value must not be in list [1, 2, 3] repeated uint32 value = 1 (buf.validate.field).uint32 = { not_in: [1, 2, 3] }; } ``` |
UInt64Rules describes the constraints applied to `uint64` values. These
rules may also be applied to the `google.protobuf.UInt64Value` Well-Known-Type.
| Field | Type | Label | Description |
| const | uint64 | optional | `const` requires the field value to exactly match the specified value. If the field value doesn't match, an error message is generated. ```proto message MyUInt64 { // value must equal 42 uint64 value = 1 [(buf.validate.field).uint64.const = 42]; } ``` |
| lt | uint64 | `lt` requires the field value to be less than the specified value (field < value). If the field value is equal to or greater than the specified value, an error message is generated. ```proto message MyUInt64 { // value must be less than 10 uint64 value = 1 [(buf.validate.field).uint64.lt = 10]; } ``` |
|
| lte | uint64 | `lte` requires the field value to be less than or equal to the specified value (field <= value). If the field value is greater than the specified value, an error message is generated. ```proto message MyUInt64 { // value must be less than or equal to 10 uint64 value = 1 [(buf.validate.field).uint64.lte = 10]; } ``` |
|
| gt | uint64 | `gt` requires the field value to be greater than the specified value (exclusive). If the value of `gt` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyUInt64 { // value must be greater than 5 [uint64.gt] uint64 value = 1 [(buf.validate.field).uint64.gt = 5]; // value must be greater than 5 and less than 10 [uint64.gt_lt] uint64 other_value = 2 [(buf.validate.field).uint64 = { gt: 5, lt: 10 }]; // value must be greater than 10 or less than 5 [uint64.gt_lt_exclusive] uint64 another_value = 3 [(buf.validate.field).uint64 = { gt: 10, lt: 5 }]; } ``` |
|
| gte | uint64 | `gte` requires the field value to be greater than or equal to the specified value (exclusive). If the value of `gte` is larger than a specified `lt` or `lte`, the range is reversed, and the field value must be outside the specified range. If the field value doesn't meet the required conditions, an error message is generated. ```proto message MyUInt64 { // value must be greater than or equal to 5 [uint64.gte] uint64 value = 1 [(buf.validate.field).uint64.gte = 5]; // value must be greater than or equal to 5 and less than 10 [uint64.gte_lt] uint64 other_value = 2 [(buf.validate.field).uint64 = { gte: 5, lt: 10 }]; // value must be greater than or equal to 10 or less than 5 [uint64.gte_lt_exclusive] uint64 another_value = 3 [(buf.validate.field).uint64 = { gte: 10, lt: 5 }]; } ``` |
|
| in | uint64 | repeated | `in` requires the field value to be equal to one of the specified values. If the field value isn't one of the specified values, an error message is generated. ```proto message MyUInt64 { // value must be in list [1, 2, 3] repeated uint64 value = 1 (buf.validate.field).uint64 = { in: [1, 2, 3] }; } ``` |
| not_in | uint64 | repeated | `not_in` requires the field value to not be equal to any of the specified values. If the field value is one of the specified values, an error message is generated. ```proto message MyUInt64 { // value must not be in list [1, 2, 3] repeated uint64 value = 1 (buf.validate.field).uint64 = { not_in: [1, 2, 3] }; } ``` |
WellKnownRegex contain some well-known patterns.
| Name | Number | Description |
| KNOWN_REGEX_UNSPECIFIED | 0 | |
| KNOWN_REGEX_HTTP_HEADER_NAME | 1 | HTTP header name as defined by [RFC 7230](https://tools.ietf.org/html/rfc7230#section-3.2). |
| KNOWN_REGEX_HTTP_HEADER_VALUE | 2 | HTTP header value as defined by [RFC 7230](https://tools.ietf.org/html/rfc7230#section-3.2.4). |
| Extension | Type | Base | Number | Description |
| field | FieldConstraints | .google.protobuf.FieldOptions | 1159 | Rules specify the validations to be performed on this field. By default, no validation is performed against a field. |
| message | MessageConstraints | .google.protobuf.MessageOptions | 1159 | Rules specify the validations to be performed on this message. By default, no validation is performed against a message. |
| oneof | OneofConstraints | .google.protobuf.OneofOptions | 1159 | Rules specify the validations to be performed on this oneof. By default, no validation is performed against a oneof. |
| Field | Type | Label | Description |
| user_id | int64 |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | DjangoUser |
|
| Field | Type | Label | Description |
| string |
|
||
| uid | string |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | DjangoUser |
|
| Field | Type | Label | Description |
| id | int64 |
|
|
| name | string |
|
|
| permissions | DjangoPermission | repeated |
|
| Field | Type | Label | Description |
| id | int64 |
|
|
| name | string |
|
|
| codename | string |
|
|
| content_type | int64 |
|
| Field | Type | Label | Description |
| id | int64 |
|
|
| username | string |
|
|
| first_name | string |
|
|
| last_name | string |
|
|
| string |
|
||
| is_staff | bool |
|
|
| is_active | bool |
|
|
| date_joined | google.protobuf.Timestamp |
|
|
| last_login | google.protobuf.Timestamp |
|
|
| is_superuser | bool |
|
|
| avatar_url | string |
|
|
| groups | DjangoGroup | repeated |
|
| user_permissions | DjangoPermission | repeated |
|
| name | string |
|
|
| phone | string |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | UserNotification | repeated |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | DjangoUser |
|
| Field | Type | Label | Description |
| offset | int64 |
|
|
| limit | int64 |
|
|
| user_id | int64 |
|
|
| notify_type | int32 |
|
|
| status | int32 |
|
| Field | Type | Label | Description |
| opts | ListUserNotificationOptions |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | UserNotification | repeated |
|
| Field | Type | Label | Description |
| username | string |
|
|
| password | string |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| token | string |
|
|
| data | DjangoUser |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
| Field | Type | Label | Description |
| string |
|
||
| user_id | int64 |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
| Field | Type | Label | Description |
| data | DjangoUser |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| token | string |
|
|
| data | DjangoUser |
|
| Field | Type | Label | Description |
| string |
|
||
| username | string |
|
|
| password | string |
|
|
| captcha | string |
|
| Field | Type | Label | Description |
| phone | string |
|
|
| username | string |
|
|
| password | string |
|
|
| captcha | string |
|
| Field | Type | Label | Description |
| update_fields | string | repeated |
|
| Field | Type | Label | Description |
| data | UserNotification | repeated |
|
| opts | UpdateUserNotificationOptions |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| affected | int64 |
|
| Field | Type | Label | Description |
| id | int64 |
|
|
| user_id | int64 |
|
|
| notify_type | int32 |
|
|
| notify_arguments | string |
|
|
| status | int32 |
|
|
| created_at | google.protobuf.Timestamp |
|
|
| updated_at | google.protobuf.Timestamp |
|
Request message for VerifyOTP
| Field | Type | Label | Description |
| phone | string | User's phone number |
|
| otp | string | One-time password |
Response message for VerifyOTP
| Field | Type | Label | Description |
| code | int32 | Response code |
|
| msg | string | Response message |
|
| success | bool | Indicates if the OTP verification was successful |
| Method Name | Request Type | Response Type | Description |
| GetMe | GetMeRequest | GetMeResponse | |
| GetMeNotification | GetMeNotificationRequest | GetMeNotificationResponse | |
| ListUserNotifications | ListUserNotificationsRequest | ListUserNotificationsResponse | |
| UpdateUserNotification | UpdateUserNotificationRequest | UpdateUserNotificationResponse | |
| Login | LoginRequest | LoginResponse | |
| Logout | LogoutRequest | LogoutResponse | |
| SignUp | SignUpRequest | SignUpResponse | |
| SignupEmail | SignupEmailRequest | SignUpResponse | |
| SignupPhone | SignupPhoneRequest | SignUpResponse | |
| VerifyOTP | VerifyOTPRequest | VerifyOTPResponse | |
| ConfirmEmail | ConfirmEmailRequest | ConfirmEmailResponse | |
| ResendEmail | ResendEmailRequest | ResendEmailResponse | |
| CheckUserStatus | CheckUserStatusRequest | CheckUserStatusResponse |
| Method Name | Method | Pattern | Body |
| GetMe | POST | /grpc-gateway/v1/user/get_me | * |
| GetMeNotification | POST | /grpc-gateway/v1/user/get_me_notification | * |
| ListUserNotifications | POST | /grpc-gateway/v1/user/list_user_notifications | * |
| UpdateUserNotification | POST | /grpc-gateway/v1/user/update_user_notification | * |
| Login | POST | /grpc-gateway/v1/user/login | * |
| Logout | POST | /grpc-gateway/v1/user/logout | * |
| SignUp | POST | /grpc-gateway/v1/user/sign_up | * |
| SignupEmail | POST | /grpc-gateway/v1/user/signup_email | * |
| SignupPhone | POST | /grpc-gateway/v1/user/signup_phone | * |
| VerifyOTP | POST | /grpc-gateway/v1/user/verify_otp | * |
| ConfirmEmail | POST | /grpc-gateway/v1/user/confirm_email | * |
| ResendEmail | POST | /grpc-gateway/v1/user/resend_email | * |
| CheckUserStatus | POST | /grpc-gateway/v1/user/check_user_status | * |
| Field | Type | Label | Description |
| code | int64 |
|
|
| msg | string |
|
|
| data | string |
|
| Method Name | Request Type | Response Type | Description |
| GetUploadToken | GetUploadTokenRequest | GetUploadTokenResponse |
| Method Name | Method | Pattern | Body |
| GetUploadToken | POST | /grpc-gateway/v1/qiniu/get_upload_token | * |
| Field | Type | Label | Description |
| origin_url | string | 源链 |
|
| remark | string | 短链标记 |
|
| type | uint32 | 短链类型 |
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | ShortLink |
|
| Field | Type | Label | Description |
| short_link_code | string | 短链码 |
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | ShortLink |
|
| Field | Type | Label | Description |
| short_link_code | string | 短链码 |
|
| origin_url | string | 源链 |
|
| origin_url_md5 | string | 源链MD5 |
|
| pv | uint32 | 访问次数 |
|
| type | uint32 | 短链类型 |
|
| remark | string | 短链标记 |
|
| status | uint32 | 短链状态 |
| Name | Number | Description |
| Normal | 0 | |
| Deleted | 1 | |
| Invalid | 2 | |
| Expired | 3 |
| Name | Number | Description |
| INVALID | 0 | |
| INTERNAL | 1 | |
| JOB | 2 | |
| DEPARTMENT | 3 | |
| EXTERNAL | 4 |
| Extension | Type | Base | Number | Description |
| mandarin | string | .google.protobuf.EnumValueOptions | 51234 |
| Method Name | Request Type | Response Type | Description |
| CreateShortLink | CreateShortLinkRequest | CreateShortLinkResponse | |
| GetShortLink | GetShortLinkRequest | GetShortLinkResponse |
| Method Name | Method | Pattern | Body |
| CreateShortLink | POST | /grpc-gateway/v1/shortlink/create | * |
| GetShortLink | POST | /grpc-gateway/v1/shortlink/get | * |
| Field | Type | Label | Description |
| origin_url | string |
|
|
| remark | string |
|
|
| type | uint32 |
|
|
| user_id | int64 |
|
| Field | Type | Label | Description |
| short_link_code | string | repeated |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| affected | uint32 |
|
| Field | Type | Label | Description |
| user_id | int64 |
|
|
| target | string |
|
|
| reason | string |
|
|
| id | int64 | the id of the interaction to be disliked |
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| id | int64 |
|
|
| like_count | uint32 |
|
|
| dislike_count | uint32 |
|
| Field | Type | Label | Description |
| user_id | int64 |
|
|
| short_link_code | string |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | shortlink.ShortLink |
|
| Field | Type | Label | Description |
| user_id | int64 |
|
|
| target | string |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| id | int64 |
|
|
| like_count | uint32 |
|
|
| dislike_count | uint32 |
|
| Field | Type | Label | Description |
| short_link_code | string |
|
|
| origin_url | string |
|
|
| remark | string |
|
| Field | Type | Label | Description |
| user_id | int64 |
|
|
| page | uint32 |
|
|
| page_size | uint32 |
|
|
| options | ListShortLinkOptions |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | shortlink.ShortLink | repeated |
|
| total | uint32 |
|
| Field | Type | Label | Description |
| short_link | shortlink.ShortLink |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | shortlink.ShortLink |
|
| Field | Type | Label | Description |
| id | int64 |
|
|
| user_id | int64 |
|
|
| type | UserInteractionType |
|
|
| target | string |
|
|
| ctime | google.protobuf.Timestamp |
|
|
| data | UserInteraction.DataEntry | repeated |
|
| Field | Type | Label | Description |
| key | string |
|
|
| value | string |
|
| Name | Number | Description |
| UNKNOWN | 0 | |
| LIKE | 1 | |
| DISLIKE | 2 | |
| FAVORITE | 3 | |
| UNFAVORITE | 4 | |
| VIEW | 5 | |
| COMMENT | 6 | |
| SHARE | 7 | |
| CREATE_SHORT_LINK | 8 | |
| CREATE_QR_CODE | 9 | |
| SIGN_UP_TEMP_VISITOR | 10 | |
| SIGN_UP_KYC | 11 |
| Method Name | Request Type | Response Type | Description |
| Like | LikeRequest | LikeResponse | |
| Dislike | DislikeRequest | DislikeResponse | |
| CreateShortLink | CreateShortLinkRequest | .shortlink.CreateShortLinkResponse | |
| ListShortLink | ListShortLinkRequest | ListShortLinkResponse | |
| GetShortLink | GetShortLinkRequest | GetShortLinkResponse | |
| UpdateShortLink | UpdateShortLinkRequest | UpdateShortLinkResponse | |
| DeleteShortLink | DeleteShortLinkRequest | DeleteShortLinkResponse |
| Method Name | Method | Pattern | Body |
| Like | POST | /knowuv.UserInteractionService/Like | * |
| Dislike | POST | /knowuv.UserInteractionService/Dislike | * |
| CreateShortLink | POST | /knowuv.UserInteractionService/CreateShortLink | * |
| ListShortLink | POST | /knowuv.UserInteractionService/ListShortLink | * |
| GetShortLink | POST | /knowuv.UserInteractionService/GetShortLink | * |
| UpdateShortLink | POST | /knowuv.UserInteractionService/UpdateShortLink | * |
| DeleteShortLink | POST | /knowuv.UserInteractionService/DeleteShortLink | * |
| Field | Type | Label | Description |
| options | ListSentenceOptions |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| affected | int32 |
|
| Field | Type | Label | Description |
| data | WordList |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| affected | int32 |
|
| Field | Type | Label | Description |
| origin | string |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| tokens | string | repeated |
|
| l1_part_of_speech | PartOfSpeech | repeated |
|
| l2_part_of_speech | PartOfSpeech | repeated |
|
| Field | Type | Label | Description |
| search_opts | SearchWordOptions | this field is required |
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | WordList | repeated |
|
| Field | Type | Label | Description |
| limit | uint32 |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | string | repeated |
|
| Field | Type | Label | Description |
| word | string |
|
|
| code | string |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| pronunciation | Pronunciation | repeated |
|
| Field | Type | Label | Description |
| excludedWords | string | repeated |
|
| limit | int32 |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | WordList | repeated |
|
| Field | Type | Label | Description |
| data | Sentence |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| _id | string |
|
| Field | Type | Label | Description |
| data | WordList |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| _id | string |
|
| Field | Type | Label | Description |
| limit | int64 |
|
|
| offset | int64 |
|
|
| id | string |
|
|
| id_list | string | repeated |
|
| exclude_fields | string | repeated |
|
| include_fields | string | repeated |
|
| Field | Type | Label | Description |
| options | ListSentenceOptions |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | Sentence | repeated |
|
| Field | Type | Label | Description |
| limit | uint32 |
|
|
| offset | uint32 |
|
|
| excludedWords | string | repeated |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | WordList | repeated |
|
| total | int32 |
|
| Field | Type | Label | Description |
| limit | int64 |
|
|
| offset | int64 |
|
|
| last_word | string |
|
|
| daily_shuffle | bool |
|
|
| only_sort_weighted | bool |
|
|
| order_by_field | string |
|
|
| word_in | string | repeated |
|
| word_not_in | string | repeated |
|
| exclude_fields | string | repeated |
|
| include_fields | string | repeated |
|
| Field | Type | Label | Description |
| limit | uint32 |
|
|
| offset | uint32 |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | WordList | repeated |
|
| Field | Type | Label | Description |
| start | int32 |
|
|
| end | int32 |
|
|
| name | string |
|
|
| color | string |
|
| Field | Type | Label | Description |
| id | uint32 |
|
|
| word | string |
|
|
| original | string |
|
|
| addtime | string |
|
|
| hits | uint32 |
|
|
| username | string |
|
|
| sex | string |
|
|
| country | string |
|
|
| code | string |
|
|
| langname | string |
|
|
| pathmp3 | string |
|
|
| pathogg | string |
|
|
| rate | uint32 |
|
|
| num_votes | uint32 |
|
|
| num_positive_votes | uint32 |
|
| Field | Type | Label | Description |
| opts | ListWordOptions |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | WordList | repeated |
|
| Field | Type | Label | Description |
| keyword | string |
|
| Field | Type | Label | Description |
| ctime | int64 |
|
|
| mtime | int64 |
|
|
| origin | string |
|
|
| relatedWords | string | repeated |
|
| explains | SentenceExplain | repeated |
|
| pronunciation | Pronunciation | repeated |
|
| sortweight | int32 |
|
|
| pv | uint32 |
|
|
| _id | string |
|
|
| tags | string | repeated |
|
| Field | Type | Label | Description |
| segments | SentenceSegment | repeated | segment to [subject / predicate / object / etc..] |
| translation | string |
|
| Field | Type | Label | Description |
| index | uint32 |
|
|
| segment | string |
|
|
| type | string |
|
| Field | Type | Label | Description |
| type | string | v / vi / vt / adj / adv / conj / prep / pron / n |
|
| translation | string |
|
| Field | Type | Label | Description |
| update_fields | string | repeated | to specify which field should be updated, if empty, update all fields |
| Field | Type | Label | Description |
| data | Sentence |
|
|
| options | UpdateSentenceOptions |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| affected | int32 |
|
| Field | Type | Label | Description |
| update_fields | string | repeated | to specify which field should be updated, if empty, update all fields |
| Field | Type | Label | Description |
| data | WordList |
|
|
| options | UpdateWordListOptions |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| affected | int32 |
|
| Field | Type | Label | Description |
| ctime | uint32 |
|
|
| mtime | uint32 |
|
|
| word | string |
|
|
| relatedWords | string | repeated |
|
| mandarin | Translation | repeated |
|
| sentenceList | string | repeated |
|
| pronunciation | Pronunciation | repeated |
|
| images | string | repeated |
|
| sortweight | int32 |
|
|
| pv | uint32 |
|
|
| id | string |
|
| Extension | Type | Base | Number | Description |
| bson | string | .google.protobuf.FieldOptions | 1000 |
| Method Name | Request Type | Response Type | Description |
| List | ListSentenceRequest | ListSentenceResponse | |
| Insert | InsertSentenceRequest | InsertSentenceResponse | |
| Update | UpdateSentenceRequest | UpdateSentenceResponse | |
| Delete | DeleteSentenceRequest | DeleteSentenceResponse | |
| Dismantle | DismantleSentenceRequest | DismantleSentenceResponse |
| Method Name | Method | Pattern | Body |
| List | POST | /grpc-gateway/v1/sentence/list | * |
| Insert | POST | /grpc-gateway/v1/sentence/insert | * |
| Update | POST | /grpc-gateway/v1/sentence/update | * |
| Delete | POST | /grpc-gateway/v1/sentence/delete | * |
| Dismantle | POST | /grpc-gateway/v1/sentence/dismantle | * |
| Method Name | Request Type | Response Type | Description |
| List | ListWordRequest | ListWordResponse | |
| Insert | InsertWordListRequest | InsertWordListResponse | |
| Update | UpdateWordListRequest | UpdateWordListResponse | |
| Delete | DeleteWordListRequest | DeleteWordListResponse | |
| GetByWord | GetByWordRequest | GetByWordResponse | |
| GetTestWordList | GetTestWordListRequest | GetTestWordListResponse | |
| GetStandardPronunciation | GetStandardPronunciationRequest | GetStandardPronunciationResponse | |
| ListUnfamiliarWords | ListUnfamiliarWordsRequest | ListUnfamiliarWordsResponse | |
| GetRandomWords | GetRandomWordsRequest | GetRandomWordsResponse | |
| ReadOnlyList | ReadOnlyListWordRequest | ReadOnlyListWordResponse |
| Method Name | Method | Pattern | Body |
| List | POST | /grpc-gateway/v1/wordlist/list | * |
| Insert | POST | /grpc-gateway/v1/wordlist/insert | * |
| Update | POST | /grpc-gateway/v1/wordlist/update | * |
| Delete | POST | /grpc-gateway/v1/wordlist/delete | * |
| GetByWord | POST | /grpc-gateway/v1/wordlist/getbyword | * |
| GetTestWordList | POST | /grpc-gateway/v1/wordlist/gettestwordlist | * |
| GetStandardPronunciation | POST | /grpc-gateway/v1/wordlist/getstandardpronunciation | * |
| ListUnfamiliarWords | POST | /grpc-gateway/v1/wordlist/ListUnfamiliarWords | * |
| GetRandomWords | POST | /grpc-gateway/v1/wordlist/getrandomwords | * |
| ReadOnlyList | POST | /grpc-gateway/v1/wordlist/readonlylist | * |
| Field | Type | Label | Description |
| phrase_list | string | repeated |
|
| save_history | bool |
|
|
| phrase | string |
|
| Field | Type | Label | Description |
| password | string |
|
| Field | Type | Label | Description |
| offset | uint32 |
|
|
| limit | uint32 |
|
| Field | Type | Label | Description |
| history | string | repeated |
|
| Method Name | Request Type | Response Type | Description |
| GetComplexPassword | GetComplexPasswordRequest | GetComplexPasswordResponse | |
| GetHistory | GetHistoryRequest | GetHistoryResponse |
| Method Name | Method | Pattern | Body |
| GetComplexPassword | POST | /grpc-gateway/v1/passphrase/get-complex-password | * |
| GetHistory | POST | /grpc-gateway/v1/passphrase/get-history | * |
| Field | Type | Label | Description |
| cache_addr | string | the cache addr that should be replaced. example: http://localhost:8012/gateway/TracebackService/ServeCachedResource generally only need to replace the `host` above. |
|
| enable | bool | whether use built-in cache, used in ws / create pretty API |
| Field | Type | Label | Description |
| list_options | ListTracebackDataOptions |
|
|
| caching_method | TracebackEventsCachingMethod | deprecate soon |
|
| cache_options | TracebackResourceCacheOptions |
|
|
| id | string |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
| Field | Type | Label | Description |
| data | TracebackData |
|
|
| sync | bool | whether to wait for the result |
|
| cache_config | CacheConfig |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| task_id | string |
|
|
| id | string |
|
| Field | Type | Label | Description |
| traceback_id_list | string | repeated |
|
| list_options | ListTracebackDataOptions |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| affected | int64 |
|
| Field | Type | Label | Description |
| list_options | ListTracebackDataOptions |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| videos | DownloadTracebackVideoResponse.VideosEntry | repeated | traceback_id -> video_url |
| Field | Type | Label | Description |
| key | string |
|
|
| value | string |
|
| Field | Type | Label | Description |
| traceback_id | string |
|
|
| receiver | string |
|
|
| notify_type | uint32 |
|
|
| force_generate | bool | by default it won't be regenerated if video already exists |
|
| cache_addr | string |
|
|
| video_config | TracebackVideoConfig |
|
|
| list_options | ListTracebackDataOptions |
|
|
| cache_config | CacheConfig |
|
|
| use_proxy | bool |
|
|
| user_id | int64 |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| url | string |
|
|
| task_id | string |
|
| Field | Type | Label | Description |
| from | string |
|
|
| to | string |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | TracebackDailyStatistics | repeated |
|
| Field | Type | Label | Description |
| timestamp | int64 |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| uid | string |
|
| Field | Type | Label | Description |
| id | string |
|
|
| traceback_id | string |
|
|
| timestamp_from | int64 |
|
|
| timestamp_to | int64 |
|
|
| limit | int64 |
|
|
| offset | int64 |
|
|
| exclude_fields | string | repeated |
|
| ctime_from | int64 |
|
|
| ctime_to | int64 |
|
|
| cache_addr | string | whether or not replace resources in original events to the cached resources. default is false Sometimes the original resources has vanished in internet, and you still want to replay traceback data, then you should use this option. Attention: some dynamic url that are calculated by other urls can not present properly in browser, but still can be seen in http_proxy based video generation. |
|
| id_list | string | repeated |
|
| client_uid | string |
|
|
| urlPrefix | string |
|
|
| ip | string |
|
| Field | Type | Label | Description |
| options | ListTracebackDataOptions |
|
| Field | Type | Label | Description |
| total | uint32 |
|
|
| traceback_list | TracebackData | repeated |
|
| code | int32 |
|
|
| msg | string |
|
| Field | Type | Label | Description |
| traceback_id | string |
|
|
| sub_id | string |
|
|
| send_timestamp_from | int64 |
|
|
| send_timestamp_to | int64 |
|
|
| limit | int64 |
|
|
| offset | int64 |
|
|
| proj_name | string |
|
|
| order_id | string |
|
|
| id | int64 |
|
| Field | Type | Label | Description |
| date | string |
|
|
| uv | uint32 |
|
|
| pv | uint32 |
|
| Field | Type | Label | Description |
| traceback_id | string |
|
|
| events | string |
|
|
| ctime | int64 |
|
|
| attach | string | will be replaced by `remark` field in future |
|
| id | string |
|
|
| timestamp_from | int64 | for analysis |
|
| timestamp_to | int64 |
|
|
| has_type_page_load | bool |
|
|
| remark | TracebackData.RemarkEntry | repeated |
|
| Field | Type | Label | Description |
| key | string |
|
|
| value | string |
|
| Field | Type | Label | Description |
| traceback_id | string |
|
|
| sub_id | string |
|
|
| send_timestamp | int64 |
|
|
| event_num | int64 |
|
|
| status | int32 |
|
|
| proj_name | string |
|
|
| order_id | string |
|
|
| events | string |
|
|
| id | int64 |
|
| Field | Type | Label | Description |
| cache_addr | string |
|
|
| caching_method | TracebackEventsCachingMethod |
|
|
| save_resource_list_to_db | bool | whether or not save the analysis result to db since in API you can choose directly get the result without saving it. |
|
| error_policy | TracebackErrorPolicy |
|
|
| save_video_to | string | where to write the generated video if you chose caching_method=`AnalysisEvents` default is "" meaning not to save the video |
| Field | Type | Label | Description |
| speed | int32 |
|
|
| skipInactive | bool |
|
|
| startDelayTime | int32 |
|
| Field | Type | Label | Description |
| uid | string | repeated |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| uid_to_timestamp | UidToTimestampResponse.UidToTimestampEntry | repeated |
|
| Field | Type | Label | Description |
| key | string |
|
|
| value | int64 |
|
| Field | Type | Label | Description |
| data | TracebackData |
|
| Field | Type | Label | Description |
| code | int32 |
|
|
| msg | string |
|
|
| data | TracebackData |
|
| Name | Number | Description |
| Fail | 0 | |
| Ignore | 1 |
| Name | Number | Description |
| NoCache | 0 | |
| AnalysisEvents | 1 | |
| HttpProxy | 2 |
| Method Name | Request Type | Response Type | Description |
| UidToTimestamp | UidToTimestampRequest | UidToTimestampResponse | |
| GetUid | GetUidRequest | GetUidResponse | get uid by timestamp |
| CreateTraceback | CreateTracebackRequest | CreateTracebackResponse | create traceback data |
| ListTracebackData | ListTracebackDataRequest | ListTracebackDataResponse | list traceback data |
| GenerateTracebackVideo | GenerateTracebackVideoRequest | GenerateTracebackVideoResponse | generate traceback video |
| CacheTracebackDependencies | CacheTracebackDependenciesRequest | CacheTracebackDependenciesResponse | |
| DeleteTracebackData | DeleteTracebackDataRequest | DeleteTracebackDataResponse | delete traceback data |
| UpdateTracebackData | UpdateTracebackDataRequest | UpdateTracebackDataResponse | |
| DownloadTracebackVideo | DownloadTracebackVideoRequest | DownloadTracebackVideoResponse | |
| GetTracebackDailyStatistics | GetTracebackDailyStatisticsRequest | GetTracebackDailyStatisticsResponse | get daily statistics |
| Method Name | Method | Pattern | Body |
| UidToTimestamp | POST | /grpc-gateway/v1/traceback/uid_to_timestamp | * |
| GetUid | POST | /grpc-gateway/v1/traceback/get_uid | * |
| CreateTraceback | POST | /grpc-gateway/v1/traceback/create_traceback | * |
| ListTracebackData | POST | /grpc-gateway/v1/traceback/list_traceback_data | * |
| GenerateTracebackVideo | POST | /grpc-gateway/v1/traceback/generate_traceback_video | * |
| CacheTracebackDependencies | POST | /grpc-gateway/v1/traceback/cache_traceback_dependencies | * |
| DeleteTracebackData | POST | /grpc-gateway/v1/traceback/delete_traceback_data | * |
| UpdateTracebackData | POST | /grpc-gateway/v1/traceback/update_traceback_data | * |
| DownloadTracebackVideo | POST | /grpc-gateway/v1/traceback/download_traceback_video | * |
| GetTracebackDailyStatistics | POST | /grpc-gateway/v1/traceback/get_traceback_daily_statistics | * |
| Method Name | Request Type | Response Type | Description |
| UidToTimestamp | UidToTimestampRequest | UidToTimestampResponse | |
| GetUid | GetUidRequest | GetUidResponse | get uid by timestamp |
| CreateTraceback | CreateTracebackRequest | CreateTracebackResponse | create traceback data |
| ListTracebackData | ListTracebackDataRequest | ListTracebackDataResponse | list traceback data |
| GenerateTracebackVideo | GenerateTracebackVideoRequest | GenerateTracebackVideoResponse | generate traceback video |
| CacheTracebackDependencies | CacheTracebackDependenciesRequest | CacheTracebackDependenciesResponse | |
| DeleteTracebackData | DeleteTracebackDataRequest | DeleteTracebackDataResponse | delete traceback data |
| UpdateTracebackData | UpdateTracebackDataRequest | UpdateTracebackDataResponse | |
| DownloadTracebackVideo | DownloadTracebackVideoRequest | DownloadTracebackVideoResponse | |
| GetTracebackDailyStatistics | GetTracebackDailyStatisticsRequest | GetTracebackDailyStatisticsResponse | get daily statistics |
| Method Name | Method | Pattern | Body |
| UidToTimestamp | POST | /grpc-gateway/v1/traceback/uid_to_timestamp | * |
| GetUid | POST | /grpc-gateway/v1/traceback/get_uid | * |
| CreateTraceback | POST | /grpc-gateway/v1/traceback/create_traceback | * |
| ListTracebackData | POST | /grpc-gateway/v1/traceback/list_traceback_data | * |
| GenerateTracebackVideo | POST | /grpc-gateway/v1/traceback/generate_traceback_video | * |
| CacheTracebackDependencies | POST | /grpc-gateway/v1/traceback/cache_traceback_dependencies | * |
| DeleteTracebackData | POST | /grpc-gateway/v1/traceback/delete_traceback_data | * |
| UpdateTracebackData | POST | /grpc-gateway/v1/traceback/update_traceback_data | * |
| DownloadTracebackVideo | POST | /grpc-gateway/v1/traceback/download_traceback_video | * |
| GetTracebackDailyStatistics | POST | /grpc-gateway/v1/traceback/get_traceback_daily_statistics | * |
| .proto Type | Notes | C++ | Java | Python | Go | C# | PHP | Ruby |
| double | double | double | float | float64 | double | float | Float | |
| float | float | float | float | float32 | float | float | Float | |
| int32 | Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead. | int32 | int | int | int32 | int | integer | Bignum or Fixnum (as required) |
| int64 | Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead. | int64 | long | int/long | int64 | long | integer/string | Bignum |
| uint32 | Uses variable-length encoding. | uint32 | int | int/long | uint32 | uint | integer | Bignum or Fixnum (as required) |
| uint64 | Uses variable-length encoding. | uint64 | long | int/long | uint64 | ulong | integer/string | Bignum or Fixnum (as required) |
| sint32 | Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s. | int32 | int | int | int32 | int | integer | Bignum or Fixnum (as required) |
| sint64 | Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s. | int64 | long | int/long | int64 | long | integer/string | Bignum |
| fixed32 | Always four bytes. More efficient than uint32 if values are often greater than 2^28. | uint32 | int | int | uint32 | uint | integer | Bignum or Fixnum (as required) |
| fixed64 | Always eight bytes. More efficient than uint64 if values are often greater than 2^56. | uint64 | long | int/long | uint64 | ulong | integer/string | Bignum |
| sfixed32 | Always four bytes. | int32 | int | int | int32 | int | integer | Bignum or Fixnum (as required) |
| sfixed64 | Always eight bytes. | int64 | long | int/long | int64 | long | integer/string | Bignum |
| bool | bool | boolean | boolean | bool | bool | boolean | TrueClass/FalseClass | |
| string | A string must always contain UTF-8 encoded or 7-bit ASCII text. | string | String | str/unicode | string | string | string | String (UTF-8) |
| bytes | May contain any arbitrary sequence of bytes. | string | ByteString | str | []byte | ByteString | string | String (ASCII-8BIT) |