validate.proto 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. syntax = "proto2";
  2. package validate;
  3. option go_package = "github.com/envoyproxy/protoc-gen-validate/validate";
  4. option java_package = "io.envoyproxy.pgv.validate";
  5. import "google/protobuf/descriptor.proto";
  6. import "google/protobuf/duration.proto";
  7. import "google/protobuf/timestamp.proto";
  8. // Validation rules applied at the message level
  9. extend google.protobuf.MessageOptions {
  10. // Disabled nullifies any validation rules for this message, including any
  11. // message fields associated with it that do support validation.
  12. optional bool disabled = 1071;
  13. // Ignore skips generation of validation methods for this message.
  14. optional bool ignored = 1072;
  15. }
  16. // Validation rules applied at the oneof level
  17. extend google.protobuf.OneofOptions {
  18. // Required ensures that exactly one the field options in a oneof is set;
  19. // validation fails if no fields in the oneof are set.
  20. optional bool required = 1071;
  21. }
  22. // Validation rules applied at the field level
  23. extend google.protobuf.FieldOptions {
  24. // Rules specify the validations to be performed on this field. By default,
  25. // no validation is performed against a field.
  26. optional FieldRules rules = 1071;
  27. }
  28. // FieldRules encapsulates the rules for each type of field. Depending on the
  29. // field, the correct set should be used to ensure proper validations.
  30. message FieldRules {
  31. optional MessageRules message = 17;
  32. oneof type {
  33. // Scalar Field Types
  34. FloatRules float = 1;
  35. DoubleRules double = 2;
  36. Int32Rules int32 = 3;
  37. Int64Rules int64 = 4;
  38. UInt32Rules uint32 = 5;
  39. UInt64Rules uint64 = 6;
  40. SInt32Rules sint32 = 7;
  41. SInt64Rules sint64 = 8;
  42. Fixed32Rules fixed32 = 9;
  43. Fixed64Rules fixed64 = 10;
  44. SFixed32Rules sfixed32 = 11;
  45. SFixed64Rules sfixed64 = 12;
  46. BoolRules bool = 13;
  47. StringRules string = 14;
  48. BytesRules bytes = 15;
  49. // Complex Field Types
  50. EnumRules enum = 16;
  51. RepeatedRules repeated = 18;
  52. MapRules map = 19;
  53. // Well-Known Field Types
  54. AnyRules any = 20;
  55. DurationRules duration = 21;
  56. TimestampRules timestamp = 22;
  57. }
  58. }
  59. // FloatRules describes the constraints applied to `float` values
  60. message FloatRules {
  61. // Const specifies that this field must be exactly the specified value
  62. optional float const = 1;
  63. // Lt specifies that this field must be less than the specified value,
  64. // exclusive
  65. optional float lt = 2;
  66. // Lte specifies that this field must be less than or equal to the
  67. // specified value, inclusive
  68. optional float lte = 3;
  69. // Gt specifies that this field must be greater than the specified value,
  70. // exclusive. If the value of Gt is larger than a specified Lt or Lte, the
  71. // range is reversed.
  72. optional float gt = 4;
  73. // Gte specifies that this field must be greater than or equal to the
  74. // specified value, inclusive. If the value of Gte is larger than a
  75. // specified Lt or Lte, the range is reversed.
  76. optional float gte = 5;
  77. // In specifies that this field must be equal to one of the specified
  78. // values
  79. repeated float in = 6;
  80. // NotIn specifies that this field cannot be equal to one of the specified
  81. // values
  82. repeated float not_in = 7;
  83. // IgnoreEmpty specifies that the validation rules of this field should be
  84. // evaluated only if the field is not empty
  85. optional bool ignore_empty = 8;
  86. }
  87. // DoubleRules describes the constraints applied to `double` values
  88. message DoubleRules {
  89. // Const specifies that this field must be exactly the specified value
  90. optional double const = 1;
  91. // Lt specifies that this field must be less than the specified value,
  92. // exclusive
  93. optional double lt = 2;
  94. // Lte specifies that this field must be less than or equal to the
  95. // specified value, inclusive
  96. optional double lte = 3;
  97. // Gt specifies that this field must be greater than the specified value,
  98. // exclusive. If the value of Gt is larger than a specified Lt or Lte, the
  99. // range is reversed.
  100. optional double gt = 4;
  101. // Gte specifies that this field must be greater than or equal to the
  102. // specified value, inclusive. If the value of Gte is larger than a
  103. // specified Lt or Lte, the range is reversed.
  104. optional double gte = 5;
  105. // In specifies that this field must be equal to one of the specified
  106. // values
  107. repeated double in = 6;
  108. // NotIn specifies that this field cannot be equal to one of the specified
  109. // values
  110. repeated double not_in = 7;
  111. // IgnoreEmpty specifies that the validation rules of this field should be
  112. // evaluated only if the field is not empty
  113. optional bool ignore_empty = 8;
  114. }
  115. // Int32Rules describes the constraints applied to `int32` values
  116. message Int32Rules {
  117. // Const specifies that this field must be exactly the specified value
  118. optional int32 const = 1;
  119. // Lt specifies that this field must be less than the specified value,
  120. // exclusive
  121. optional int32 lt = 2;
  122. // Lte specifies that this field must be less than or equal to the
  123. // specified value, inclusive
  124. optional int32 lte = 3;
  125. // Gt specifies that this field must be greater than the specified value,
  126. // exclusive. If the value of Gt is larger than a specified Lt or Lte, the
  127. // range is reversed.
  128. optional int32 gt = 4;
  129. // Gte specifies that this field must be greater than or equal to the
  130. // specified value, inclusive. If the value of Gte is larger than a
  131. // specified Lt or Lte, the range is reversed.
  132. optional int32 gte = 5;
  133. // In specifies that this field must be equal to one of the specified
  134. // values
  135. repeated int32 in = 6;
  136. // NotIn specifies that this field cannot be equal to one of the specified
  137. // values
  138. repeated int32 not_in = 7;
  139. // IgnoreEmpty specifies that the validation rules of this field should be
  140. // evaluated only if the field is not empty
  141. optional bool ignore_empty = 8;
  142. }
  143. // Int64Rules describes the constraints applied to `int64` values
  144. message Int64Rules {
  145. // Const specifies that this field must be exactly the specified value
  146. optional int64 const = 1;
  147. // Lt specifies that this field must be less than the specified value,
  148. // exclusive
  149. optional int64 lt = 2;
  150. // Lte specifies that this field must be less than or equal to the
  151. // specified value, inclusive
  152. optional int64 lte = 3;
  153. // Gt specifies that this field must be greater than the specified value,
  154. // exclusive. If the value of Gt is larger than a specified Lt or Lte, the
  155. // range is reversed.
  156. optional int64 gt = 4;
  157. // Gte specifies that this field must be greater than or equal to the
  158. // specified value, inclusive. If the value of Gte is larger than a
  159. // specified Lt or Lte, the range is reversed.
  160. optional int64 gte = 5;
  161. // In specifies that this field must be equal to one of the specified
  162. // values
  163. repeated int64 in = 6;
  164. // NotIn specifies that this field cannot be equal to one of the specified
  165. // values
  166. repeated int64 not_in = 7;
  167. // IgnoreEmpty specifies that the validation rules of this field should be
  168. // evaluated only if the field is not empty
  169. optional bool ignore_empty = 8;
  170. }
  171. // UInt32Rules describes the constraints applied to `uint32` values
  172. message UInt32Rules {
  173. // Const specifies that this field must be exactly the specified value
  174. optional uint32 const = 1;
  175. // Lt specifies that this field must be less than the specified value,
  176. // exclusive
  177. optional uint32 lt = 2;
  178. // Lte specifies that this field must be less than or equal to the
  179. // specified value, inclusive
  180. optional uint32 lte = 3;
  181. // Gt specifies that this field must be greater than the specified value,
  182. // exclusive. If the value of Gt is larger than a specified Lt or Lte, the
  183. // range is reversed.
  184. optional uint32 gt = 4;
  185. // Gte specifies that this field must be greater than or equal to the
  186. // specified value, inclusive. If the value of Gte is larger than a
  187. // specified Lt or Lte, the range is reversed.
  188. optional uint32 gte = 5;
  189. // In specifies that this field must be equal to one of the specified
  190. // values
  191. repeated uint32 in = 6;
  192. // NotIn specifies that this field cannot be equal to one of the specified
  193. // values
  194. repeated uint32 not_in = 7;
  195. // IgnoreEmpty specifies that the validation rules of this field should be
  196. // evaluated only if the field is not empty
  197. optional bool ignore_empty = 8;
  198. }
  199. // UInt64Rules describes the constraints applied to `uint64` values
  200. message UInt64Rules {
  201. // Const specifies that this field must be exactly the specified value
  202. optional uint64 const = 1;
  203. // Lt specifies that this field must be less than the specified value,
  204. // exclusive
  205. optional uint64 lt = 2;
  206. // Lte specifies that this field must be less than or equal to the
  207. // specified value, inclusive
  208. optional uint64 lte = 3;
  209. // Gt specifies that this field must be greater than the specified value,
  210. // exclusive. If the value of Gt is larger than a specified Lt or Lte, the
  211. // range is reversed.
  212. optional uint64 gt = 4;
  213. // Gte specifies that this field must be greater than or equal to the
  214. // specified value, inclusive. If the value of Gte is larger than a
  215. // specified Lt or Lte, the range is reversed.
  216. optional uint64 gte = 5;
  217. // In specifies that this field must be equal to one of the specified
  218. // values
  219. repeated uint64 in = 6;
  220. // NotIn specifies that this field cannot be equal to one of the specified
  221. // values
  222. repeated uint64 not_in = 7;
  223. // IgnoreEmpty specifies that the validation rules of this field should be
  224. // evaluated only if the field is not empty
  225. optional bool ignore_empty = 8;
  226. }
  227. // SInt32Rules describes the constraints applied to `sint32` values
  228. message SInt32Rules {
  229. // Const specifies that this field must be exactly the specified value
  230. optional sint32 const = 1;
  231. // Lt specifies that this field must be less than the specified value,
  232. // exclusive
  233. optional sint32 lt = 2;
  234. // Lte specifies that this field must be less than or equal to the
  235. // specified value, inclusive
  236. optional sint32 lte = 3;
  237. // Gt specifies that this field must be greater than the specified value,
  238. // exclusive. If the value of Gt is larger than a specified Lt or Lte, the
  239. // range is reversed.
  240. optional sint32 gt = 4;
  241. // Gte specifies that this field must be greater than or equal to the
  242. // specified value, inclusive. If the value of Gte is larger than a
  243. // specified Lt or Lte, the range is reversed.
  244. optional sint32 gte = 5;
  245. // In specifies that this field must be equal to one of the specified
  246. // values
  247. repeated sint32 in = 6;
  248. // NotIn specifies that this field cannot be equal to one of the specified
  249. // values
  250. repeated sint32 not_in = 7;
  251. // IgnoreEmpty specifies that the validation rules of this field should be
  252. // evaluated only if the field is not empty
  253. optional bool ignore_empty = 8;
  254. }
  255. // SInt64Rules describes the constraints applied to `sint64` values
  256. message SInt64Rules {
  257. // Const specifies that this field must be exactly the specified value
  258. optional sint64 const = 1;
  259. // Lt specifies that this field must be less than the specified value,
  260. // exclusive
  261. optional sint64 lt = 2;
  262. // Lte specifies that this field must be less than or equal to the
  263. // specified value, inclusive
  264. optional sint64 lte = 3;
  265. // Gt specifies that this field must be greater than the specified value,
  266. // exclusive. If the value of Gt is larger than a specified Lt or Lte, the
  267. // range is reversed.
  268. optional sint64 gt = 4;
  269. // Gte specifies that this field must be greater than or equal to the
  270. // specified value, inclusive. If the value of Gte is larger than a
  271. // specified Lt or Lte, the range is reversed.
  272. optional sint64 gte = 5;
  273. // In specifies that this field must be equal to one of the specified
  274. // values
  275. repeated sint64 in = 6;
  276. // NotIn specifies that this field cannot be equal to one of the specified
  277. // values
  278. repeated sint64 not_in = 7;
  279. // IgnoreEmpty specifies that the validation rules of this field should be
  280. // evaluated only if the field is not empty
  281. optional bool ignore_empty = 8;
  282. }
  283. // Fixed32Rules describes the constraints applied to `fixed32` values
  284. message Fixed32Rules {
  285. // Const specifies that this field must be exactly the specified value
  286. optional fixed32 const = 1;
  287. // Lt specifies that this field must be less than the specified value,
  288. // exclusive
  289. optional fixed32 lt = 2;
  290. // Lte specifies that this field must be less than or equal to the
  291. // specified value, inclusive
  292. optional fixed32 lte = 3;
  293. // Gt specifies that this field must be greater than the specified value,
  294. // exclusive. If the value of Gt is larger than a specified Lt or Lte, the
  295. // range is reversed.
  296. optional fixed32 gt = 4;
  297. // Gte specifies that this field must be greater than or equal to the
  298. // specified value, inclusive. If the value of Gte is larger than a
  299. // specified Lt or Lte, the range is reversed.
  300. optional fixed32 gte = 5;
  301. // In specifies that this field must be equal to one of the specified
  302. // values
  303. repeated fixed32 in = 6;
  304. // NotIn specifies that this field cannot be equal to one of the specified
  305. // values
  306. repeated fixed32 not_in = 7;
  307. // IgnoreEmpty specifies that the validation rules of this field should be
  308. // evaluated only if the field is not empty
  309. optional bool ignore_empty = 8;
  310. }
  311. // Fixed64Rules describes the constraints applied to `fixed64` values
  312. message Fixed64Rules {
  313. // Const specifies that this field must be exactly the specified value
  314. optional fixed64 const = 1;
  315. // Lt specifies that this field must be less than the specified value,
  316. // exclusive
  317. optional fixed64 lt = 2;
  318. // Lte specifies that this field must be less than or equal to the
  319. // specified value, inclusive
  320. optional fixed64 lte = 3;
  321. // Gt specifies that this field must be greater than the specified value,
  322. // exclusive. If the value of Gt is larger than a specified Lt or Lte, the
  323. // range is reversed.
  324. optional fixed64 gt = 4;
  325. // Gte specifies that this field must be greater than or equal to the
  326. // specified value, inclusive. If the value of Gte is larger than a
  327. // specified Lt or Lte, the range is reversed.
  328. optional fixed64 gte = 5;
  329. // In specifies that this field must be equal to one of the specified
  330. // values
  331. repeated fixed64 in = 6;
  332. // NotIn specifies that this field cannot be equal to one of the specified
  333. // values
  334. repeated fixed64 not_in = 7;
  335. // IgnoreEmpty specifies that the validation rules of this field should be
  336. // evaluated only if the field is not empty
  337. optional bool ignore_empty = 8;
  338. }
  339. // SFixed32Rules describes the constraints applied to `sfixed32` values
  340. message SFixed32Rules {
  341. // Const specifies that this field must be exactly the specified value
  342. optional sfixed32 const = 1;
  343. // Lt specifies that this field must be less than the specified value,
  344. // exclusive
  345. optional sfixed32 lt = 2;
  346. // Lte specifies that this field must be less than or equal to the
  347. // specified value, inclusive
  348. optional sfixed32 lte = 3;
  349. // Gt specifies that this field must be greater than the specified value,
  350. // exclusive. If the value of Gt is larger than a specified Lt or Lte, the
  351. // range is reversed.
  352. optional sfixed32 gt = 4;
  353. // Gte specifies that this field must be greater than or equal to the
  354. // specified value, inclusive. If the value of Gte is larger than a
  355. // specified Lt or Lte, the range is reversed.
  356. optional sfixed32 gte = 5;
  357. // In specifies that this field must be equal to one of the specified
  358. // values
  359. repeated sfixed32 in = 6;
  360. // NotIn specifies that this field cannot be equal to one of the specified
  361. // values
  362. repeated sfixed32 not_in = 7;
  363. // IgnoreEmpty specifies that the validation rules of this field should be
  364. // evaluated only if the field is not empty
  365. optional bool ignore_empty = 8;
  366. }
  367. // SFixed64Rules describes the constraints applied to `sfixed64` values
  368. message SFixed64Rules {
  369. // Const specifies that this field must be exactly the specified value
  370. optional sfixed64 const = 1;
  371. // Lt specifies that this field must be less than the specified value,
  372. // exclusive
  373. optional sfixed64 lt = 2;
  374. // Lte specifies that this field must be less than or equal to the
  375. // specified value, inclusive
  376. optional sfixed64 lte = 3;
  377. // Gt specifies that this field must be greater than the specified value,
  378. // exclusive. If the value of Gt is larger than a specified Lt or Lte, the
  379. // range is reversed.
  380. optional sfixed64 gt = 4;
  381. // Gte specifies that this field must be greater than or equal to the
  382. // specified value, inclusive. If the value of Gte is larger than a
  383. // specified Lt or Lte, the range is reversed.
  384. optional sfixed64 gte = 5;
  385. // In specifies that this field must be equal to one of the specified
  386. // values
  387. repeated sfixed64 in = 6;
  388. // NotIn specifies that this field cannot be equal to one of the specified
  389. // values
  390. repeated sfixed64 not_in = 7;
  391. // IgnoreEmpty specifies that the validation rules of this field should be
  392. // evaluated only if the field is not empty
  393. optional bool ignore_empty = 8;
  394. }
  395. // BoolRules describes the constraints applied to `bool` values
  396. message BoolRules {
  397. // Const specifies that this field must be exactly the specified value
  398. optional bool const = 1;
  399. }
  400. // StringRules describe the constraints applied to `string` values
  401. message StringRules {
  402. // Const specifies that this field must be exactly the specified value
  403. optional string const = 1;
  404. // Len specifies that this field must be the specified number of
  405. // characters (Unicode code points). Note that the number of
  406. // characters may differ from the number of bytes in the string.
  407. optional uint64 len = 19;
  408. // MinLen specifies that this field must be the specified number of
  409. // characters (Unicode code points) at a minimum. Note that the number of
  410. // characters may differ from the number of bytes in the string.
  411. optional uint64 min_len = 2;
  412. // MaxLen specifies that this field must be the specified number of
  413. // characters (Unicode code points) at a maximum. Note that the number of
  414. // characters may differ from the number of bytes in the string.
  415. optional uint64 max_len = 3;
  416. // LenBytes specifies that this field must be the specified number of bytes
  417. // at a minimum
  418. optional uint64 len_bytes = 20;
  419. // MinBytes specifies that this field must be the specified number of bytes
  420. // at a minimum
  421. optional uint64 min_bytes = 4;
  422. // MaxBytes specifies that this field must be the specified number of bytes
  423. // at a maximum
  424. optional uint64 max_bytes = 5;
  425. // Pattern specifes that this field must match against the specified
  426. // regular expression (RE2 syntax). The included expression should elide
  427. // any delimiters.
  428. optional string pattern = 6;
  429. // Prefix specifies that this field must have the specified substring at
  430. // the beginning of the string.
  431. optional string prefix = 7;
  432. // Suffix specifies that this field must have the specified substring at
  433. // the end of the string.
  434. optional string suffix = 8;
  435. // Contains specifies that this field must have the specified substring
  436. // anywhere in the string.
  437. optional string contains = 9;
  438. // NotContains specifies that this field cannot have the specified substring
  439. // anywhere in the string.
  440. optional string not_contains = 23;
  441. // In specifies that this field must be equal to one of the specified
  442. // values
  443. repeated string in = 10;
  444. // NotIn specifies that this field cannot be equal to one of the specified
  445. // values
  446. repeated string not_in = 11;
  447. // WellKnown rules provide advanced constraints against common string
  448. // patterns
  449. oneof well_known {
  450. // Email specifies that the field must be a valid email address as
  451. // defined by RFC 5322
  452. bool email = 12;
  453. // Hostname specifies that the field must be a valid hostname as
  454. // defined by RFC 1034. This constraint does not support
  455. // internationalized domain names (IDNs).
  456. bool hostname = 13;
  457. // Ip specifies that the field must be a valid IP (v4 or v6) address.
  458. // Valid IPv6 addresses should not include surrounding square brackets.
  459. bool ip = 14;
  460. // Ipv4 specifies that the field must be a valid IPv4 address.
  461. bool ipv4 = 15;
  462. // Ipv6 specifies that the field must be a valid IPv6 address. Valid
  463. // IPv6 addresses should not include surrounding square brackets.
  464. bool ipv6 = 16;
  465. // Uri specifies that the field must be a valid, absolute URI as defined
  466. // by RFC 3986
  467. bool uri = 17;
  468. // UriRef specifies that the field must be a valid URI as defined by RFC
  469. // 3986 and may be relative or absolute.
  470. bool uri_ref = 18;
  471. // Address specifies that the field must be either a valid hostname as
  472. // defined by RFC 1034 (which does not support internationalized domain
  473. // names or IDNs), or it can be a valid IP (v4 or v6).
  474. bool address = 21;
  475. // Uuid specifies that the field must be a valid UUID as defined by
  476. // RFC 4122
  477. bool uuid = 22;
  478. // WellKnownRegex specifies a common well known pattern defined as a regex.
  479. KnownRegex well_known_regex = 24;
  480. }
  481. // This applies to regexes HTTP_HEADER_NAME and HTTP_HEADER_VALUE to enable
  482. // strict header validation.
  483. // By default, this is true, and HTTP header validations are RFC-compliant.
  484. // Setting to false will enable a looser validations that only disallows
  485. // \r\n\0 characters, which can be used to bypass header matching rules.
  486. optional bool strict = 25 [default = true];
  487. // IgnoreEmpty specifies that the validation rules of this field should be
  488. // evaluated only if the field is not empty
  489. optional bool ignore_empty = 26;
  490. }
  491. // WellKnownRegex contain some well-known patterns.
  492. enum KnownRegex {
  493. UNKNOWN = 0;
  494. // HTTP header name as defined by RFC 7230.
  495. HTTP_HEADER_NAME = 1;
  496. // HTTP header value as defined by RFC 7230.
  497. HTTP_HEADER_VALUE = 2;
  498. }
  499. // BytesRules describe the constraints applied to `bytes` values
  500. message BytesRules {
  501. // Const specifies that this field must be exactly the specified value
  502. optional bytes const = 1;
  503. // Len specifies that this field must be the specified number of bytes
  504. optional uint64 len = 13;
  505. // MinLen specifies that this field must be the specified number of bytes
  506. // at a minimum
  507. optional uint64 min_len = 2;
  508. // MaxLen specifies that this field must be the specified number of bytes
  509. // at a maximum
  510. optional uint64 max_len = 3;
  511. // Pattern specifes that this field must match against the specified
  512. // regular expression (RE2 syntax). The included expression should elide
  513. // any delimiters.
  514. optional string pattern = 4;
  515. // Prefix specifies that this field must have the specified bytes at the
  516. // beginning of the string.
  517. optional bytes prefix = 5;
  518. // Suffix specifies that this field must have the specified bytes at the
  519. // end of the string.
  520. optional bytes suffix = 6;
  521. // Contains specifies that this field must have the specified bytes
  522. // anywhere in the string.
  523. optional bytes contains = 7;
  524. // In specifies that this field must be equal to one of the specified
  525. // values
  526. repeated bytes in = 8;
  527. // NotIn specifies that this field cannot be equal to one of the specified
  528. // values
  529. repeated bytes not_in = 9;
  530. // WellKnown rules provide advanced constraints against common byte
  531. // patterns
  532. oneof well_known {
  533. // Ip specifies that the field must be a valid IP (v4 or v6) address in
  534. // byte format
  535. bool ip = 10;
  536. // Ipv4 specifies that the field must be a valid IPv4 address in byte
  537. // format
  538. bool ipv4 = 11;
  539. // Ipv6 specifies that the field must be a valid IPv6 address in byte
  540. // format
  541. bool ipv6 = 12;
  542. }
  543. // IgnoreEmpty specifies that the validation rules of this field should be
  544. // evaluated only if the field is not empty
  545. optional bool ignore_empty = 14;
  546. }
  547. // EnumRules describe the constraints applied to enum values
  548. message EnumRules {
  549. // Const specifies that this field must be exactly the specified value
  550. optional int32 const = 1;
  551. // DefinedOnly specifies that this field must be only one of the defined
  552. // values for this enum, failing on any undefined value.
  553. optional bool defined_only = 2;
  554. // In specifies that this field must be equal to one of the specified
  555. // values
  556. repeated int32 in = 3;
  557. // NotIn specifies that this field cannot be equal to one of the specified
  558. // values
  559. repeated int32 not_in = 4;
  560. }
  561. // MessageRules describe the constraints applied to embedded message values.
  562. // For message-type fields, validation is performed recursively.
  563. message MessageRules {
  564. // Skip specifies that the validation rules of this field should not be
  565. // evaluated
  566. optional bool skip = 1;
  567. // Required specifies that this field must be set
  568. optional bool required = 2;
  569. }
  570. // RepeatedRules describe the constraints applied to `repeated` values
  571. message RepeatedRules {
  572. // MinItems specifies that this field must have the specified number of
  573. // items at a minimum
  574. optional uint64 min_items = 1;
  575. // MaxItems specifies that this field must have the specified number of
  576. // items at a maximum
  577. optional uint64 max_items = 2;
  578. // Unique specifies that all elements in this field must be unique. This
  579. // contraint is only applicable to scalar and enum types (messages are not
  580. // supported).
  581. optional bool unique = 3;
  582. // Items specifies the contraints to be applied to each item in the field.
  583. // Repeated message fields will still execute validation against each item
  584. // unless skip is specified here.
  585. optional FieldRules items = 4;
  586. // IgnoreEmpty specifies that the validation rules of this field should be
  587. // evaluated only if the field is not empty
  588. optional bool ignore_empty = 5;
  589. }
  590. // MapRules describe the constraints applied to `map` values
  591. message MapRules {
  592. // MinPairs specifies that this field must have the specified number of
  593. // KVs at a minimum
  594. optional uint64 min_pairs = 1;
  595. // MaxPairs specifies that this field must have the specified number of
  596. // KVs at a maximum
  597. optional uint64 max_pairs = 2;
  598. // NoSparse specifies values in this field cannot be unset. This only
  599. // applies to map's with message value types.
  600. optional bool no_sparse = 3;
  601. // Keys specifies the constraints to be applied to each key in the field.
  602. optional FieldRules keys = 4;
  603. // Values specifies the constraints to be applied to the value of each key
  604. // in the field. Message values will still have their validations evaluated
  605. // unless skip is specified here.
  606. optional FieldRules values = 5;
  607. // IgnoreEmpty specifies that the validation rules of this field should be
  608. // evaluated only if the field is not empty
  609. optional bool ignore_empty = 6;
  610. }
  611. // AnyRules describe constraints applied exclusively to the
  612. // `google.protobuf.Any` well-known type
  613. message AnyRules {
  614. // Required specifies that this field must be set
  615. optional bool required = 1;
  616. // In specifies that this field's `type_url` must be equal to one of the
  617. // specified values.
  618. repeated string in = 2;
  619. // NotIn specifies that this field's `type_url` must not be equal to any of
  620. // the specified values.
  621. repeated string not_in = 3;
  622. }
  623. // DurationRules describe the constraints applied exclusively to the
  624. // `google.protobuf.Duration` well-known type
  625. message DurationRules {
  626. // Required specifies that this field must be set
  627. optional bool required = 1;
  628. // Const specifies that this field must be exactly the specified value
  629. optional google.protobuf.Duration const = 2;
  630. // Lt specifies that this field must be less than the specified value,
  631. // exclusive
  632. optional google.protobuf.Duration lt = 3;
  633. // Lt specifies that this field must be less than the specified value,
  634. // inclusive
  635. optional google.protobuf.Duration lte = 4;
  636. // Gt specifies that this field must be greater than the specified value,
  637. // exclusive
  638. optional google.protobuf.Duration gt = 5;
  639. // Gte specifies that this field must be greater than the specified value,
  640. // inclusive
  641. optional google.protobuf.Duration gte = 6;
  642. // In specifies that this field must be equal to one of the specified
  643. // values
  644. repeated google.protobuf.Duration in = 7;
  645. // NotIn specifies that this field cannot be equal to one of the specified
  646. // values
  647. repeated google.protobuf.Duration not_in = 8;
  648. }
  649. // TimestampRules describe the constraints applied exclusively to the
  650. // `google.protobuf.Timestamp` well-known type
  651. message TimestampRules {
  652. // Required specifies that this field must be set
  653. optional bool required = 1;
  654. // Const specifies that this field must be exactly the specified value
  655. optional google.protobuf.Timestamp const = 2;
  656. // Lt specifies that this field must be less than the specified value,
  657. // exclusive
  658. optional google.protobuf.Timestamp lt = 3;
  659. // Lte specifies that this field must be less than the specified value,
  660. // inclusive
  661. optional google.protobuf.Timestamp lte = 4;
  662. // Gt specifies that this field must be greater than the specified value,
  663. // exclusive
  664. optional google.protobuf.Timestamp gt = 5;
  665. // Gte specifies that this field must be greater than the specified value,
  666. // inclusive
  667. optional google.protobuf.Timestamp gte = 6;
  668. // LtNow specifies that this must be less than the current time. LtNow
  669. // can only be used with the Within rule.
  670. optional bool lt_now = 7;
  671. // GtNow specifies that this must be greater than the current time. GtNow
  672. // can only be used with the Within rule.
  673. optional bool gt_now = 8;
  674. // Within specifies that this field must be within this duration of the
  675. // current time. This constraint can be used alone or with the LtNow and
  676. // GtNow rules.
  677. optional google.protobuf.Duration within = 9;
  678. }