Skip to content
This repository was archived by the owner on Jan 15, 2026. It is now read-only.

Commit f7d6a0a

Browse files
envoyproxy/protoc-gen-validate (#20)
1 parent aa40915 commit f7d6a0a

23 files changed

Lines changed: 2358 additions & 188 deletions

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ all:
55

66
.PHONY: gen-proto
77
gen-proto:
8+
buf lint idl
9+
buf format idl -w
10+
buf mod update idl
811
buf generate idl
912

1013
.PHONY: gen-models

buf.gen.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@ plugins:
88
out: internal/idl
99
opt:
1010
- require_unimplemented_servers=false
11-
- paths=source_relative
11+
- paths=source_relative
12+
- remote: buf.build/jirkad/plugins/protoc-gen-validate:v0.6.7
13+
out: internal/idl
14+
opt:
15+
- paths=source_relative
16+
- lang=go

docs/CONTRIBUTING.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,20 @@ dispatch=# select driver_id from driver_location ;
124124
WBG-Chimu-Bistro
125125
WBG-Birria-Landia
126126
(16 rows)
127-
```
127+
```
128+
129+
## JetBrains Protobuf Import Paths
130+
In `Languages & Frameworks > Protocol Buffers`, import the `./idl` directory.
131+
132+
Install envoyproxy/protoc-gen-validate into your `GOPATH`.
133+
```
134+
$ go env -json GOPATH GOROOT
135+
{
136+
"GOPATH": "/Users/kevinchen/go",
137+
"GOROOT": "/opt/homebrew/Cellar/go/1.18.2/libexec"
138+
}
139+
140+
$ go install github.com/envoyproxy/protoc-gen-validate@latest
141+
```
142+
143+
Add an import path for `${GOPATH}/pkg/mod/github.com/envoyproxy/protoc-gen-validate@v0.6.7`.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.18
44

55
require (
66
github.com/XSAM/otelsql v0.14.1
7+
github.com/envoyproxy/protoc-gen-validate v0.1.0
78
github.com/friendsofgo/errors v0.9.2
89
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
910
github.com/google/go-cmp v0.5.8

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.m
113113
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
114114
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
115115
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
116+
github.com/envoyproxy/protoc-gen-validate v0.1.0 h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A=
116117
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
117118
github.com/ericlagergren/decimal v0.0.0-20181231230500-73749d4874d5 h1:HQGCJNlqt1dUs/BhtEKmqWd6LWS+DWYVxi9+Jo4r0jE=
118119
github.com/ericlagergren/decimal v0.0.0-20181231230500-73749d4874d5/go.mod h1:1yj25TwtUlJ+pfOu9apAVaM1RWfZGg+aFpd4hPQZekQ=

idl/buf.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Generated by buf. DO NOT EDIT.
2+
version: v1
3+
deps:
4+
- remote: buf.build
5+
owner: envoyproxy
6+
repository: protoc-gen-validate
7+
commit: dc09a417d27241f7b069feae2cd74a0e

idl/buf.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
version: v1
2+
deps:
3+
- buf.build/envoyproxy/protoc-gen-validate:0e25aabb25c0709aff19aea176a1da13328b12fb
24
breaking:
35
use:
46
- FILE

idl/coop/drivers/dispatch/v1beta1/api.proto

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "coop/drivers/dispatch/v1beta1/driver.proto";
66
import "coop/drivers/dispatch/v1beta1/latlng.proto";
77
import "coop/drivers/dispatch/v1beta1/trip.proto";
88
import "google/protobuf/duration.proto";
9+
import "validate/validate.proto";
910

1011
option go_package = "github.com/kevinmichaelchen/api-dispatch/internal/idl/coop/drivers/dispatch/v1beta1";
1112

@@ -24,21 +25,30 @@ service DispatchService {
2425
}
2526

2627
message UpdateDriverLocationsRequest {
27-
repeated DriverLocation locations = 1;
28+
repeated DriverLocation locations = 1 [(validate.rules).repeated = {
29+
min_items: 1,
30+
max_items: 1000
31+
}];
2832
}
2933

3034
message UpdateDriverLocationsResponse {}
3135

3236
message CreateTripsRequest {
33-
repeated Trip trips = 1;
37+
repeated Trip trips = 1 [(validate.rules).repeated = {
38+
min_items: 1,
39+
max_items: 1000
40+
}];
3441
}
3542

3643
message CreateTripsResponse {}
3744

3845
message GetNearestDriversRequest {
3946
// trip pickup location
4047
LatLng pickup_location = 1;
41-
int32 limit = 2;
48+
int32 limit = 2 [(validate.rules).int32 = {
49+
gt: 0,
50+
lte: 1000
51+
}];
4252
}
4353

4454
message GetNearestDriversResponse {
@@ -48,10 +58,15 @@ message GetNearestDriversResponse {
4858

4959
message GetNearestTripsRequest {
5060
oneof driver {
61+
option (validate.required) = true;
62+
5163
string driver_id = 1;
5264
LatLng driver_location = 2;
5365
}
54-
int32 limit = 3;
66+
int32 limit = 3 [(validate.rules).int32 = {
67+
gt: 0,
68+
lte: 1000
69+
}];
5570
}
5671

5772
message GetNearestTripsResponse {

idl/coop/drivers/dispatch/v1beta1/driver.proto

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ package coop.drivers.dispatch.v1beta1;
44

55
import "coop/drivers/dispatch/v1beta1/latlng.proto";
66
import "google/protobuf/timestamp.proto";
7+
import "validate/validate.proto";
78

89
option go_package = "github.com/kevinmichaelchen/api-dispatch/internal/idl/coop/drivers/dispatch/v1beta1";
910

1011
message DriverLocation {
11-
string driver_id = 1;
12-
google.protobuf.Timestamp most_recent_heartbeat = 2;
13-
LatLng current_location = 3;
12+
string driver_id = 1 [(validate.rules).string.min_len = 1];
13+
google.protobuf.Timestamp most_recent_heartbeat = 2 [(validate.rules).timestamp.required = true];
14+
LatLng current_location = 3 [(validate.rules).message.required = true];
1415
}

idl/coop/drivers/dispatch/v1beta1/latlng.proto

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ syntax = "proto3";
22

33
package coop.drivers.dispatch.v1beta1;
44

5+
import "validate/validate.proto";
6+
57
option go_package = "github.com/kevinmichaelchen/api-dispatch/internal/idl/coop/drivers/dispatch/v1beta1";
68

79
// An object that represents a latitude/longitude pair. This is expressed as a
@@ -11,8 +13,14 @@ option go_package = "github.com/kevinmichaelchen/api-dispatch/internal/idl/coop/
1113
// standard</a>. Values must be within normalized ranges.
1214
message LatLng {
1315
// The latitude in degrees. It must be in the range [-90.0, +90.0].
14-
double latitude = 1;
16+
double latitude = 1 [(validate.rules).double = {
17+
gte: -90,
18+
lte: 90
19+
}];
1520

1621
// The longitude in degrees. It must be in the range [-180.0, +180.0].
17-
double longitude = 2;
22+
double longitude = 2 [(validate.rules).double = {
23+
gte: -180,
24+
lte: 180
25+
}];
1826
}

0 commit comments

Comments
 (0)