How Protovalidate annotations translate to OpenAPI
mainThe protoc-gen-connect-openapi plugin supports many Protovalidate annotations, translating them into standard OpenAPI schema constraints where possible.
Standard Constraints
Simple numeric or length constraints are mapped to direct OpenAPI properties. For example, a Protobuf gte (greater than or equal to) constraint on an int32 field is translated to the OpenAPI minimum property.
Custom CEL Expressions
For complex validation logic using Common Expression Language (CEL), the plugin appends the CEL expression and its associated message to the OpenAPI description field of the property. This ensures that the custom validation logic is documented in the resulting OpenAPI specification even if it cannot be represented as a standard JSON Schema constraint.
syntax = "proto3";
import "buf/validate/validate.proto";
message User {
int32 age = 1 [(buf.validate.field).int32.gte = 18];
}// Results in:
components:
schemas:
User:
properties:
age:
minimum: 18
type: integer