validate.proto 201 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004
  1. // Copyright 2023-2025 Buf Technologies, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto2";
  15. package buf.validate;
  16. import "google/protobuf/descriptor.proto";
  17. import "google/protobuf/duration.proto";
  18. import "google/protobuf/timestamp.proto";
  19. option go_package = "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate";
  20. option java_multiple_files = true;
  21. option java_outer_classname = "ValidateProto";
  22. option java_package = "build.buf.validate";
  23. // MessageOptions is an extension to google.protobuf.MessageOptions. It allows
  24. // the addition of validation rules at the message level. These rules can be
  25. // applied to incoming messages to ensure they meet certain criteria before
  26. // being processed.
  27. extend google.protobuf.MessageOptions {
  28. // Rules specify the validations to be performed on this message. By default,
  29. // no validation is performed against a message.
  30. optional MessageRules message = 1159;
  31. }
  32. // OneofOptions is an extension to google.protobuf.OneofOptions. It allows
  33. // the addition of validation rules on a oneof. These rules can be
  34. // applied to incoming messages to ensure they meet certain criteria before
  35. // being processed.
  36. extend google.protobuf.OneofOptions {
  37. // Rules specify the validations to be performed on this oneof. By default,
  38. // no validation is performed against a oneof.
  39. optional OneofRules oneof = 1159;
  40. }
  41. // FieldOptions is an extension to google.protobuf.FieldOptions. It allows
  42. // the addition of validation rules at the field level. These rules can be
  43. // applied to incoming messages to ensure they meet certain criteria before
  44. // being processed.
  45. extend google.protobuf.FieldOptions {
  46. // Rules specify the validations to be performed on this field. By default,
  47. // no validation is performed against a field.
  48. optional FieldRules field = 1159;
  49. // Specifies predefined rules. When extending a standard rule message,
  50. // this adds additional CEL expressions that apply when the extension is used.
  51. //
  52. // ```proto
  53. // extend buf.validate.Int32Rules {
  54. // bool is_zero [(buf.validate.predefined).cel = {
  55. // id: "int32.is_zero",
  56. // message: "value must be zero",
  57. // expression: "!rule || this == 0",
  58. // }];
  59. // }
  60. //
  61. // message Foo {
  62. // int32 reserved = 1 [(buf.validate.field).int32.(is_zero) = true];
  63. // }
  64. // ```
  65. optional PredefinedRules predefined = 1160;
  66. }
  67. // `Rule` represents a validation rule written in the Common Expression
  68. // Language (CEL) syntax. Each Rule includes a unique identifier, an
  69. // optional error message, and the CEL expression to evaluate. For more
  70. // information, [see our documentation](https://buf.build/docs/protovalidate/schemas/custom-rules/).
  71. //
  72. // ```proto
  73. // message Foo {
  74. // option (buf.validate.message).cel = {
  75. // id: "foo.bar"
  76. // message: "bar must be greater than 0"
  77. // expression: "this.bar > 0"
  78. // };
  79. // int32 bar = 1;
  80. // }
  81. // ```
  82. message Rule {
  83. // `id` is a string that serves as a machine-readable name for this Rule.
  84. // It should be unique within its scope, which could be either a message or a field.
  85. optional string id = 1;
  86. // `message` is an optional field that provides a human-readable error message
  87. // for this Rule when the CEL expression evaluates to false. If a
  88. // non-empty message is provided, any strings resulting from the CEL
  89. // expression evaluation are ignored.
  90. optional string message = 2;
  91. // `expression` is the actual CEL expression that will be evaluated for
  92. // validation. This string must resolve to either a boolean or a string
  93. // value. If the expression evaluates to false or a non-empty string, the
  94. // validation is considered failed, and the message is rejected.
  95. optional string expression = 3;
  96. }
  97. // MessageRules represents validation rules that are applied to the entire message.
  98. // It includes disabling options and a list of Rule messages representing Common Expression Language (CEL) validation rules.
  99. message MessageRules {
  100. // `cel` is a repeated field of type Rule. Each Rule specifies a validation rule to be applied to this message.
  101. // These rules are written in Common Expression Language (CEL) syntax. For more information,
  102. // [see our documentation](https://buf.build/docs/protovalidate/schemas/custom-rules/).
  103. //
  104. //
  105. // ```proto
  106. // message MyMessage {
  107. // // The field `foo` must be greater than 42.
  108. // option (buf.validate.message).cel = {
  109. // id: "my_message.value",
  110. // message: "value must be greater than 42",
  111. // expression: "this.foo > 42",
  112. // };
  113. // optional int32 foo = 1;
  114. // }
  115. // ```
  116. repeated Rule cel = 3;
  117. // `oneof` is a repeated field of type MessageOneofRule that specifies a list of fields
  118. // of which at most one can be present. If `required` is also specified, then exactly one
  119. // of the specified fields _must_ be present.
  120. //
  121. // This will enforce oneof-like constraints with a few features not provided by
  122. // actual Protobuf oneof declarations:
  123. // 1. Repeated and map fields are allowed in this validation. In a Protobuf oneof,
  124. // only scalar fields are allowed.
  125. // 2. Fields with implicit presence are allowed. In a Protobuf oneof, all member
  126. // fields have explicit presence. This means that, for the purpose of determining
  127. // how many fields are set, explicitly setting such a field to its zero value is
  128. // effectively the same as not setting it at all.
  129. // 3. This will always generate validation errors for a message unmarshalled from
  130. // serialized data that sets more than one field. With a Protobuf oneof, when
  131. // multiple fields are present in the serialized form, earlier values are usually
  132. // silently ignored when unmarshalling, with only the last field being set when
  133. // unmarshalling completes.
  134. //
  135. // Note that adding a field to a `oneof` will also set the IGNORE_IF_ZERO_VALUE on the fields. This means
  136. // only the field that is set will be validated and the unset fields are not validated according to the field rules.
  137. // This behavior can be overridden by setting `ignore` against a field.
  138. //
  139. // ```proto
  140. // message MyMessage {
  141. // // Only one of `field1` or `field2` _can_ be present in this message.
  142. // option (buf.validate.message).oneof = { fields: ["field1", "field2"] };
  143. // // Exactly one of `field3` or `field4` _must_ be present in this message.
  144. // option (buf.validate.message).oneof = { fields: ["field3", "field4"], required: true };
  145. // string field1 = 1;
  146. // bytes field2 = 2;
  147. // bool field3 = 3;
  148. // int32 field4 = 4;
  149. // }
  150. // ```
  151. repeated MessageOneofRule oneof = 4;
  152. reserved 1;
  153. reserved "disabled";
  154. }
  155. message MessageOneofRule {
  156. // A list of field names to include in the oneof. All field names must be
  157. // defined in the message. At least one field must be specified, and
  158. // duplicates are not permitted.
  159. repeated string fields = 1;
  160. // If true, one of the fields specified _must_ be set.
  161. optional bool required = 2;
  162. }
  163. // The `OneofRules` message type enables you to manage rules for
  164. // oneof fields in your protobuf messages.
  165. message OneofRules {
  166. // If `required` is true, exactly one field of the oneof must be set. A
  167. // validation error is returned if no fields in the oneof are set. Further rules
  168. // should be placed on the fields themselves to ensure they are valid values,
  169. // such as `min_len` or `gt`.
  170. //
  171. // ```proto
  172. // message MyMessage {
  173. // oneof value {
  174. // // Either `a` or `b` must be set. If `a` is set, it must also be
  175. // // non-empty; whereas if `b` is set, it can still be an empty string.
  176. // option (buf.validate.oneof).required = true;
  177. // string a = 1 [(buf.validate.field).string.min_len = 1];
  178. // string b = 2;
  179. // }
  180. // }
  181. // ```
  182. optional bool required = 1;
  183. }
  184. // FieldRules encapsulates the rules for each type of field. Depending on
  185. // the field, the correct set should be used to ensure proper validations.
  186. message FieldRules {
  187. // `cel` is a repeated field used to represent a textual expression
  188. // in the Common Expression Language (CEL) syntax. For more information,
  189. // [see our documentation](https://buf.build/docs/protovalidate/schemas/custom-rules/).
  190. //
  191. // ```proto
  192. // message MyMessage {
  193. // // The field `value` must be greater than 42.
  194. // optional int32 value = 1 [(buf.validate.field).cel = {
  195. // id: "my_message.value",
  196. // message: "value must be greater than 42",
  197. // expression: "this > 42",
  198. // }];
  199. // }
  200. // ```
  201. repeated Rule cel = 23;
  202. // If `required` is true, the field must be set. A validation error is returned
  203. // if the field is not set.
  204. //
  205. // ```proto
  206. // syntax="proto3";
  207. //
  208. // message FieldsWithPresence {
  209. // // Requires any string to be set, including the empty string.
  210. // optional string link = 1 [
  211. // (buf.validate.field).required = true
  212. // ];
  213. // // Requires true or false to be set.
  214. // optional bool disabled = 2 [
  215. // (buf.validate.field).required = true
  216. // ];
  217. // // Requires a message to be set, including the empty message.
  218. // SomeMessage msg = 4 [
  219. // (buf.validate.field).required = true
  220. // ];
  221. // }
  222. // ```
  223. //
  224. // All fields in the example above track presence. By default, Protovalidate
  225. // ignores rules on those fields if no value is set. `required` ensures that
  226. // the fields are set and valid.
  227. //
  228. // Fields that don't track presence are always validated by Protovalidate,
  229. // whether they are set or not. It is not necessary to add `required`. It
  230. // can be added to indicate that the field cannot be the zero value.
  231. //
  232. // ```proto
  233. // syntax="proto3";
  234. //
  235. // message FieldsWithoutPresence {
  236. // // `string.email` always applies, even to an empty string.
  237. // string link = 1 [
  238. // (buf.validate.field).string.email = true
  239. // ];
  240. // // `repeated.min_items` always applies, even to an empty list.
  241. // repeated string labels = 2 [
  242. // (buf.validate.field).repeated.min_items = 1
  243. // ];
  244. // // `required`, for fields that don't track presence, indicates
  245. // // the value of the field can't be the zero value.
  246. // int32 zero_value_not_allowed = 3 [
  247. // (buf.validate.field).required = true
  248. // ];
  249. // }
  250. // ```
  251. //
  252. // To learn which fields track presence, see the
  253. // [Field Presence cheat sheet](https://protobuf.dev/programming-guides/field_presence/#cheat).
  254. //
  255. // Note: While field rules can be applied to repeated items, map keys, and map
  256. // values, the elements are always considered to be set. Consequently,
  257. // specifying `repeated.items.required` is redundant.
  258. optional bool required = 25;
  259. // Ignore validation rules on the field if its value matches the specified
  260. // criteria. See the `Ignore` enum for details.
  261. //
  262. // ```proto
  263. // message UpdateRequest {
  264. // // The uri rule only applies if the field is not an empty string.
  265. // string url = 1 [
  266. // (buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
  267. // (buf.validate.field).string.uri = true
  268. // ];
  269. // }
  270. // ```
  271. optional Ignore ignore = 27;
  272. oneof type {
  273. // Scalar Field Types
  274. FloatRules float = 1;
  275. DoubleRules double = 2;
  276. Int32Rules int32 = 3;
  277. Int64Rules int64 = 4;
  278. UInt32Rules uint32 = 5;
  279. UInt64Rules uint64 = 6;
  280. SInt32Rules sint32 = 7;
  281. SInt64Rules sint64 = 8;
  282. Fixed32Rules fixed32 = 9;
  283. Fixed64Rules fixed64 = 10;
  284. SFixed32Rules sfixed32 = 11;
  285. SFixed64Rules sfixed64 = 12;
  286. BoolRules bool = 13;
  287. StringRules string = 14;
  288. BytesRules bytes = 15;
  289. // Complex Field Types
  290. EnumRules enum = 16;
  291. RepeatedRules repeated = 18;
  292. MapRules map = 19;
  293. // Well-Known Field Types
  294. AnyRules any = 20;
  295. DurationRules duration = 21;
  296. TimestampRules timestamp = 22;
  297. }
  298. reserved 24, 26;
  299. reserved "skipped", "ignore_empty";
  300. }
  301. // PredefinedRules are custom rules that can be re-used with
  302. // multiple fields.
  303. message PredefinedRules {
  304. // `cel` is a repeated field used to represent a textual expression
  305. // in the Common Expression Language (CEL) syntax. For more information,
  306. // [see our documentation](https://buf.build/docs/protovalidate/schemas/predefined-rules/).
  307. //
  308. // ```proto
  309. // message MyMessage {
  310. // // The field `value` must be greater than 42.
  311. // optional int32 value = 1 [(buf.validate.predefined).cel = {
  312. // id: "my_message.value",
  313. // message: "value must be greater than 42",
  314. // expression: "this > 42",
  315. // }];
  316. // }
  317. // ```
  318. repeated Rule cel = 1;
  319. reserved 24, 26;
  320. reserved "skipped", "ignore_empty";
  321. }
  322. // Specifies how `FieldRules.ignore` behaves, depending on the field's value, and
  323. // whether the field tracks presence.
  324. enum Ignore {
  325. // Ignore rules if the field tracks presence and is unset. This is the default
  326. // behavior.
  327. //
  328. // In proto3, only message fields, members of a Protobuf `oneof`, and fields
  329. // with the `optional` label track presence. Consequently, the following fields
  330. // are always validated, whether a value is set or not:
  331. //
  332. // ```proto
  333. // syntax="proto3";
  334. //
  335. // message RulesApply {
  336. // string email = 1 [
  337. // (buf.validate.field).string.email = true
  338. // ];
  339. // int32 age = 2 [
  340. // (buf.validate.field).int32.gt = 0
  341. // ];
  342. // repeated string labels = 3 [
  343. // (buf.validate.field).repeated.min_items = 1
  344. // ];
  345. // }
  346. // ```
  347. //
  348. // In contrast, the following fields track presence, and are only validated if
  349. // a value is set:
  350. //
  351. // ```proto
  352. // syntax="proto3";
  353. //
  354. // message RulesApplyIfSet {
  355. // optional string email = 1 [
  356. // (buf.validate.field).string.email = true
  357. // ];
  358. // oneof ref {
  359. // string reference = 2 [
  360. // (buf.validate.field).string.uuid = true
  361. // ];
  362. // string name = 3 [
  363. // (buf.validate.field).string.min_len = 4
  364. // ];
  365. // }
  366. // SomeMessage msg = 4 [
  367. // (buf.validate.field).cel = {/* ... */}
  368. // ];
  369. // }
  370. // ```
  371. //
  372. // To ensure that such a field is set, add the `required` rule.
  373. //
  374. // To learn which fields track presence, see the
  375. // [Field Presence cheat sheet](https://protobuf.dev/programming-guides/field_presence/#cheat).
  376. IGNORE_UNSPECIFIED = 0;
  377. // Ignore rules if the field is unset, or set to the zero value.
  378. //
  379. // The zero value depends on the field type:
  380. // - For strings, the zero value is the empty string.
  381. // - For bytes, the zero value is empty bytes.
  382. // - For bool, the zero value is false.
  383. // - For numeric types, the zero value is zero.
  384. // - For enums, the zero value is the first defined enum value.
  385. // - For repeated fields, the zero is an empty list.
  386. // - For map fields, the zero is an empty map.
  387. // - For message fields, absence of the message (typically a null-value) is considered zero value.
  388. //
  389. // For fields that track presence (e.g. adding the `optional` label in proto3),
  390. // this a no-op and behavior is the same as the default `IGNORE_UNSPECIFIED`.
  391. IGNORE_IF_ZERO_VALUE = 1;
  392. // Always ignore rules, including the `required` rule.
  393. //
  394. // This is useful for ignoring the rules of a referenced message, or to
  395. // temporarily ignore rules during development.
  396. //
  397. // ```proto
  398. // message MyMessage {
  399. // // The field's rules will always be ignored, including any validations
  400. // // on value's fields.
  401. // MyOtherMessage value = 1 [
  402. // (buf.validate.field).ignore = IGNORE_ALWAYS
  403. // ];
  404. // }
  405. // ```
  406. IGNORE_ALWAYS = 3;
  407. reserved 2;
  408. reserved "IGNORE_EMPTY", "IGNORE_DEFAULT", "IGNORE_IF_DEFAULT_VALUE", "IGNORE_IF_UNPOPULATED";
  409. }
  410. // FloatRules describes the rules applied to `float` values. These
  411. // rules may also be applied to the `google.protobuf.FloatValue` Well-Known-Type.
  412. message FloatRules {
  413. // `const` requires the field value to exactly match the specified value. If
  414. // the field value doesn't match, an error message is generated.
  415. //
  416. // ```proto
  417. // message MyFloat {
  418. // // value must equal 42.0
  419. // float value = 1 [(buf.validate.field).float.const = 42.0];
  420. // }
  421. // ```
  422. optional float const = 1 [(predefined).cel = {
  423. id: "float.const"
  424. expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
  425. }];
  426. oneof less_than {
  427. // `lt` requires the field value to be less than the specified value (field <
  428. // value). If the field value is equal to or greater than the specified value,
  429. // an error message is generated.
  430. //
  431. // ```proto
  432. // message MyFloat {
  433. // // value must be less than 10.0
  434. // float value = 1 [(buf.validate.field).float.lt = 10.0];
  435. // }
  436. // ```
  437. float lt = 2 [(predefined).cel = {
  438. id: "float.lt"
  439. expression:
  440. "!has(rules.gte) && !has(rules.gt) && (this.isNan() || this >= rules.lt)"
  441. "? 'value must be less than %s'.format([rules.lt]) : ''"
  442. }];
  443. // `lte` requires the field value to be less than or equal to the specified
  444. // value (field <= value). If the field value is greater than the specified
  445. // value, an error message is generated.
  446. //
  447. // ```proto
  448. // message MyFloat {
  449. // // value must be less than or equal to 10.0
  450. // float value = 1 [(buf.validate.field).float.lte = 10.0];
  451. // }
  452. // ```
  453. float lte = 3 [(predefined).cel = {
  454. id: "float.lte"
  455. expression:
  456. "!has(rules.gte) && !has(rules.gt) && (this.isNan() || this > rules.lte)"
  457. "? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
  458. }];
  459. }
  460. oneof greater_than {
  461. // `gt` requires the field value to be greater than the specified value
  462. // (exclusive). If the value of `gt` is larger than a specified `lt` or
  463. // `lte`, the range is reversed, and the field value must be outside the
  464. // specified range. If the field value doesn't meet the required conditions,
  465. // an error message is generated.
  466. //
  467. // ```proto
  468. // message MyFloat {
  469. // // value must be greater than 5.0 [float.gt]
  470. // float value = 1 [(buf.validate.field).float.gt = 5.0];
  471. //
  472. // // value must be greater than 5 and less than 10.0 [float.gt_lt]
  473. // float other_value = 2 [(buf.validate.field).float = { gt: 5.0, lt: 10.0 }];
  474. //
  475. // // value must be greater than 10 or less than 5.0 [float.gt_lt_exclusive]
  476. // float another_value = 3 [(buf.validate.field).float = { gt: 10.0, lt: 5.0 }];
  477. // }
  478. // ```
  479. float gt = 4 [
  480. (predefined).cel = {
  481. id: "float.gt"
  482. expression:
  483. "!has(rules.lt) && !has(rules.lte) && (this.isNan() || this <= rules.gt)"
  484. "? 'value must be greater than %s'.format([rules.gt]) : ''"
  485. },
  486. (predefined).cel = {
  487. id: "float.gt_lt"
  488. expression:
  489. "has(rules.lt) && rules.lt >= rules.gt && (this.isNan() || this >= rules.lt || this <= rules.gt)"
  490. "? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
  491. },
  492. (predefined).cel = {
  493. id: "float.gt_lt_exclusive"
  494. expression:
  495. "has(rules.lt) && rules.lt < rules.gt && (this.isNan() || (rules.lt <= this && this <= rules.gt))"
  496. "? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
  497. },
  498. (predefined).cel = {
  499. id: "float.gt_lte"
  500. expression:
  501. "has(rules.lte) && rules.lte >= rules.gt && (this.isNan() || this > rules.lte || this <= rules.gt)"
  502. "? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  503. },
  504. (predefined).cel = {
  505. id: "float.gt_lte_exclusive"
  506. expression:
  507. "has(rules.lte) && rules.lte < rules.gt && (this.isNan() || (rules.lte < this && this <= rules.gt))"
  508. "? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  509. }
  510. ];
  511. // `gte` requires the field value to be greater than or equal to the specified
  512. // value (exclusive). If the value of `gte` is larger than a specified `lt`
  513. // or `lte`, the range is reversed, and the field value must be outside the
  514. // specified range. If the field value doesn't meet the required conditions,
  515. // an error message is generated.
  516. //
  517. // ```proto
  518. // message MyFloat {
  519. // // value must be greater than or equal to 5.0 [float.gte]
  520. // float value = 1 [(buf.validate.field).float.gte = 5.0];
  521. //
  522. // // value must be greater than or equal to 5.0 and less than 10.0 [float.gte_lt]
  523. // float other_value = 2 [(buf.validate.field).float = { gte: 5.0, lt: 10.0 }];
  524. //
  525. // // value must be greater than or equal to 10.0 or less than 5.0 [float.gte_lt_exclusive]
  526. // float another_value = 3 [(buf.validate.field).float = { gte: 10.0, lt: 5.0 }];
  527. // }
  528. // ```
  529. float gte = 5 [
  530. (predefined).cel = {
  531. id: "float.gte"
  532. expression:
  533. "!has(rules.lt) && !has(rules.lte) && (this.isNan() || this < rules.gte)"
  534. "? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
  535. },
  536. (predefined).cel = {
  537. id: "float.gte_lt"
  538. expression:
  539. "has(rules.lt) && rules.lt >= rules.gte && (this.isNan() || this >= rules.lt || this < rules.gte)"
  540. "? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
  541. },
  542. (predefined).cel = {
  543. id: "float.gte_lt_exclusive"
  544. expression:
  545. "has(rules.lt) && rules.lt < rules.gte && (this.isNan() || (rules.lt <= this && this < rules.gte))"
  546. "? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
  547. },
  548. (predefined).cel = {
  549. id: "float.gte_lte"
  550. expression:
  551. "has(rules.lte) && rules.lte >= rules.gte && (this.isNan() || this > rules.lte || this < rules.gte)"
  552. "? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  553. },
  554. (predefined).cel = {
  555. id: "float.gte_lte_exclusive"
  556. expression:
  557. "has(rules.lte) && rules.lte < rules.gte && (this.isNan() || (rules.lte < this && this < rules.gte))"
  558. "? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  559. }
  560. ];
  561. }
  562. // `in` requires the field value to be equal to one of the specified values.
  563. // If the field value isn't one of the specified values, an error message
  564. // is generated.
  565. //
  566. // ```proto
  567. // message MyFloat {
  568. // // value must be in list [1.0, 2.0, 3.0]
  569. // float value = 1 [(buf.validate.field).float = { in: [1.0, 2.0, 3.0] }];
  570. // }
  571. // ```
  572. repeated float in = 6 [(predefined).cel = {
  573. id: "float.in"
  574. expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
  575. }];
  576. // `in` requires the field value to not be equal to any of the specified
  577. // values. If the field value is one of the specified values, an error
  578. // message is generated.
  579. //
  580. // ```proto
  581. // message MyFloat {
  582. // // value must not be in list [1.0, 2.0, 3.0]
  583. // float value = 1 [(buf.validate.field).float = { not_in: [1.0, 2.0, 3.0] }];
  584. // }
  585. // ```
  586. repeated float not_in = 7 [(predefined).cel = {
  587. id: "float.not_in"
  588. expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''"
  589. }];
  590. // `finite` requires the field value to be finite. If the field value is
  591. // infinite or NaN, an error message is generated.
  592. optional bool finite = 8 [(predefined).cel = {
  593. id: "float.finite"
  594. expression: "rules.finite ? (this.isNan() || this.isInf() ? 'value must be finite' : '') : ''"
  595. }];
  596. // `example` specifies values that the field may have. These values SHOULD
  597. // conform to other rules. `example` values will not impact validation
  598. // but may be used as helpful guidance on how to populate the given field.
  599. //
  600. // ```proto
  601. // message MyFloat {
  602. // float value = 1 [
  603. // (buf.validate.field).float.example = 1.0,
  604. // (buf.validate.field).float.example = inf
  605. // ];
  606. // }
  607. // ```
  608. repeated float example = 9 [(predefined).cel = {
  609. id: "float.example"
  610. expression: "true"
  611. }];
  612. // Extension fields in this range that have the (buf.validate.predefined)
  613. // option set will be treated as predefined field rules that can then be
  614. // set on the field options of other fields to apply field rules.
  615. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  616. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  617. // above this range are reserved for extension numbers that are not explicitly
  618. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  619. // above 99999 is discouraged due to the risk of conflicts.
  620. //
  621. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  622. extensions 1000 to max;
  623. }
  624. // DoubleRules describes the rules applied to `double` values. These
  625. // rules may also be applied to the `google.protobuf.DoubleValue` Well-Known-Type.
  626. message DoubleRules {
  627. // `const` requires the field value to exactly match the specified value. If
  628. // the field value doesn't match, an error message is generated.
  629. //
  630. // ```proto
  631. // message MyDouble {
  632. // // value must equal 42.0
  633. // double value = 1 [(buf.validate.field).double.const = 42.0];
  634. // }
  635. // ```
  636. optional double const = 1 [(predefined).cel = {
  637. id: "double.const"
  638. expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
  639. }];
  640. oneof less_than {
  641. // `lt` requires the field value to be less than the specified value (field <
  642. // value). If the field value is equal to or greater than the specified
  643. // value, an error message is generated.
  644. //
  645. // ```proto
  646. // message MyDouble {
  647. // // value must be less than 10.0
  648. // double value = 1 [(buf.validate.field).double.lt = 10.0];
  649. // }
  650. // ```
  651. double lt = 2 [(predefined).cel = {
  652. id: "double.lt"
  653. expression:
  654. "!has(rules.gte) && !has(rules.gt) && (this.isNan() || this >= rules.lt)"
  655. "? 'value must be less than %s'.format([rules.lt]) : ''"
  656. }];
  657. // `lte` requires the field value to be less than or equal to the specified value
  658. // (field <= value). If the field value is greater than the specified value,
  659. // an error message is generated.
  660. //
  661. // ```proto
  662. // message MyDouble {
  663. // // value must be less than or equal to 10.0
  664. // double value = 1 [(buf.validate.field).double.lte = 10.0];
  665. // }
  666. // ```
  667. double lte = 3 [(predefined).cel = {
  668. id: "double.lte"
  669. expression:
  670. "!has(rules.gte) && !has(rules.gt) && (this.isNan() || this > rules.lte)"
  671. "? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
  672. }];
  673. }
  674. oneof greater_than {
  675. // `gt` requires the field value to be greater than the specified value
  676. // (exclusive). If the value of `gt` is larger than a specified `lt` or `lte`,
  677. // the range is reversed, and the field value must be outside the specified
  678. // range. If the field value doesn't meet the required conditions, an error
  679. // message is generated.
  680. //
  681. // ```proto
  682. // message MyDouble {
  683. // // value must be greater than 5.0 [double.gt]
  684. // double value = 1 [(buf.validate.field).double.gt = 5.0];
  685. //
  686. // // value must be greater than 5 and less than 10.0 [double.gt_lt]
  687. // double other_value = 2 [(buf.validate.field).double = { gt: 5.0, lt: 10.0 }];
  688. //
  689. // // value must be greater than 10 or less than 5.0 [double.gt_lt_exclusive]
  690. // double another_value = 3 [(buf.validate.field).double = { gt: 10.0, lt: 5.0 }];
  691. // }
  692. // ```
  693. double gt = 4 [
  694. (predefined).cel = {
  695. id: "double.gt"
  696. expression:
  697. "!has(rules.lt) && !has(rules.lte) && (this.isNan() || this <= rules.gt)"
  698. "? 'value must be greater than %s'.format([rules.gt]) : ''"
  699. },
  700. (predefined).cel = {
  701. id: "double.gt_lt"
  702. expression:
  703. "has(rules.lt) && rules.lt >= rules.gt && (this.isNan() || this >= rules.lt || this <= rules.gt)"
  704. "? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
  705. },
  706. (predefined).cel = {
  707. id: "double.gt_lt_exclusive"
  708. expression:
  709. "has(rules.lt) && rules.lt < rules.gt && (this.isNan() || (rules.lt <= this && this <= rules.gt))"
  710. "? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
  711. },
  712. (predefined).cel = {
  713. id: "double.gt_lte"
  714. expression:
  715. "has(rules.lte) && rules.lte >= rules.gt && (this.isNan() || this > rules.lte || this <= rules.gt)"
  716. "? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  717. },
  718. (predefined).cel = {
  719. id: "double.gt_lte_exclusive"
  720. expression:
  721. "has(rules.lte) && rules.lte < rules.gt && (this.isNan() || (rules.lte < this && this <= rules.gt))"
  722. "? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  723. }
  724. ];
  725. // `gte` requires the field value to be greater than or equal to the specified
  726. // value (exclusive). If the value of `gte` is larger than a specified `lt` or
  727. // `lte`, the range is reversed, and the field value must be outside the
  728. // specified range. If the field value doesn't meet the required conditions,
  729. // an error message is generated.
  730. //
  731. // ```proto
  732. // message MyDouble {
  733. // // value must be greater than or equal to 5.0 [double.gte]
  734. // double value = 1 [(buf.validate.field).double.gte = 5.0];
  735. //
  736. // // value must be greater than or equal to 5.0 and less than 10.0 [double.gte_lt]
  737. // double other_value = 2 [(buf.validate.field).double = { gte: 5.0, lt: 10.0 }];
  738. //
  739. // // value must be greater than or equal to 10.0 or less than 5.0 [double.gte_lt_exclusive]
  740. // double another_value = 3 [(buf.validate.field).double = { gte: 10.0, lt: 5.0 }];
  741. // }
  742. // ```
  743. double gte = 5 [
  744. (predefined).cel = {
  745. id: "double.gte"
  746. expression:
  747. "!has(rules.lt) && !has(rules.lte) && (this.isNan() || this < rules.gte)"
  748. "? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
  749. },
  750. (predefined).cel = {
  751. id: "double.gte_lt"
  752. expression:
  753. "has(rules.lt) && rules.lt >= rules.gte && (this.isNan() || this >= rules.lt || this < rules.gte)"
  754. "? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
  755. },
  756. (predefined).cel = {
  757. id: "double.gte_lt_exclusive"
  758. expression:
  759. "has(rules.lt) && rules.lt < rules.gte && (this.isNan() || (rules.lt <= this && this < rules.gte))"
  760. "? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
  761. },
  762. (predefined).cel = {
  763. id: "double.gte_lte"
  764. expression:
  765. "has(rules.lte) && rules.lte >= rules.gte && (this.isNan() || this > rules.lte || this < rules.gte)"
  766. "? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  767. },
  768. (predefined).cel = {
  769. id: "double.gte_lte_exclusive"
  770. expression:
  771. "has(rules.lte) && rules.lte < rules.gte && (this.isNan() || (rules.lte < this && this < rules.gte))"
  772. "? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  773. }
  774. ];
  775. }
  776. // `in` requires the field value to be equal to one of the specified values.
  777. // If the field value isn't one of the specified values, an error message is
  778. // generated.
  779. //
  780. // ```proto
  781. // message MyDouble {
  782. // // value must be in list [1.0, 2.0, 3.0]
  783. // double value = 1 [(buf.validate.field).double = { in: [1.0, 2.0, 3.0] }];
  784. // }
  785. // ```
  786. repeated double in = 6 [(predefined).cel = {
  787. id: "double.in"
  788. expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
  789. }];
  790. // `not_in` requires the field value to not be equal to any of the specified
  791. // values. If the field value is one of the specified values, an error
  792. // message is generated.
  793. //
  794. // ```proto
  795. // message MyDouble {
  796. // // value must not be in list [1.0, 2.0, 3.0]
  797. // double value = 1 [(buf.validate.field).double = { not_in: [1.0, 2.0, 3.0] }];
  798. // }
  799. // ```
  800. repeated double not_in = 7 [(predefined).cel = {
  801. id: "double.not_in"
  802. expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''"
  803. }];
  804. // `finite` requires the field value to be finite. If the field value is
  805. // infinite or NaN, an error message is generated.
  806. optional bool finite = 8 [(predefined).cel = {
  807. id: "double.finite"
  808. expression: "rules.finite ? (this.isNan() || this.isInf() ? 'value must be finite' : '') : ''"
  809. }];
  810. // `example` specifies values that the field may have. These values SHOULD
  811. // conform to other rules. `example` values will not impact validation
  812. // but may be used as helpful guidance on how to populate the given field.
  813. //
  814. // ```proto
  815. // message MyDouble {
  816. // double value = 1 [
  817. // (buf.validate.field).double.example = 1.0,
  818. // (buf.validate.field).double.example = inf
  819. // ];
  820. // }
  821. // ```
  822. repeated double example = 9 [(predefined).cel = {
  823. id: "double.example"
  824. expression: "true"
  825. }];
  826. // Extension fields in this range that have the (buf.validate.predefined)
  827. // option set will be treated as predefined field rules that can then be
  828. // set on the field options of other fields to apply field rules.
  829. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  830. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  831. // above this range are reserved for extension numbers that are not explicitly
  832. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  833. // above 99999 is discouraged due to the risk of conflicts.
  834. //
  835. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  836. extensions 1000 to max;
  837. }
  838. // Int32Rules describes the rules applied to `int32` values. These
  839. // rules may also be applied to the `google.protobuf.Int32Value` Well-Known-Type.
  840. message Int32Rules {
  841. // `const` requires the field value to exactly match the specified value. If
  842. // the field value doesn't match, an error message is generated.
  843. //
  844. // ```proto
  845. // message MyInt32 {
  846. // // value must equal 42
  847. // int32 value = 1 [(buf.validate.field).int32.const = 42];
  848. // }
  849. // ```
  850. optional int32 const = 1 [(predefined).cel = {
  851. id: "int32.const"
  852. expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
  853. }];
  854. oneof less_than {
  855. // `lt` requires the field value to be less than the specified value (field
  856. // < value). If the field value is equal to or greater than the specified
  857. // value, an error message is generated.
  858. //
  859. // ```proto
  860. // message MyInt32 {
  861. // // value must be less than 10
  862. // int32 value = 1 [(buf.validate.field).int32.lt = 10];
  863. // }
  864. // ```
  865. int32 lt = 2 [(predefined).cel = {
  866. id: "int32.lt"
  867. expression:
  868. "!has(rules.gte) && !has(rules.gt) && this >= rules.lt"
  869. "? 'value must be less than %s'.format([rules.lt]) : ''"
  870. }];
  871. // `lte` requires the field value to be less than or equal to the specified
  872. // value (field <= value). If the field value is greater than the specified
  873. // value, an error message is generated.
  874. //
  875. // ```proto
  876. // message MyInt32 {
  877. // // value must be less than or equal to 10
  878. // int32 value = 1 [(buf.validate.field).int32.lte = 10];
  879. // }
  880. // ```
  881. int32 lte = 3 [(predefined).cel = {
  882. id: "int32.lte"
  883. expression:
  884. "!has(rules.gte) && !has(rules.gt) && this > rules.lte"
  885. "? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
  886. }];
  887. }
  888. oneof greater_than {
  889. // `gt` requires the field value to be greater than the specified value
  890. // (exclusive). If the value of `gt` is larger than a specified `lt` or
  891. // `lte`, the range is reversed, and the field value must be outside the
  892. // specified range. If the field value doesn't meet the required conditions,
  893. // an error message is generated.
  894. //
  895. // ```proto
  896. // message MyInt32 {
  897. // // value must be greater than 5 [int32.gt]
  898. // int32 value = 1 [(buf.validate.field).int32.gt = 5];
  899. //
  900. // // value must be greater than 5 and less than 10 [int32.gt_lt]
  901. // int32 other_value = 2 [(buf.validate.field).int32 = { gt: 5, lt: 10 }];
  902. //
  903. // // value must be greater than 10 or less than 5 [int32.gt_lt_exclusive]
  904. // int32 another_value = 3 [(buf.validate.field).int32 = { gt: 10, lt: 5 }];
  905. // }
  906. // ```
  907. int32 gt = 4 [
  908. (predefined).cel = {
  909. id: "int32.gt"
  910. expression:
  911. "!has(rules.lt) && !has(rules.lte) && this <= rules.gt"
  912. "? 'value must be greater than %s'.format([rules.gt]) : ''"
  913. },
  914. (predefined).cel = {
  915. id: "int32.gt_lt"
  916. expression:
  917. "has(rules.lt) && rules.lt >= rules.gt && (this >= rules.lt || this <= rules.gt)"
  918. "? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
  919. },
  920. (predefined).cel = {
  921. id: "int32.gt_lt_exclusive"
  922. expression:
  923. "has(rules.lt) && rules.lt < rules.gt && (rules.lt <= this && this <= rules.gt)"
  924. "? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
  925. },
  926. (predefined).cel = {
  927. id: "int32.gt_lte"
  928. expression:
  929. "has(rules.lte) && rules.lte >= rules.gt && (this > rules.lte || this <= rules.gt)"
  930. "? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  931. },
  932. (predefined).cel = {
  933. id: "int32.gt_lte_exclusive"
  934. expression:
  935. "has(rules.lte) && rules.lte < rules.gt && (rules.lte < this && this <= rules.gt)"
  936. "? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  937. }
  938. ];
  939. // `gte` requires the field value to be greater than or equal to the specified value
  940. // (exclusive). If the value of `gte` is larger than a specified `lt` or
  941. // `lte`, the range is reversed, and the field value must be outside the
  942. // specified range. If the field value doesn't meet the required conditions,
  943. // an error message is generated.
  944. //
  945. // ```proto
  946. // message MyInt32 {
  947. // // value must be greater than or equal to 5 [int32.gte]
  948. // int32 value = 1 [(buf.validate.field).int32.gte = 5];
  949. //
  950. // // value must be greater than or equal to 5 and less than 10 [int32.gte_lt]
  951. // int32 other_value = 2 [(buf.validate.field).int32 = { gte: 5, lt: 10 }];
  952. //
  953. // // value must be greater than or equal to 10 or less than 5 [int32.gte_lt_exclusive]
  954. // int32 another_value = 3 [(buf.validate.field).int32 = { gte: 10, lt: 5 }];
  955. // }
  956. // ```
  957. int32 gte = 5 [
  958. (predefined).cel = {
  959. id: "int32.gte"
  960. expression:
  961. "!has(rules.lt) && !has(rules.lte) && this < rules.gte"
  962. "? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
  963. },
  964. (predefined).cel = {
  965. id: "int32.gte_lt"
  966. expression:
  967. "has(rules.lt) && rules.lt >= rules.gte && (this >= rules.lt || this < rules.gte)"
  968. "? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
  969. },
  970. (predefined).cel = {
  971. id: "int32.gte_lt_exclusive"
  972. expression:
  973. "has(rules.lt) && rules.lt < rules.gte && (rules.lt <= this && this < rules.gte)"
  974. "? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
  975. },
  976. (predefined).cel = {
  977. id: "int32.gte_lte"
  978. expression:
  979. "has(rules.lte) && rules.lte >= rules.gte && (this > rules.lte || this < rules.gte)"
  980. "? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  981. },
  982. (predefined).cel = {
  983. id: "int32.gte_lte_exclusive"
  984. expression:
  985. "has(rules.lte) && rules.lte < rules.gte && (rules.lte < this && this < rules.gte)"
  986. "? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  987. }
  988. ];
  989. }
  990. // `in` requires the field value to be equal to one of the specified values.
  991. // If the field value isn't one of the specified values, an error message is
  992. // generated.
  993. //
  994. // ```proto
  995. // message MyInt32 {
  996. // // value must be in list [1, 2, 3]
  997. // int32 value = 1 [(buf.validate.field).int32 = { in: [1, 2, 3] }];
  998. // }
  999. // ```
  1000. repeated int32 in = 6 [(predefined).cel = {
  1001. id: "int32.in"
  1002. expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
  1003. }];
  1004. // `not_in` requires the field value to not be equal to any of the specified
  1005. // values. If the field value is one of the specified values, an error message
  1006. // is generated.
  1007. //
  1008. // ```proto
  1009. // message MyInt32 {
  1010. // // value must not be in list [1, 2, 3]
  1011. // int32 value = 1 [(buf.validate.field).int32 = { not_in: [1, 2, 3] }];
  1012. // }
  1013. // ```
  1014. repeated int32 not_in = 7 [(predefined).cel = {
  1015. id: "int32.not_in"
  1016. expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''"
  1017. }];
  1018. // `example` specifies values that the field may have. These values SHOULD
  1019. // conform to other rules. `example` values will not impact validation
  1020. // but may be used as helpful guidance on how to populate the given field.
  1021. //
  1022. // ```proto
  1023. // message MyInt32 {
  1024. // int32 value = 1 [
  1025. // (buf.validate.field).int32.example = 1,
  1026. // (buf.validate.field).int32.example = -10
  1027. // ];
  1028. // }
  1029. // ```
  1030. repeated int32 example = 8 [(predefined).cel = {
  1031. id: "int32.example"
  1032. expression: "true"
  1033. }];
  1034. // Extension fields in this range that have the (buf.validate.predefined)
  1035. // option set will be treated as predefined field rules that can then be
  1036. // set on the field options of other fields to apply field rules.
  1037. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  1038. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  1039. // above this range are reserved for extension numbers that are not explicitly
  1040. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  1041. // above 99999 is discouraged due to the risk of conflicts.
  1042. //
  1043. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  1044. extensions 1000 to max;
  1045. }
  1046. // Int64Rules describes the rules applied to `int64` values. These
  1047. // rules may also be applied to the `google.protobuf.Int64Value` Well-Known-Type.
  1048. message Int64Rules {
  1049. // `const` requires the field value to exactly match the specified value. If
  1050. // the field value doesn't match, an error message is generated.
  1051. //
  1052. // ```proto
  1053. // message MyInt64 {
  1054. // // value must equal 42
  1055. // int64 value = 1 [(buf.validate.field).int64.const = 42];
  1056. // }
  1057. // ```
  1058. optional int64 const = 1 [(predefined).cel = {
  1059. id: "int64.const"
  1060. expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
  1061. }];
  1062. oneof less_than {
  1063. // `lt` requires the field value to be less than the specified value (field <
  1064. // value). If the field value is equal to or greater than the specified value,
  1065. // an error message is generated.
  1066. //
  1067. // ```proto
  1068. // message MyInt64 {
  1069. // // value must be less than 10
  1070. // int64 value = 1 [(buf.validate.field).int64.lt = 10];
  1071. // }
  1072. // ```
  1073. int64 lt = 2 [(predefined).cel = {
  1074. id: "int64.lt"
  1075. expression:
  1076. "!has(rules.gte) && !has(rules.gt) && this >= rules.lt"
  1077. "? 'value must be less than %s'.format([rules.lt]) : ''"
  1078. }];
  1079. // `lte` requires the field value to be less than or equal to the specified
  1080. // value (field <= value). If the field value is greater than the specified
  1081. // value, an error message is generated.
  1082. //
  1083. // ```proto
  1084. // message MyInt64 {
  1085. // // value must be less than or equal to 10
  1086. // int64 value = 1 [(buf.validate.field).int64.lte = 10];
  1087. // }
  1088. // ```
  1089. int64 lte = 3 [(predefined).cel = {
  1090. id: "int64.lte"
  1091. expression:
  1092. "!has(rules.gte) && !has(rules.gt) && this > rules.lte"
  1093. "? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
  1094. }];
  1095. }
  1096. oneof greater_than {
  1097. // `gt` requires the field value to be greater than the specified value
  1098. // (exclusive). If the value of `gt` is larger than a specified `lt` or
  1099. // `lte`, the range is reversed, and the field value must be outside the
  1100. // specified range. If the field value doesn't meet the required conditions,
  1101. // an error message is generated.
  1102. //
  1103. // ```proto
  1104. // message MyInt64 {
  1105. // // value must be greater than 5 [int64.gt]
  1106. // int64 value = 1 [(buf.validate.field).int64.gt = 5];
  1107. //
  1108. // // value must be greater than 5 and less than 10 [int64.gt_lt]
  1109. // int64 other_value = 2 [(buf.validate.field).int64 = { gt: 5, lt: 10 }];
  1110. //
  1111. // // value must be greater than 10 or less than 5 [int64.gt_lt_exclusive]
  1112. // int64 another_value = 3 [(buf.validate.field).int64 = { gt: 10, lt: 5 }];
  1113. // }
  1114. // ```
  1115. int64 gt = 4 [
  1116. (predefined).cel = {
  1117. id: "int64.gt"
  1118. expression:
  1119. "!has(rules.lt) && !has(rules.lte) && this <= rules.gt"
  1120. "? 'value must be greater than %s'.format([rules.gt]) : ''"
  1121. },
  1122. (predefined).cel = {
  1123. id: "int64.gt_lt"
  1124. expression:
  1125. "has(rules.lt) && rules.lt >= rules.gt && (this >= rules.lt || this <= rules.gt)"
  1126. "? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
  1127. },
  1128. (predefined).cel = {
  1129. id: "int64.gt_lt_exclusive"
  1130. expression:
  1131. "has(rules.lt) && rules.lt < rules.gt && (rules.lt <= this && this <= rules.gt)"
  1132. "? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
  1133. },
  1134. (predefined).cel = {
  1135. id: "int64.gt_lte"
  1136. expression:
  1137. "has(rules.lte) && rules.lte >= rules.gt && (this > rules.lte || this <= rules.gt)"
  1138. "? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  1139. },
  1140. (predefined).cel = {
  1141. id: "int64.gt_lte_exclusive"
  1142. expression:
  1143. "has(rules.lte) && rules.lte < rules.gt && (rules.lte < this && this <= rules.gt)"
  1144. "? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  1145. }
  1146. ];
  1147. // `gte` requires the field value to be greater than or equal to the specified
  1148. // value (exclusive). If the value of `gte` is larger than a specified `lt`
  1149. // or `lte`, the range is reversed, and the field value must be outside the
  1150. // specified range. If the field value doesn't meet the required conditions,
  1151. // an error message is generated.
  1152. //
  1153. // ```proto
  1154. // message MyInt64 {
  1155. // // value must be greater than or equal to 5 [int64.gte]
  1156. // int64 value = 1 [(buf.validate.field).int64.gte = 5];
  1157. //
  1158. // // value must be greater than or equal to 5 and less than 10 [int64.gte_lt]
  1159. // int64 other_value = 2 [(buf.validate.field).int64 = { gte: 5, lt: 10 }];
  1160. //
  1161. // // value must be greater than or equal to 10 or less than 5 [int64.gte_lt_exclusive]
  1162. // int64 another_value = 3 [(buf.validate.field).int64 = { gte: 10, lt: 5 }];
  1163. // }
  1164. // ```
  1165. int64 gte = 5 [
  1166. (predefined).cel = {
  1167. id: "int64.gte"
  1168. expression:
  1169. "!has(rules.lt) && !has(rules.lte) && this < rules.gte"
  1170. "? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
  1171. },
  1172. (predefined).cel = {
  1173. id: "int64.gte_lt"
  1174. expression:
  1175. "has(rules.lt) && rules.lt >= rules.gte && (this >= rules.lt || this < rules.gte)"
  1176. "? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
  1177. },
  1178. (predefined).cel = {
  1179. id: "int64.gte_lt_exclusive"
  1180. expression:
  1181. "has(rules.lt) && rules.lt < rules.gte && (rules.lt <= this && this < rules.gte)"
  1182. "? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
  1183. },
  1184. (predefined).cel = {
  1185. id: "int64.gte_lte"
  1186. expression:
  1187. "has(rules.lte) && rules.lte >= rules.gte && (this > rules.lte || this < rules.gte)"
  1188. "? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  1189. },
  1190. (predefined).cel = {
  1191. id: "int64.gte_lte_exclusive"
  1192. expression:
  1193. "has(rules.lte) && rules.lte < rules.gte && (rules.lte < this && this < rules.gte)"
  1194. "? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  1195. }
  1196. ];
  1197. }
  1198. // `in` requires the field value to be equal to one of the specified values.
  1199. // If the field value isn't one of the specified values, an error message is
  1200. // generated.
  1201. //
  1202. // ```proto
  1203. // message MyInt64 {
  1204. // // value must be in list [1, 2, 3]
  1205. // int64 value = 1 [(buf.validate.field).int64 = { in: [1, 2, 3] }];
  1206. // }
  1207. // ```
  1208. repeated int64 in = 6 [(predefined).cel = {
  1209. id: "int64.in"
  1210. expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
  1211. }];
  1212. // `not_in` requires the field value to not be equal to any of the specified
  1213. // values. If the field value is one of the specified values, an error
  1214. // message is generated.
  1215. //
  1216. // ```proto
  1217. // message MyInt64 {
  1218. // // value must not be in list [1, 2, 3]
  1219. // int64 value = 1 [(buf.validate.field).int64 = { not_in: [1, 2, 3] }];
  1220. // }
  1221. // ```
  1222. repeated int64 not_in = 7 [(predefined).cel = {
  1223. id: "int64.not_in"
  1224. expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''"
  1225. }];
  1226. // `example` specifies values that the field may have. These values SHOULD
  1227. // conform to other rules. `example` values will not impact validation
  1228. // but may be used as helpful guidance on how to populate the given field.
  1229. //
  1230. // ```proto
  1231. // message MyInt64 {
  1232. // int64 value = 1 [
  1233. // (buf.validate.field).int64.example = 1,
  1234. // (buf.validate.field).int64.example = -10
  1235. // ];
  1236. // }
  1237. // ```
  1238. repeated int64 example = 9 [(predefined).cel = {
  1239. id: "int64.example"
  1240. expression: "true"
  1241. }];
  1242. // Extension fields in this range that have the (buf.validate.predefined)
  1243. // option set will be treated as predefined field rules that can then be
  1244. // set on the field options of other fields to apply field rules.
  1245. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  1246. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  1247. // above this range are reserved for extension numbers that are not explicitly
  1248. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  1249. // above 99999 is discouraged due to the risk of conflicts.
  1250. //
  1251. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  1252. extensions 1000 to max;
  1253. }
  1254. // UInt32Rules describes the rules applied to `uint32` values. These
  1255. // rules may also be applied to the `google.protobuf.UInt32Value` Well-Known-Type.
  1256. message UInt32Rules {
  1257. // `const` requires the field value to exactly match the specified value. If
  1258. // the field value doesn't match, an error message is generated.
  1259. //
  1260. // ```proto
  1261. // message MyUInt32 {
  1262. // // value must equal 42
  1263. // uint32 value = 1 [(buf.validate.field).uint32.const = 42];
  1264. // }
  1265. // ```
  1266. optional uint32 const = 1 [(predefined).cel = {
  1267. id: "uint32.const"
  1268. expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
  1269. }];
  1270. oneof less_than {
  1271. // `lt` requires the field value to be less than the specified value (field <
  1272. // value). If the field value is equal to or greater than the specified value,
  1273. // an error message is generated.
  1274. //
  1275. // ```proto
  1276. // message MyUInt32 {
  1277. // // value must be less than 10
  1278. // uint32 value = 1 [(buf.validate.field).uint32.lt = 10];
  1279. // }
  1280. // ```
  1281. uint32 lt = 2 [(predefined).cel = {
  1282. id: "uint32.lt"
  1283. expression:
  1284. "!has(rules.gte) && !has(rules.gt) && this >= rules.lt"
  1285. "? 'value must be less than %s'.format([rules.lt]) : ''"
  1286. }];
  1287. // `lte` requires the field value to be less than or equal to the specified
  1288. // value (field <= value). If the field value is greater than the specified
  1289. // value, an error message is generated.
  1290. //
  1291. // ```proto
  1292. // message MyUInt32 {
  1293. // // value must be less than or equal to 10
  1294. // uint32 value = 1 [(buf.validate.field).uint32.lte = 10];
  1295. // }
  1296. // ```
  1297. uint32 lte = 3 [(predefined).cel = {
  1298. id: "uint32.lte"
  1299. expression:
  1300. "!has(rules.gte) && !has(rules.gt) && this > rules.lte"
  1301. "? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
  1302. }];
  1303. }
  1304. oneof greater_than {
  1305. // `gt` requires the field value to be greater than the specified value
  1306. // (exclusive). If the value of `gt` is larger than a specified `lt` or
  1307. // `lte`, the range is reversed, and the field value must be outside the
  1308. // specified range. If the field value doesn't meet the required conditions,
  1309. // an error message is generated.
  1310. //
  1311. // ```proto
  1312. // message MyUInt32 {
  1313. // // value must be greater than 5 [uint32.gt]
  1314. // uint32 value = 1 [(buf.validate.field).uint32.gt = 5];
  1315. //
  1316. // // value must be greater than 5 and less than 10 [uint32.gt_lt]
  1317. // uint32 other_value = 2 [(buf.validate.field).uint32 = { gt: 5, lt: 10 }];
  1318. //
  1319. // // value must be greater than 10 or less than 5 [uint32.gt_lt_exclusive]
  1320. // uint32 another_value = 3 [(buf.validate.field).uint32 = { gt: 10, lt: 5 }];
  1321. // }
  1322. // ```
  1323. uint32 gt = 4 [
  1324. (predefined).cel = {
  1325. id: "uint32.gt"
  1326. expression:
  1327. "!has(rules.lt) && !has(rules.lte) && this <= rules.gt"
  1328. "? 'value must be greater than %s'.format([rules.gt]) : ''"
  1329. },
  1330. (predefined).cel = {
  1331. id: "uint32.gt_lt"
  1332. expression:
  1333. "has(rules.lt) && rules.lt >= rules.gt && (this >= rules.lt || this <= rules.gt)"
  1334. "? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
  1335. },
  1336. (predefined).cel = {
  1337. id: "uint32.gt_lt_exclusive"
  1338. expression:
  1339. "has(rules.lt) && rules.lt < rules.gt && (rules.lt <= this && this <= rules.gt)"
  1340. "? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
  1341. },
  1342. (predefined).cel = {
  1343. id: "uint32.gt_lte"
  1344. expression:
  1345. "has(rules.lte) && rules.lte >= rules.gt && (this > rules.lte || this <= rules.gt)"
  1346. "? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  1347. },
  1348. (predefined).cel = {
  1349. id: "uint32.gt_lte_exclusive"
  1350. expression:
  1351. "has(rules.lte) && rules.lte < rules.gt && (rules.lte < this && this <= rules.gt)"
  1352. "? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  1353. }
  1354. ];
  1355. // `gte` requires the field value to be greater than or equal to the specified
  1356. // value (exclusive). If the value of `gte` is larger than a specified `lt`
  1357. // or `lte`, the range is reversed, and the field value must be outside the
  1358. // specified range. If the field value doesn't meet the required conditions,
  1359. // an error message is generated.
  1360. //
  1361. // ```proto
  1362. // message MyUInt32 {
  1363. // // value must be greater than or equal to 5 [uint32.gte]
  1364. // uint32 value = 1 [(buf.validate.field).uint32.gte = 5];
  1365. //
  1366. // // value must be greater than or equal to 5 and less than 10 [uint32.gte_lt]
  1367. // uint32 other_value = 2 [(buf.validate.field).uint32 = { gte: 5, lt: 10 }];
  1368. //
  1369. // // value must be greater than or equal to 10 or less than 5 [uint32.gte_lt_exclusive]
  1370. // uint32 another_value = 3 [(buf.validate.field).uint32 = { gte: 10, lt: 5 }];
  1371. // }
  1372. // ```
  1373. uint32 gte = 5 [
  1374. (predefined).cel = {
  1375. id: "uint32.gte"
  1376. expression:
  1377. "!has(rules.lt) && !has(rules.lte) && this < rules.gte"
  1378. "? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
  1379. },
  1380. (predefined).cel = {
  1381. id: "uint32.gte_lt"
  1382. expression:
  1383. "has(rules.lt) && rules.lt >= rules.gte && (this >= rules.lt || this < rules.gte)"
  1384. "? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
  1385. },
  1386. (predefined).cel = {
  1387. id: "uint32.gte_lt_exclusive"
  1388. expression:
  1389. "has(rules.lt) && rules.lt < rules.gte && (rules.lt <= this && this < rules.gte)"
  1390. "? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
  1391. },
  1392. (predefined).cel = {
  1393. id: "uint32.gte_lte"
  1394. expression:
  1395. "has(rules.lte) && rules.lte >= rules.gte && (this > rules.lte || this < rules.gte)"
  1396. "? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  1397. },
  1398. (predefined).cel = {
  1399. id: "uint32.gte_lte_exclusive"
  1400. expression:
  1401. "has(rules.lte) && rules.lte < rules.gte && (rules.lte < this && this < rules.gte)"
  1402. "? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  1403. }
  1404. ];
  1405. }
  1406. // `in` requires the field value to be equal to one of the specified values.
  1407. // If the field value isn't one of the specified values, an error message is
  1408. // generated.
  1409. //
  1410. // ```proto
  1411. // message MyUInt32 {
  1412. // // value must be in list [1, 2, 3]
  1413. // uint32 value = 1 [(buf.validate.field).uint32 = { in: [1, 2, 3] }];
  1414. // }
  1415. // ```
  1416. repeated uint32 in = 6 [(predefined).cel = {
  1417. id: "uint32.in"
  1418. expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
  1419. }];
  1420. // `not_in` requires the field value to not be equal to any of the specified
  1421. // values. If the field value is one of the specified values, an error
  1422. // message is generated.
  1423. //
  1424. // ```proto
  1425. // message MyUInt32 {
  1426. // // value must not be in list [1, 2, 3]
  1427. // uint32 value = 1 [(buf.validate.field).uint32 = { not_in: [1, 2, 3] }];
  1428. // }
  1429. // ```
  1430. repeated uint32 not_in = 7 [(predefined).cel = {
  1431. id: "uint32.not_in"
  1432. expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''"
  1433. }];
  1434. // `example` specifies values that the field may have. These values SHOULD
  1435. // conform to other rules. `example` values will not impact validation
  1436. // but may be used as helpful guidance on how to populate the given field.
  1437. //
  1438. // ```proto
  1439. // message MyUInt32 {
  1440. // uint32 value = 1 [
  1441. // (buf.validate.field).uint32.example = 1,
  1442. // (buf.validate.field).uint32.example = 10
  1443. // ];
  1444. // }
  1445. // ```
  1446. repeated uint32 example = 8 [(predefined).cel = {
  1447. id: "uint32.example"
  1448. expression: "true"
  1449. }];
  1450. // Extension fields in this range that have the (buf.validate.predefined)
  1451. // option set will be treated as predefined field rules that can then be
  1452. // set on the field options of other fields to apply field rules.
  1453. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  1454. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  1455. // above this range are reserved for extension numbers that are not explicitly
  1456. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  1457. // above 99999 is discouraged due to the risk of conflicts.
  1458. //
  1459. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  1460. extensions 1000 to max;
  1461. }
  1462. // UInt64Rules describes the rules applied to `uint64` values. These
  1463. // rules may also be applied to the `google.protobuf.UInt64Value` Well-Known-Type.
  1464. message UInt64Rules {
  1465. // `const` requires the field value to exactly match the specified value. If
  1466. // the field value doesn't match, an error message is generated.
  1467. //
  1468. // ```proto
  1469. // message MyUInt64 {
  1470. // // value must equal 42
  1471. // uint64 value = 1 [(buf.validate.field).uint64.const = 42];
  1472. // }
  1473. // ```
  1474. optional uint64 const = 1 [(predefined).cel = {
  1475. id: "uint64.const"
  1476. expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
  1477. }];
  1478. oneof less_than {
  1479. // `lt` requires the field value to be less than the specified value (field <
  1480. // value). If the field value is equal to or greater than the specified value,
  1481. // an error message is generated.
  1482. //
  1483. // ```proto
  1484. // message MyUInt64 {
  1485. // // value must be less than 10
  1486. // uint64 value = 1 [(buf.validate.field).uint64.lt = 10];
  1487. // }
  1488. // ```
  1489. uint64 lt = 2 [(predefined).cel = {
  1490. id: "uint64.lt"
  1491. expression:
  1492. "!has(rules.gte) && !has(rules.gt) && this >= rules.lt"
  1493. "? 'value must be less than %s'.format([rules.lt]) : ''"
  1494. }];
  1495. // `lte` requires the field value to be less than or equal to the specified
  1496. // value (field <= value). If the field value is greater than the specified
  1497. // value, an error message is generated.
  1498. //
  1499. // ```proto
  1500. // message MyUInt64 {
  1501. // // value must be less than or equal to 10
  1502. // uint64 value = 1 [(buf.validate.field).uint64.lte = 10];
  1503. // }
  1504. // ```
  1505. uint64 lte = 3 [(predefined).cel = {
  1506. id: "uint64.lte"
  1507. expression:
  1508. "!has(rules.gte) && !has(rules.gt) && this > rules.lte"
  1509. "? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
  1510. }];
  1511. }
  1512. oneof greater_than {
  1513. // `gt` requires the field value to be greater than the specified value
  1514. // (exclusive). If the value of `gt` is larger than a specified `lt` or
  1515. // `lte`, the range is reversed, and the field value must be outside the
  1516. // specified range. If the field value doesn't meet the required conditions,
  1517. // an error message is generated.
  1518. //
  1519. // ```proto
  1520. // message MyUInt64 {
  1521. // // value must be greater than 5 [uint64.gt]
  1522. // uint64 value = 1 [(buf.validate.field).uint64.gt = 5];
  1523. //
  1524. // // value must be greater than 5 and less than 10 [uint64.gt_lt]
  1525. // uint64 other_value = 2 [(buf.validate.field).uint64 = { gt: 5, lt: 10 }];
  1526. //
  1527. // // value must be greater than 10 or less than 5 [uint64.gt_lt_exclusive]
  1528. // uint64 another_value = 3 [(buf.validate.field).uint64 = { gt: 10, lt: 5 }];
  1529. // }
  1530. // ```
  1531. uint64 gt = 4 [
  1532. (predefined).cel = {
  1533. id: "uint64.gt"
  1534. expression:
  1535. "!has(rules.lt) && !has(rules.lte) && this <= rules.gt"
  1536. "? 'value must be greater than %s'.format([rules.gt]) : ''"
  1537. },
  1538. (predefined).cel = {
  1539. id: "uint64.gt_lt"
  1540. expression:
  1541. "has(rules.lt) && rules.lt >= rules.gt && (this >= rules.lt || this <= rules.gt)"
  1542. "? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
  1543. },
  1544. (predefined).cel = {
  1545. id: "uint64.gt_lt_exclusive"
  1546. expression:
  1547. "has(rules.lt) && rules.lt < rules.gt && (rules.lt <= this && this <= rules.gt)"
  1548. "? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
  1549. },
  1550. (predefined).cel = {
  1551. id: "uint64.gt_lte"
  1552. expression:
  1553. "has(rules.lte) && rules.lte >= rules.gt && (this > rules.lte || this <= rules.gt)"
  1554. "? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  1555. },
  1556. (predefined).cel = {
  1557. id: "uint64.gt_lte_exclusive"
  1558. expression:
  1559. "has(rules.lte) && rules.lte < rules.gt && (rules.lte < this && this <= rules.gt)"
  1560. "? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  1561. }
  1562. ];
  1563. // `gte` requires the field value to be greater than or equal to the specified
  1564. // value (exclusive). If the value of `gte` is larger than a specified `lt`
  1565. // or `lte`, the range is reversed, and the field value must be outside the
  1566. // specified range. If the field value doesn't meet the required conditions,
  1567. // an error message is generated.
  1568. //
  1569. // ```proto
  1570. // message MyUInt64 {
  1571. // // value must be greater than or equal to 5 [uint64.gte]
  1572. // uint64 value = 1 [(buf.validate.field).uint64.gte = 5];
  1573. //
  1574. // // value must be greater than or equal to 5 and less than 10 [uint64.gte_lt]
  1575. // uint64 other_value = 2 [(buf.validate.field).uint64 = { gte: 5, lt: 10 }];
  1576. //
  1577. // // value must be greater than or equal to 10 or less than 5 [uint64.gte_lt_exclusive]
  1578. // uint64 another_value = 3 [(buf.validate.field).uint64 = { gte: 10, lt: 5 }];
  1579. // }
  1580. // ```
  1581. uint64 gte = 5 [
  1582. (predefined).cel = {
  1583. id: "uint64.gte"
  1584. expression:
  1585. "!has(rules.lt) && !has(rules.lte) && this < rules.gte"
  1586. "? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
  1587. },
  1588. (predefined).cel = {
  1589. id: "uint64.gte_lt"
  1590. expression:
  1591. "has(rules.lt) && rules.lt >= rules.gte && (this >= rules.lt || this < rules.gte)"
  1592. "? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
  1593. },
  1594. (predefined).cel = {
  1595. id: "uint64.gte_lt_exclusive"
  1596. expression:
  1597. "has(rules.lt) && rules.lt < rules.gte && (rules.lt <= this && this < rules.gte)"
  1598. "? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
  1599. },
  1600. (predefined).cel = {
  1601. id: "uint64.gte_lte"
  1602. expression:
  1603. "has(rules.lte) && rules.lte >= rules.gte && (this > rules.lte || this < rules.gte)"
  1604. "? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  1605. },
  1606. (predefined).cel = {
  1607. id: "uint64.gte_lte_exclusive"
  1608. expression:
  1609. "has(rules.lte) && rules.lte < rules.gte && (rules.lte < this && this < rules.gte)"
  1610. "? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  1611. }
  1612. ];
  1613. }
  1614. // `in` requires the field value to be equal to one of the specified values.
  1615. // If the field value isn't one of the specified values, an error message is
  1616. // generated.
  1617. //
  1618. // ```proto
  1619. // message MyUInt64 {
  1620. // // value must be in list [1, 2, 3]
  1621. // uint64 value = 1 [(buf.validate.field).uint64 = { in: [1, 2, 3] }];
  1622. // }
  1623. // ```
  1624. repeated uint64 in = 6 [(predefined).cel = {
  1625. id: "uint64.in"
  1626. expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
  1627. }];
  1628. // `not_in` requires the field value to not be equal to any of the specified
  1629. // values. If the field value is one of the specified values, an error
  1630. // message is generated.
  1631. //
  1632. // ```proto
  1633. // message MyUInt64 {
  1634. // // value must not be in list [1, 2, 3]
  1635. // uint64 value = 1 [(buf.validate.field).uint64 = { not_in: [1, 2, 3] }];
  1636. // }
  1637. // ```
  1638. repeated uint64 not_in = 7 [(predefined).cel = {
  1639. id: "uint64.not_in"
  1640. expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''"
  1641. }];
  1642. // `example` specifies values that the field may have. These values SHOULD
  1643. // conform to other rules. `example` values will not impact validation
  1644. // but may be used as helpful guidance on how to populate the given field.
  1645. //
  1646. // ```proto
  1647. // message MyUInt64 {
  1648. // uint64 value = 1 [
  1649. // (buf.validate.field).uint64.example = 1,
  1650. // (buf.validate.field).uint64.example = -10
  1651. // ];
  1652. // }
  1653. // ```
  1654. repeated uint64 example = 8 [(predefined).cel = {
  1655. id: "uint64.example"
  1656. expression: "true"
  1657. }];
  1658. // Extension fields in this range that have the (buf.validate.predefined)
  1659. // option set will be treated as predefined field rules that can then be
  1660. // set on the field options of other fields to apply field rules.
  1661. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  1662. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  1663. // above this range are reserved for extension numbers that are not explicitly
  1664. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  1665. // above 99999 is discouraged due to the risk of conflicts.
  1666. //
  1667. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  1668. extensions 1000 to max;
  1669. }
  1670. // SInt32Rules describes the rules applied to `sint32` values.
  1671. message SInt32Rules {
  1672. // `const` requires the field value to exactly match the specified value. If
  1673. // the field value doesn't match, an error message is generated.
  1674. //
  1675. // ```proto
  1676. // message MySInt32 {
  1677. // // value must equal 42
  1678. // sint32 value = 1 [(buf.validate.field).sint32.const = 42];
  1679. // }
  1680. // ```
  1681. optional sint32 const = 1 [(predefined).cel = {
  1682. id: "sint32.const"
  1683. expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
  1684. }];
  1685. oneof less_than {
  1686. // `lt` requires the field value to be less than the specified value (field
  1687. // < value). If the field value is equal to or greater than the specified
  1688. // value, an error message is generated.
  1689. //
  1690. // ```proto
  1691. // message MySInt32 {
  1692. // // value must be less than 10
  1693. // sint32 value = 1 [(buf.validate.field).sint32.lt = 10];
  1694. // }
  1695. // ```
  1696. sint32 lt = 2 [(predefined).cel = {
  1697. id: "sint32.lt"
  1698. expression:
  1699. "!has(rules.gte) && !has(rules.gt) && this >= rules.lt"
  1700. "? 'value must be less than %s'.format([rules.lt]) : ''"
  1701. }];
  1702. // `lte` requires the field value to be less than or equal to the specified
  1703. // value (field <= value). If the field value is greater than the specified
  1704. // value, an error message is generated.
  1705. //
  1706. // ```proto
  1707. // message MySInt32 {
  1708. // // value must be less than or equal to 10
  1709. // sint32 value = 1 [(buf.validate.field).sint32.lte = 10];
  1710. // }
  1711. // ```
  1712. sint32 lte = 3 [(predefined).cel = {
  1713. id: "sint32.lte"
  1714. expression:
  1715. "!has(rules.gte) && !has(rules.gt) && this > rules.lte"
  1716. "? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
  1717. }];
  1718. }
  1719. oneof greater_than {
  1720. // `gt` requires the field value to be greater than the specified value
  1721. // (exclusive). If the value of `gt` is larger than a specified `lt` or
  1722. // `lte`, the range is reversed, and the field value must be outside the
  1723. // specified range. If the field value doesn't meet the required conditions,
  1724. // an error message is generated.
  1725. //
  1726. // ```proto
  1727. // message MySInt32 {
  1728. // // value must be greater than 5 [sint32.gt]
  1729. // sint32 value = 1 [(buf.validate.field).sint32.gt = 5];
  1730. //
  1731. // // value must be greater than 5 and less than 10 [sint32.gt_lt]
  1732. // sint32 other_value = 2 [(buf.validate.field).sint32 = { gt: 5, lt: 10 }];
  1733. //
  1734. // // value must be greater than 10 or less than 5 [sint32.gt_lt_exclusive]
  1735. // sint32 another_value = 3 [(buf.validate.field).sint32 = { gt: 10, lt: 5 }];
  1736. // }
  1737. // ```
  1738. sint32 gt = 4 [
  1739. (predefined).cel = {
  1740. id: "sint32.gt"
  1741. expression:
  1742. "!has(rules.lt) && !has(rules.lte) && this <= rules.gt"
  1743. "? 'value must be greater than %s'.format([rules.gt]) : ''"
  1744. },
  1745. (predefined).cel = {
  1746. id: "sint32.gt_lt"
  1747. expression:
  1748. "has(rules.lt) && rules.lt >= rules.gt && (this >= rules.lt || this <= rules.gt)"
  1749. "? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
  1750. },
  1751. (predefined).cel = {
  1752. id: "sint32.gt_lt_exclusive"
  1753. expression:
  1754. "has(rules.lt) && rules.lt < rules.gt && (rules.lt <= this && this <= rules.gt)"
  1755. "? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
  1756. },
  1757. (predefined).cel = {
  1758. id: "sint32.gt_lte"
  1759. expression:
  1760. "has(rules.lte) && rules.lte >= rules.gt && (this > rules.lte || this <= rules.gt)"
  1761. "? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  1762. },
  1763. (predefined).cel = {
  1764. id: "sint32.gt_lte_exclusive"
  1765. expression:
  1766. "has(rules.lte) && rules.lte < rules.gt && (rules.lte < this && this <= rules.gt)"
  1767. "? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  1768. }
  1769. ];
  1770. // `gte` requires the field value to be greater than or equal to the specified
  1771. // value (exclusive). If the value of `gte` is larger than a specified `lt`
  1772. // or `lte`, the range is reversed, and the field value must be outside the
  1773. // specified range. If the field value doesn't meet the required conditions,
  1774. // an error message is generated.
  1775. //
  1776. // ```proto
  1777. // message MySInt32 {
  1778. // // value must be greater than or equal to 5 [sint32.gte]
  1779. // sint32 value = 1 [(buf.validate.field).sint32.gte = 5];
  1780. //
  1781. // // value must be greater than or equal to 5 and less than 10 [sint32.gte_lt]
  1782. // sint32 other_value = 2 [(buf.validate.field).sint32 = { gte: 5, lt: 10 }];
  1783. //
  1784. // // value must be greater than or equal to 10 or less than 5 [sint32.gte_lt_exclusive]
  1785. // sint32 another_value = 3 [(buf.validate.field).sint32 = { gte: 10, lt: 5 }];
  1786. // }
  1787. // ```
  1788. sint32 gte = 5 [
  1789. (predefined).cel = {
  1790. id: "sint32.gte"
  1791. expression:
  1792. "!has(rules.lt) && !has(rules.lte) && this < rules.gte"
  1793. "? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
  1794. },
  1795. (predefined).cel = {
  1796. id: "sint32.gte_lt"
  1797. expression:
  1798. "has(rules.lt) && rules.lt >= rules.gte && (this >= rules.lt || this < rules.gte)"
  1799. "? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
  1800. },
  1801. (predefined).cel = {
  1802. id: "sint32.gte_lt_exclusive"
  1803. expression:
  1804. "has(rules.lt) && rules.lt < rules.gte && (rules.lt <= this && this < rules.gte)"
  1805. "? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
  1806. },
  1807. (predefined).cel = {
  1808. id: "sint32.gte_lte"
  1809. expression:
  1810. "has(rules.lte) && rules.lte >= rules.gte && (this > rules.lte || this < rules.gte)"
  1811. "? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  1812. },
  1813. (predefined).cel = {
  1814. id: "sint32.gte_lte_exclusive"
  1815. expression:
  1816. "has(rules.lte) && rules.lte < rules.gte && (rules.lte < this && this < rules.gte)"
  1817. "? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  1818. }
  1819. ];
  1820. }
  1821. // `in` requires the field value to be equal to one of the specified values.
  1822. // If the field value isn't one of the specified values, an error message is
  1823. // generated.
  1824. //
  1825. // ```proto
  1826. // message MySInt32 {
  1827. // // value must be in list [1, 2, 3]
  1828. // sint32 value = 1 [(buf.validate.field).sint32 = { in: [1, 2, 3] }];
  1829. // }
  1830. // ```
  1831. repeated sint32 in = 6 [(predefined).cel = {
  1832. id: "sint32.in"
  1833. expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
  1834. }];
  1835. // `not_in` requires the field value to not be equal to any of the specified
  1836. // values. If the field value is one of the specified values, an error
  1837. // message is generated.
  1838. //
  1839. // ```proto
  1840. // message MySInt32 {
  1841. // // value must not be in list [1, 2, 3]
  1842. // sint32 value = 1 [(buf.validate.field).sint32 = { not_in: [1, 2, 3] }];
  1843. // }
  1844. // ```
  1845. repeated sint32 not_in = 7 [(predefined).cel = {
  1846. id: "sint32.not_in"
  1847. expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''"
  1848. }];
  1849. // `example` specifies values that the field may have. These values SHOULD
  1850. // conform to other rules. `example` values will not impact validation
  1851. // but may be used as helpful guidance on how to populate the given field.
  1852. //
  1853. // ```proto
  1854. // message MySInt32 {
  1855. // sint32 value = 1 [
  1856. // (buf.validate.field).sint32.example = 1,
  1857. // (buf.validate.field).sint32.example = -10
  1858. // ];
  1859. // }
  1860. // ```
  1861. repeated sint32 example = 8 [(predefined).cel = {
  1862. id: "sint32.example"
  1863. expression: "true"
  1864. }];
  1865. // Extension fields in this range that have the (buf.validate.predefined)
  1866. // option set will be treated as predefined field rules that can then be
  1867. // set on the field options of other fields to apply field rules.
  1868. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  1869. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  1870. // above this range are reserved for extension numbers that are not explicitly
  1871. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  1872. // above 99999 is discouraged due to the risk of conflicts.
  1873. //
  1874. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  1875. extensions 1000 to max;
  1876. }
  1877. // SInt64Rules describes the rules applied to `sint64` values.
  1878. message SInt64Rules {
  1879. // `const` requires the field value to exactly match the specified value. If
  1880. // the field value doesn't match, an error message is generated.
  1881. //
  1882. // ```proto
  1883. // message MySInt64 {
  1884. // // value must equal 42
  1885. // sint64 value = 1 [(buf.validate.field).sint64.const = 42];
  1886. // }
  1887. // ```
  1888. optional sint64 const = 1 [(predefined).cel = {
  1889. id: "sint64.const"
  1890. expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
  1891. }];
  1892. oneof less_than {
  1893. // `lt` requires the field value to be less than the specified value (field
  1894. // < value). If the field value is equal to or greater than the specified
  1895. // value, an error message is generated.
  1896. //
  1897. // ```proto
  1898. // message MySInt64 {
  1899. // // value must be less than 10
  1900. // sint64 value = 1 [(buf.validate.field).sint64.lt = 10];
  1901. // }
  1902. // ```
  1903. sint64 lt = 2 [(predefined).cel = {
  1904. id: "sint64.lt"
  1905. expression:
  1906. "!has(rules.gte) && !has(rules.gt) && this >= rules.lt"
  1907. "? 'value must be less than %s'.format([rules.lt]) : ''"
  1908. }];
  1909. // `lte` requires the field value to be less than or equal to the specified
  1910. // value (field <= value). If the field value is greater than the specified
  1911. // value, an error message is generated.
  1912. //
  1913. // ```proto
  1914. // message MySInt64 {
  1915. // // value must be less than or equal to 10
  1916. // sint64 value = 1 [(buf.validate.field).sint64.lte = 10];
  1917. // }
  1918. // ```
  1919. sint64 lte = 3 [(predefined).cel = {
  1920. id: "sint64.lte"
  1921. expression:
  1922. "!has(rules.gte) && !has(rules.gt) && this > rules.lte"
  1923. "? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
  1924. }];
  1925. }
  1926. oneof greater_than {
  1927. // `gt` requires the field value to be greater than the specified value
  1928. // (exclusive). If the value of `gt` is larger than a specified `lt` or
  1929. // `lte`, the range is reversed, and the field value must be outside the
  1930. // specified range. If the field value doesn't meet the required conditions,
  1931. // an error message is generated.
  1932. //
  1933. // ```proto
  1934. // message MySInt64 {
  1935. // // value must be greater than 5 [sint64.gt]
  1936. // sint64 value = 1 [(buf.validate.field).sint64.gt = 5];
  1937. //
  1938. // // value must be greater than 5 and less than 10 [sint64.gt_lt]
  1939. // sint64 other_value = 2 [(buf.validate.field).sint64 = { gt: 5, lt: 10 }];
  1940. //
  1941. // // value must be greater than 10 or less than 5 [sint64.gt_lt_exclusive]
  1942. // sint64 another_value = 3 [(buf.validate.field).sint64 = { gt: 10, lt: 5 }];
  1943. // }
  1944. // ```
  1945. sint64 gt = 4 [
  1946. (predefined).cel = {
  1947. id: "sint64.gt"
  1948. expression:
  1949. "!has(rules.lt) && !has(rules.lte) && this <= rules.gt"
  1950. "? 'value must be greater than %s'.format([rules.gt]) : ''"
  1951. },
  1952. (predefined).cel = {
  1953. id: "sint64.gt_lt"
  1954. expression:
  1955. "has(rules.lt) && rules.lt >= rules.gt && (this >= rules.lt || this <= rules.gt)"
  1956. "? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
  1957. },
  1958. (predefined).cel = {
  1959. id: "sint64.gt_lt_exclusive"
  1960. expression:
  1961. "has(rules.lt) && rules.lt < rules.gt && (rules.lt <= this && this <= rules.gt)"
  1962. "? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
  1963. },
  1964. (predefined).cel = {
  1965. id: "sint64.gt_lte"
  1966. expression:
  1967. "has(rules.lte) && rules.lte >= rules.gt && (this > rules.lte || this <= rules.gt)"
  1968. "? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  1969. },
  1970. (predefined).cel = {
  1971. id: "sint64.gt_lte_exclusive"
  1972. expression:
  1973. "has(rules.lte) && rules.lte < rules.gt && (rules.lte < this && this <= rules.gt)"
  1974. "? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  1975. }
  1976. ];
  1977. // `gte` requires the field value to be greater than or equal to the specified
  1978. // value (exclusive). If the value of `gte` is larger than a specified `lt`
  1979. // or `lte`, the range is reversed, and the field value must be outside the
  1980. // specified range. If the field value doesn't meet the required conditions,
  1981. // an error message is generated.
  1982. //
  1983. // ```proto
  1984. // message MySInt64 {
  1985. // // value must be greater than or equal to 5 [sint64.gte]
  1986. // sint64 value = 1 [(buf.validate.field).sint64.gte = 5];
  1987. //
  1988. // // value must be greater than or equal to 5 and less than 10 [sint64.gte_lt]
  1989. // sint64 other_value = 2 [(buf.validate.field).sint64 = { gte: 5, lt: 10 }];
  1990. //
  1991. // // value must be greater than or equal to 10 or less than 5 [sint64.gte_lt_exclusive]
  1992. // sint64 another_value = 3 [(buf.validate.field).sint64 = { gte: 10, lt: 5 }];
  1993. // }
  1994. // ```
  1995. sint64 gte = 5 [
  1996. (predefined).cel = {
  1997. id: "sint64.gte"
  1998. expression:
  1999. "!has(rules.lt) && !has(rules.lte) && this < rules.gte"
  2000. "? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
  2001. },
  2002. (predefined).cel = {
  2003. id: "sint64.gte_lt"
  2004. expression:
  2005. "has(rules.lt) && rules.lt >= rules.gte && (this >= rules.lt || this < rules.gte)"
  2006. "? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
  2007. },
  2008. (predefined).cel = {
  2009. id: "sint64.gte_lt_exclusive"
  2010. expression:
  2011. "has(rules.lt) && rules.lt < rules.gte && (rules.lt <= this && this < rules.gte)"
  2012. "? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
  2013. },
  2014. (predefined).cel = {
  2015. id: "sint64.gte_lte"
  2016. expression:
  2017. "has(rules.lte) && rules.lte >= rules.gte && (this > rules.lte || this < rules.gte)"
  2018. "? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  2019. },
  2020. (predefined).cel = {
  2021. id: "sint64.gte_lte_exclusive"
  2022. expression:
  2023. "has(rules.lte) && rules.lte < rules.gte && (rules.lte < this && this < rules.gte)"
  2024. "? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  2025. }
  2026. ];
  2027. }
  2028. // `in` requires the field value to be equal to one of the specified values.
  2029. // If the field value isn't one of the specified values, an error message
  2030. // is generated.
  2031. //
  2032. // ```proto
  2033. // message MySInt64 {
  2034. // // value must be in list [1, 2, 3]
  2035. // sint64 value = 1 [(buf.validate.field).sint64 = { in: [1, 2, 3] }];
  2036. // }
  2037. // ```
  2038. repeated sint64 in = 6 [(predefined).cel = {
  2039. id: "sint64.in"
  2040. expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
  2041. }];
  2042. // `not_in` requires the field value to not be equal to any of the specified
  2043. // values. If the field value is one of the specified values, an error
  2044. // message is generated.
  2045. //
  2046. // ```proto
  2047. // message MySInt64 {
  2048. // // value must not be in list [1, 2, 3]
  2049. // sint64 value = 1 [(buf.validate.field).sint64 = { not_in: [1, 2, 3] }];
  2050. // }
  2051. // ```
  2052. repeated sint64 not_in = 7 [(predefined).cel = {
  2053. id: "sint64.not_in"
  2054. expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''"
  2055. }];
  2056. // `example` specifies values that the field may have. These values SHOULD
  2057. // conform to other rules. `example` values will not impact validation
  2058. // but may be used as helpful guidance on how to populate the given field.
  2059. //
  2060. // ```proto
  2061. // message MySInt64 {
  2062. // sint64 value = 1 [
  2063. // (buf.validate.field).sint64.example = 1,
  2064. // (buf.validate.field).sint64.example = -10
  2065. // ];
  2066. // }
  2067. // ```
  2068. repeated sint64 example = 8 [(predefined).cel = {
  2069. id: "sint64.example"
  2070. expression: "true"
  2071. }];
  2072. // Extension fields in this range that have the (buf.validate.predefined)
  2073. // option set will be treated as predefined field rules that can then be
  2074. // set on the field options of other fields to apply field rules.
  2075. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  2076. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  2077. // above this range are reserved for extension numbers that are not explicitly
  2078. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  2079. // above 99999 is discouraged due to the risk of conflicts.
  2080. //
  2081. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  2082. extensions 1000 to max;
  2083. }
  2084. // Fixed32Rules describes the rules applied to `fixed32` values.
  2085. message Fixed32Rules {
  2086. // `const` requires the field value to exactly match the specified value.
  2087. // If the field value doesn't match, an error message is generated.
  2088. //
  2089. // ```proto
  2090. // message MyFixed32 {
  2091. // // value must equal 42
  2092. // fixed32 value = 1 [(buf.validate.field).fixed32.const = 42];
  2093. // }
  2094. // ```
  2095. optional fixed32 const = 1 [(predefined).cel = {
  2096. id: "fixed32.const"
  2097. expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
  2098. }];
  2099. oneof less_than {
  2100. // `lt` requires the field value to be less than the specified value (field <
  2101. // value). If the field value is equal to or greater than the specified value,
  2102. // an error message is generated.
  2103. //
  2104. // ```proto
  2105. // message MyFixed32 {
  2106. // // value must be less than 10
  2107. // fixed32 value = 1 [(buf.validate.field).fixed32.lt = 10];
  2108. // }
  2109. // ```
  2110. fixed32 lt = 2 [(predefined).cel = {
  2111. id: "fixed32.lt"
  2112. expression:
  2113. "!has(rules.gte) && !has(rules.gt) && this >= rules.lt"
  2114. "? 'value must be less than %s'.format([rules.lt]) : ''"
  2115. }];
  2116. // `lte` requires the field value to be less than or equal to the specified
  2117. // value (field <= value). If the field value is greater than the specified
  2118. // value, an error message is generated.
  2119. //
  2120. // ```proto
  2121. // message MyFixed32 {
  2122. // // value must be less than or equal to 10
  2123. // fixed32 value = 1 [(buf.validate.field).fixed32.lte = 10];
  2124. // }
  2125. // ```
  2126. fixed32 lte = 3 [(predefined).cel = {
  2127. id: "fixed32.lte"
  2128. expression:
  2129. "!has(rules.gte) && !has(rules.gt) && this > rules.lte"
  2130. "? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
  2131. }];
  2132. }
  2133. oneof greater_than {
  2134. // `gt` requires the field value to be greater than the specified value
  2135. // (exclusive). If the value of `gt` is larger than a specified `lt` or
  2136. // `lte`, the range is reversed, and the field value must be outside the
  2137. // specified range. If the field value doesn't meet the required conditions,
  2138. // an error message is generated.
  2139. //
  2140. // ```proto
  2141. // message MyFixed32 {
  2142. // // value must be greater than 5 [fixed32.gt]
  2143. // fixed32 value = 1 [(buf.validate.field).fixed32.gt = 5];
  2144. //
  2145. // // value must be greater than 5 and less than 10 [fixed32.gt_lt]
  2146. // fixed32 other_value = 2 [(buf.validate.field).fixed32 = { gt: 5, lt: 10 }];
  2147. //
  2148. // // value must be greater than 10 or less than 5 [fixed32.gt_lt_exclusive]
  2149. // fixed32 another_value = 3 [(buf.validate.field).fixed32 = { gt: 10, lt: 5 }];
  2150. // }
  2151. // ```
  2152. fixed32 gt = 4 [
  2153. (predefined).cel = {
  2154. id: "fixed32.gt"
  2155. expression:
  2156. "!has(rules.lt) && !has(rules.lte) && this <= rules.gt"
  2157. "? 'value must be greater than %s'.format([rules.gt]) : ''"
  2158. },
  2159. (predefined).cel = {
  2160. id: "fixed32.gt_lt"
  2161. expression:
  2162. "has(rules.lt) && rules.lt >= rules.gt && (this >= rules.lt || this <= rules.gt)"
  2163. "? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
  2164. },
  2165. (predefined).cel = {
  2166. id: "fixed32.gt_lt_exclusive"
  2167. expression:
  2168. "has(rules.lt) && rules.lt < rules.gt && (rules.lt <= this && this <= rules.gt)"
  2169. "? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
  2170. },
  2171. (predefined).cel = {
  2172. id: "fixed32.gt_lte"
  2173. expression:
  2174. "has(rules.lte) && rules.lte >= rules.gt && (this > rules.lte || this <= rules.gt)"
  2175. "? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  2176. },
  2177. (predefined).cel = {
  2178. id: "fixed32.gt_lte_exclusive"
  2179. expression:
  2180. "has(rules.lte) && rules.lte < rules.gt && (rules.lte < this && this <= rules.gt)"
  2181. "? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  2182. }
  2183. ];
  2184. // `gte` requires the field value to be greater than or equal to the specified
  2185. // value (exclusive). If the value of `gte` is larger than a specified `lt`
  2186. // or `lte`, the range is reversed, and the field value must be outside the
  2187. // specified range. If the field value doesn't meet the required conditions,
  2188. // an error message is generated.
  2189. //
  2190. // ```proto
  2191. // message MyFixed32 {
  2192. // // value must be greater than or equal to 5 [fixed32.gte]
  2193. // fixed32 value = 1 [(buf.validate.field).fixed32.gte = 5];
  2194. //
  2195. // // value must be greater than or equal to 5 and less than 10 [fixed32.gte_lt]
  2196. // fixed32 other_value = 2 [(buf.validate.field).fixed32 = { gte: 5, lt: 10 }];
  2197. //
  2198. // // value must be greater than or equal to 10 or less than 5 [fixed32.gte_lt_exclusive]
  2199. // fixed32 another_value = 3 [(buf.validate.field).fixed32 = { gte: 10, lt: 5 }];
  2200. // }
  2201. // ```
  2202. fixed32 gte = 5 [
  2203. (predefined).cel = {
  2204. id: "fixed32.gte"
  2205. expression:
  2206. "!has(rules.lt) && !has(rules.lte) && this < rules.gte"
  2207. "? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
  2208. },
  2209. (predefined).cel = {
  2210. id: "fixed32.gte_lt"
  2211. expression:
  2212. "has(rules.lt) && rules.lt >= rules.gte && (this >= rules.lt || this < rules.gte)"
  2213. "? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
  2214. },
  2215. (predefined).cel = {
  2216. id: "fixed32.gte_lt_exclusive"
  2217. expression:
  2218. "has(rules.lt) && rules.lt < rules.gte && (rules.lt <= this && this < rules.gte)"
  2219. "? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
  2220. },
  2221. (predefined).cel = {
  2222. id: "fixed32.gte_lte"
  2223. expression:
  2224. "has(rules.lte) && rules.lte >= rules.gte && (this > rules.lte || this < rules.gte)"
  2225. "? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  2226. },
  2227. (predefined).cel = {
  2228. id: "fixed32.gte_lte_exclusive"
  2229. expression:
  2230. "has(rules.lte) && rules.lte < rules.gte && (rules.lte < this && this < rules.gte)"
  2231. "? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  2232. }
  2233. ];
  2234. }
  2235. // `in` requires the field value to be equal to one of the specified values.
  2236. // If the field value isn't one of the specified values, an error message
  2237. // is generated.
  2238. //
  2239. // ```proto
  2240. // message MyFixed32 {
  2241. // // value must be in list [1, 2, 3]
  2242. // fixed32 value = 1 [(buf.validate.field).fixed32 = { in: [1, 2, 3] }];
  2243. // }
  2244. // ```
  2245. repeated fixed32 in = 6 [(predefined).cel = {
  2246. id: "fixed32.in"
  2247. expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
  2248. }];
  2249. // `not_in` requires the field value to not be equal to any of the specified
  2250. // values. If the field value is one of the specified values, an error
  2251. // message is generated.
  2252. //
  2253. // ```proto
  2254. // message MyFixed32 {
  2255. // // value must not be in list [1, 2, 3]
  2256. // fixed32 value = 1 [(buf.validate.field).fixed32 = { not_in: [1, 2, 3] }];
  2257. // }
  2258. // ```
  2259. repeated fixed32 not_in = 7 [(predefined).cel = {
  2260. id: "fixed32.not_in"
  2261. expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''"
  2262. }];
  2263. // `example` specifies values that the field may have. These values SHOULD
  2264. // conform to other rules. `example` values will not impact validation
  2265. // but may be used as helpful guidance on how to populate the given field.
  2266. //
  2267. // ```proto
  2268. // message MyFixed32 {
  2269. // fixed32 value = 1 [
  2270. // (buf.validate.field).fixed32.example = 1,
  2271. // (buf.validate.field).fixed32.example = 2
  2272. // ];
  2273. // }
  2274. // ```
  2275. repeated fixed32 example = 8 [(predefined).cel = {
  2276. id: "fixed32.example"
  2277. expression: "true"
  2278. }];
  2279. // Extension fields in this range that have the (buf.validate.predefined)
  2280. // option set will be treated as predefined field rules that can then be
  2281. // set on the field options of other fields to apply field rules.
  2282. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  2283. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  2284. // above this range are reserved for extension numbers that are not explicitly
  2285. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  2286. // above 99999 is discouraged due to the risk of conflicts.
  2287. //
  2288. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  2289. extensions 1000 to max;
  2290. }
  2291. // Fixed64Rules describes the rules applied to `fixed64` values.
  2292. message Fixed64Rules {
  2293. // `const` requires the field value to exactly match the specified value. If
  2294. // the field value doesn't match, an error message is generated.
  2295. //
  2296. // ```proto
  2297. // message MyFixed64 {
  2298. // // value must equal 42
  2299. // fixed64 value = 1 [(buf.validate.field).fixed64.const = 42];
  2300. // }
  2301. // ```
  2302. optional fixed64 const = 1 [(predefined).cel = {
  2303. id: "fixed64.const"
  2304. expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
  2305. }];
  2306. oneof less_than {
  2307. // `lt` requires the field value to be less than the specified value (field <
  2308. // value). If the field value is equal to or greater than the specified value,
  2309. // an error message is generated.
  2310. //
  2311. // ```proto
  2312. // message MyFixed64 {
  2313. // // value must be less than 10
  2314. // fixed64 value = 1 [(buf.validate.field).fixed64.lt = 10];
  2315. // }
  2316. // ```
  2317. fixed64 lt = 2 [(predefined).cel = {
  2318. id: "fixed64.lt"
  2319. expression:
  2320. "!has(rules.gte) && !has(rules.gt) && this >= rules.lt"
  2321. "? 'value must be less than %s'.format([rules.lt]) : ''"
  2322. }];
  2323. // `lte` requires the field value to be less than or equal to the specified
  2324. // value (field <= value). If the field value is greater than the specified
  2325. // value, an error message is generated.
  2326. //
  2327. // ```proto
  2328. // message MyFixed64 {
  2329. // // value must be less than or equal to 10
  2330. // fixed64 value = 1 [(buf.validate.field).fixed64.lte = 10];
  2331. // }
  2332. // ```
  2333. fixed64 lte = 3 [(predefined).cel = {
  2334. id: "fixed64.lte"
  2335. expression:
  2336. "!has(rules.gte) && !has(rules.gt) && this > rules.lte"
  2337. "? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
  2338. }];
  2339. }
  2340. oneof greater_than {
  2341. // `gt` requires the field value to be greater than the specified value
  2342. // (exclusive). If the value of `gt` is larger than a specified `lt` or
  2343. // `lte`, the range is reversed, and the field value must be outside the
  2344. // specified range. If the field value doesn't meet the required conditions,
  2345. // an error message is generated.
  2346. //
  2347. // ```proto
  2348. // message MyFixed64 {
  2349. // // value must be greater than 5 [fixed64.gt]
  2350. // fixed64 value = 1 [(buf.validate.field).fixed64.gt = 5];
  2351. //
  2352. // // value must be greater than 5 and less than 10 [fixed64.gt_lt]
  2353. // fixed64 other_value = 2 [(buf.validate.field).fixed64 = { gt: 5, lt: 10 }];
  2354. //
  2355. // // value must be greater than 10 or less than 5 [fixed64.gt_lt_exclusive]
  2356. // fixed64 another_value = 3 [(buf.validate.field).fixed64 = { gt: 10, lt: 5 }];
  2357. // }
  2358. // ```
  2359. fixed64 gt = 4 [
  2360. (predefined).cel = {
  2361. id: "fixed64.gt"
  2362. expression:
  2363. "!has(rules.lt) && !has(rules.lte) && this <= rules.gt"
  2364. "? 'value must be greater than %s'.format([rules.gt]) : ''"
  2365. },
  2366. (predefined).cel = {
  2367. id: "fixed64.gt_lt"
  2368. expression:
  2369. "has(rules.lt) && rules.lt >= rules.gt && (this >= rules.lt || this <= rules.gt)"
  2370. "? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
  2371. },
  2372. (predefined).cel = {
  2373. id: "fixed64.gt_lt_exclusive"
  2374. expression:
  2375. "has(rules.lt) && rules.lt < rules.gt && (rules.lt <= this && this <= rules.gt)"
  2376. "? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
  2377. },
  2378. (predefined).cel = {
  2379. id: "fixed64.gt_lte"
  2380. expression:
  2381. "has(rules.lte) && rules.lte >= rules.gt && (this > rules.lte || this <= rules.gt)"
  2382. "? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  2383. },
  2384. (predefined).cel = {
  2385. id: "fixed64.gt_lte_exclusive"
  2386. expression:
  2387. "has(rules.lte) && rules.lte < rules.gt && (rules.lte < this && this <= rules.gt)"
  2388. "? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  2389. }
  2390. ];
  2391. // `gte` requires the field value to be greater than or equal to the specified
  2392. // value (exclusive). If the value of `gte` is larger than a specified `lt`
  2393. // or `lte`, the range is reversed, and the field value must be outside the
  2394. // specified range. If the field value doesn't meet the required conditions,
  2395. // an error message is generated.
  2396. //
  2397. // ```proto
  2398. // message MyFixed64 {
  2399. // // value must be greater than or equal to 5 [fixed64.gte]
  2400. // fixed64 value = 1 [(buf.validate.field).fixed64.gte = 5];
  2401. //
  2402. // // value must be greater than or equal to 5 and less than 10 [fixed64.gte_lt]
  2403. // fixed64 other_value = 2 [(buf.validate.field).fixed64 = { gte: 5, lt: 10 }];
  2404. //
  2405. // // value must be greater than or equal to 10 or less than 5 [fixed64.gte_lt_exclusive]
  2406. // fixed64 another_value = 3 [(buf.validate.field).fixed64 = { gte: 10, lt: 5 }];
  2407. // }
  2408. // ```
  2409. fixed64 gte = 5 [
  2410. (predefined).cel = {
  2411. id: "fixed64.gte"
  2412. expression:
  2413. "!has(rules.lt) && !has(rules.lte) && this < rules.gte"
  2414. "? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
  2415. },
  2416. (predefined).cel = {
  2417. id: "fixed64.gte_lt"
  2418. expression:
  2419. "has(rules.lt) && rules.lt >= rules.gte && (this >= rules.lt || this < rules.gte)"
  2420. "? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
  2421. },
  2422. (predefined).cel = {
  2423. id: "fixed64.gte_lt_exclusive"
  2424. expression:
  2425. "has(rules.lt) && rules.lt < rules.gte && (rules.lt <= this && this < rules.gte)"
  2426. "? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
  2427. },
  2428. (predefined).cel = {
  2429. id: "fixed64.gte_lte"
  2430. expression:
  2431. "has(rules.lte) && rules.lte >= rules.gte && (this > rules.lte || this < rules.gte)"
  2432. "? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  2433. },
  2434. (predefined).cel = {
  2435. id: "fixed64.gte_lte_exclusive"
  2436. expression:
  2437. "has(rules.lte) && rules.lte < rules.gte && (rules.lte < this && this < rules.gte)"
  2438. "? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  2439. }
  2440. ];
  2441. }
  2442. // `in` requires the field value to be equal to one of the specified values.
  2443. // If the field value isn't one of the specified values, an error message is
  2444. // generated.
  2445. //
  2446. // ```proto
  2447. // message MyFixed64 {
  2448. // // value must be in list [1, 2, 3]
  2449. // fixed64 value = 1 [(buf.validate.field).fixed64 = { in: [1, 2, 3] }];
  2450. // }
  2451. // ```
  2452. repeated fixed64 in = 6 [(predefined).cel = {
  2453. id: "fixed64.in"
  2454. expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
  2455. }];
  2456. // `not_in` requires the field value to not be equal to any of the specified
  2457. // values. If the field value is one of the specified values, an error
  2458. // message is generated.
  2459. //
  2460. // ```proto
  2461. // message MyFixed64 {
  2462. // // value must not be in list [1, 2, 3]
  2463. // fixed64 value = 1 [(buf.validate.field).fixed64 = { not_in: [1, 2, 3] }];
  2464. // }
  2465. // ```
  2466. repeated fixed64 not_in = 7 [(predefined).cel = {
  2467. id: "fixed64.not_in"
  2468. expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''"
  2469. }];
  2470. // `example` specifies values that the field may have. These values SHOULD
  2471. // conform to other rules. `example` values will not impact validation
  2472. // but may be used as helpful guidance on how to populate the given field.
  2473. //
  2474. // ```proto
  2475. // message MyFixed64 {
  2476. // fixed64 value = 1 [
  2477. // (buf.validate.field).fixed64.example = 1,
  2478. // (buf.validate.field).fixed64.example = 2
  2479. // ];
  2480. // }
  2481. // ```
  2482. repeated fixed64 example = 8 [(predefined).cel = {
  2483. id: "fixed64.example"
  2484. expression: "true"
  2485. }];
  2486. // Extension fields in this range that have the (buf.validate.predefined)
  2487. // option set will be treated as predefined field rules that can then be
  2488. // set on the field options of other fields to apply field rules.
  2489. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  2490. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  2491. // above this range are reserved for extension numbers that are not explicitly
  2492. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  2493. // above 99999 is discouraged due to the risk of conflicts.
  2494. //
  2495. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  2496. extensions 1000 to max;
  2497. }
  2498. // SFixed32Rules describes the rules applied to `fixed32` values.
  2499. message SFixed32Rules {
  2500. // `const` requires the field value to exactly match the specified value. If
  2501. // the field value doesn't match, an error message is generated.
  2502. //
  2503. // ```proto
  2504. // message MySFixed32 {
  2505. // // value must equal 42
  2506. // sfixed32 value = 1 [(buf.validate.field).sfixed32.const = 42];
  2507. // }
  2508. // ```
  2509. optional sfixed32 const = 1 [(predefined).cel = {
  2510. id: "sfixed32.const"
  2511. expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
  2512. }];
  2513. oneof less_than {
  2514. // `lt` requires the field value to be less than the specified value (field <
  2515. // value). If the field value is equal to or greater than the specified value,
  2516. // an error message is generated.
  2517. //
  2518. // ```proto
  2519. // message MySFixed32 {
  2520. // // value must be less than 10
  2521. // sfixed32 value = 1 [(buf.validate.field).sfixed32.lt = 10];
  2522. // }
  2523. // ```
  2524. sfixed32 lt = 2 [(predefined).cel = {
  2525. id: "sfixed32.lt"
  2526. expression:
  2527. "!has(rules.gte) && !has(rules.gt) && this >= rules.lt"
  2528. "? 'value must be less than %s'.format([rules.lt]) : ''"
  2529. }];
  2530. // `lte` requires the field value to be less than or equal to the specified
  2531. // value (field <= value). If the field value is greater than the specified
  2532. // value, an error message is generated.
  2533. //
  2534. // ```proto
  2535. // message MySFixed32 {
  2536. // // value must be less than or equal to 10
  2537. // sfixed32 value = 1 [(buf.validate.field).sfixed32.lte = 10];
  2538. // }
  2539. // ```
  2540. sfixed32 lte = 3 [(predefined).cel = {
  2541. id: "sfixed32.lte"
  2542. expression:
  2543. "!has(rules.gte) && !has(rules.gt) && this > rules.lte"
  2544. "? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
  2545. }];
  2546. }
  2547. oneof greater_than {
  2548. // `gt` requires the field value to be greater than the specified value
  2549. // (exclusive). If the value of `gt` is larger than a specified `lt` or
  2550. // `lte`, the range is reversed, and the field value must be outside the
  2551. // specified range. If the field value doesn't meet the required conditions,
  2552. // an error message is generated.
  2553. //
  2554. // ```proto
  2555. // message MySFixed32 {
  2556. // // value must be greater than 5 [sfixed32.gt]
  2557. // sfixed32 value = 1 [(buf.validate.field).sfixed32.gt = 5];
  2558. //
  2559. // // value must be greater than 5 and less than 10 [sfixed32.gt_lt]
  2560. // sfixed32 other_value = 2 [(buf.validate.field).sfixed32 = { gt: 5, lt: 10 }];
  2561. //
  2562. // // value must be greater than 10 or less than 5 [sfixed32.gt_lt_exclusive]
  2563. // sfixed32 another_value = 3 [(buf.validate.field).sfixed32 = { gt: 10, lt: 5 }];
  2564. // }
  2565. // ```
  2566. sfixed32 gt = 4 [
  2567. (predefined).cel = {
  2568. id: "sfixed32.gt"
  2569. expression:
  2570. "!has(rules.lt) && !has(rules.lte) && this <= rules.gt"
  2571. "? 'value must be greater than %s'.format([rules.gt]) : ''"
  2572. },
  2573. (predefined).cel = {
  2574. id: "sfixed32.gt_lt"
  2575. expression:
  2576. "has(rules.lt) && rules.lt >= rules.gt && (this >= rules.lt || this <= rules.gt)"
  2577. "? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
  2578. },
  2579. (predefined).cel = {
  2580. id: "sfixed32.gt_lt_exclusive"
  2581. expression:
  2582. "has(rules.lt) && rules.lt < rules.gt && (rules.lt <= this && this <= rules.gt)"
  2583. "? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
  2584. },
  2585. (predefined).cel = {
  2586. id: "sfixed32.gt_lte"
  2587. expression:
  2588. "has(rules.lte) && rules.lte >= rules.gt && (this > rules.lte || this <= rules.gt)"
  2589. "? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  2590. },
  2591. (predefined).cel = {
  2592. id: "sfixed32.gt_lte_exclusive"
  2593. expression:
  2594. "has(rules.lte) && rules.lte < rules.gt && (rules.lte < this && this <= rules.gt)"
  2595. "? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  2596. }
  2597. ];
  2598. // `gte` requires the field value to be greater than or equal to the specified
  2599. // value (exclusive). If the value of `gte` is larger than a specified `lt`
  2600. // or `lte`, the range is reversed, and the field value must be outside the
  2601. // specified range. If the field value doesn't meet the required conditions,
  2602. // an error message is generated.
  2603. //
  2604. // ```proto
  2605. // message MySFixed32 {
  2606. // // value must be greater than or equal to 5 [sfixed32.gte]
  2607. // sfixed32 value = 1 [(buf.validate.field).sfixed32.gte = 5];
  2608. //
  2609. // // value must be greater than or equal to 5 and less than 10 [sfixed32.gte_lt]
  2610. // sfixed32 other_value = 2 [(buf.validate.field).sfixed32 = { gte: 5, lt: 10 }];
  2611. //
  2612. // // value must be greater than or equal to 10 or less than 5 [sfixed32.gte_lt_exclusive]
  2613. // sfixed32 another_value = 3 [(buf.validate.field).sfixed32 = { gte: 10, lt: 5 }];
  2614. // }
  2615. // ```
  2616. sfixed32 gte = 5 [
  2617. (predefined).cel = {
  2618. id: "sfixed32.gte"
  2619. expression:
  2620. "!has(rules.lt) && !has(rules.lte) && this < rules.gte"
  2621. "? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
  2622. },
  2623. (predefined).cel = {
  2624. id: "sfixed32.gte_lt"
  2625. expression:
  2626. "has(rules.lt) && rules.lt >= rules.gte && (this >= rules.lt || this < rules.gte)"
  2627. "? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
  2628. },
  2629. (predefined).cel = {
  2630. id: "sfixed32.gte_lt_exclusive"
  2631. expression:
  2632. "has(rules.lt) && rules.lt < rules.gte && (rules.lt <= this && this < rules.gte)"
  2633. "? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
  2634. },
  2635. (predefined).cel = {
  2636. id: "sfixed32.gte_lte"
  2637. expression:
  2638. "has(rules.lte) && rules.lte >= rules.gte && (this > rules.lte || this < rules.gte)"
  2639. "? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  2640. },
  2641. (predefined).cel = {
  2642. id: "sfixed32.gte_lte_exclusive"
  2643. expression:
  2644. "has(rules.lte) && rules.lte < rules.gte && (rules.lte < this && this < rules.gte)"
  2645. "? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  2646. }
  2647. ];
  2648. }
  2649. // `in` requires the field value to be equal to one of the specified values.
  2650. // If the field value isn't one of the specified values, an error message is
  2651. // generated.
  2652. //
  2653. // ```proto
  2654. // message MySFixed32 {
  2655. // // value must be in list [1, 2, 3]
  2656. // sfixed32 value = 1 [(buf.validate.field).sfixed32 = { in: [1, 2, 3] }];
  2657. // }
  2658. // ```
  2659. repeated sfixed32 in = 6 [(predefined).cel = {
  2660. id: "sfixed32.in"
  2661. expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
  2662. }];
  2663. // `not_in` requires the field value to not be equal to any of the specified
  2664. // values. If the field value is one of the specified values, an error
  2665. // message is generated.
  2666. //
  2667. // ```proto
  2668. // message MySFixed32 {
  2669. // // value must not be in list [1, 2, 3]
  2670. // sfixed32 value = 1 [(buf.validate.field).sfixed32 = { not_in: [1, 2, 3] }];
  2671. // }
  2672. // ```
  2673. repeated sfixed32 not_in = 7 [(predefined).cel = {
  2674. id: "sfixed32.not_in"
  2675. expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''"
  2676. }];
  2677. // `example` specifies values that the field may have. These values SHOULD
  2678. // conform to other rules. `example` values will not impact validation
  2679. // but may be used as helpful guidance on how to populate the given field.
  2680. //
  2681. // ```proto
  2682. // message MySFixed32 {
  2683. // sfixed32 value = 1 [
  2684. // (buf.validate.field).sfixed32.example = 1,
  2685. // (buf.validate.field).sfixed32.example = 2
  2686. // ];
  2687. // }
  2688. // ```
  2689. repeated sfixed32 example = 8 [(predefined).cel = {
  2690. id: "sfixed32.example"
  2691. expression: "true"
  2692. }];
  2693. // Extension fields in this range that have the (buf.validate.predefined)
  2694. // option set will be treated as predefined field rules that can then be
  2695. // set on the field options of other fields to apply field rules.
  2696. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  2697. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  2698. // above this range are reserved for extension numbers that are not explicitly
  2699. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  2700. // above 99999 is discouraged due to the risk of conflicts.
  2701. //
  2702. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  2703. extensions 1000 to max;
  2704. }
  2705. // SFixed64Rules describes the rules applied to `fixed64` values.
  2706. message SFixed64Rules {
  2707. // `const` requires the field value to exactly match the specified value. If
  2708. // the field value doesn't match, an error message is generated.
  2709. //
  2710. // ```proto
  2711. // message MySFixed64 {
  2712. // // value must equal 42
  2713. // sfixed64 value = 1 [(buf.validate.field).sfixed64.const = 42];
  2714. // }
  2715. // ```
  2716. optional sfixed64 const = 1 [(predefined).cel = {
  2717. id: "sfixed64.const"
  2718. expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
  2719. }];
  2720. oneof less_than {
  2721. // `lt` requires the field value to be less than the specified value (field <
  2722. // value). If the field value is equal to or greater than the specified value,
  2723. // an error message is generated.
  2724. //
  2725. // ```proto
  2726. // message MySFixed64 {
  2727. // // value must be less than 10
  2728. // sfixed64 value = 1 [(buf.validate.field).sfixed64.lt = 10];
  2729. // }
  2730. // ```
  2731. sfixed64 lt = 2 [(predefined).cel = {
  2732. id: "sfixed64.lt"
  2733. expression:
  2734. "!has(rules.gte) && !has(rules.gt) && this >= rules.lt"
  2735. "? 'value must be less than %s'.format([rules.lt]) : ''"
  2736. }];
  2737. // `lte` requires the field value to be less than or equal to the specified
  2738. // value (field <= value). If the field value is greater than the specified
  2739. // value, an error message is generated.
  2740. //
  2741. // ```proto
  2742. // message MySFixed64 {
  2743. // // value must be less than or equal to 10
  2744. // sfixed64 value = 1 [(buf.validate.field).sfixed64.lte = 10];
  2745. // }
  2746. // ```
  2747. sfixed64 lte = 3 [(predefined).cel = {
  2748. id: "sfixed64.lte"
  2749. expression:
  2750. "!has(rules.gte) && !has(rules.gt) && this > rules.lte"
  2751. "? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
  2752. }];
  2753. }
  2754. oneof greater_than {
  2755. // `gt` requires the field value to be greater than the specified value
  2756. // (exclusive). If the value of `gt` is larger than a specified `lt` or
  2757. // `lte`, the range is reversed, and the field value must be outside the
  2758. // specified range. If the field value doesn't meet the required conditions,
  2759. // an error message is generated.
  2760. //
  2761. // ```proto
  2762. // message MySFixed64 {
  2763. // // value must be greater than 5 [sfixed64.gt]
  2764. // sfixed64 value = 1 [(buf.validate.field).sfixed64.gt = 5];
  2765. //
  2766. // // value must be greater than 5 and less than 10 [sfixed64.gt_lt]
  2767. // sfixed64 other_value = 2 [(buf.validate.field).sfixed64 = { gt: 5, lt: 10 }];
  2768. //
  2769. // // value must be greater than 10 or less than 5 [sfixed64.gt_lt_exclusive]
  2770. // sfixed64 another_value = 3 [(buf.validate.field).sfixed64 = { gt: 10, lt: 5 }];
  2771. // }
  2772. // ```
  2773. sfixed64 gt = 4 [
  2774. (predefined).cel = {
  2775. id: "sfixed64.gt"
  2776. expression:
  2777. "!has(rules.lt) && !has(rules.lte) && this <= rules.gt"
  2778. "? 'value must be greater than %s'.format([rules.gt]) : ''"
  2779. },
  2780. (predefined).cel = {
  2781. id: "sfixed64.gt_lt"
  2782. expression:
  2783. "has(rules.lt) && rules.lt >= rules.gt && (this >= rules.lt || this <= rules.gt)"
  2784. "? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
  2785. },
  2786. (predefined).cel = {
  2787. id: "sfixed64.gt_lt_exclusive"
  2788. expression:
  2789. "has(rules.lt) && rules.lt < rules.gt && (rules.lt <= this && this <= rules.gt)"
  2790. "? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
  2791. },
  2792. (predefined).cel = {
  2793. id: "sfixed64.gt_lte"
  2794. expression:
  2795. "has(rules.lte) && rules.lte >= rules.gt && (this > rules.lte || this <= rules.gt)"
  2796. "? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  2797. },
  2798. (predefined).cel = {
  2799. id: "sfixed64.gt_lte_exclusive"
  2800. expression:
  2801. "has(rules.lte) && rules.lte < rules.gt && (rules.lte < this && this <= rules.gt)"
  2802. "? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  2803. }
  2804. ];
  2805. // `gte` requires the field value to be greater than or equal to the specified
  2806. // value (exclusive). If the value of `gte` is larger than a specified `lt`
  2807. // or `lte`, the range is reversed, and the field value must be outside the
  2808. // specified range. If the field value doesn't meet the required conditions,
  2809. // an error message is generated.
  2810. //
  2811. // ```proto
  2812. // message MySFixed64 {
  2813. // // value must be greater than or equal to 5 [sfixed64.gte]
  2814. // sfixed64 value = 1 [(buf.validate.field).sfixed64.gte = 5];
  2815. //
  2816. // // value must be greater than or equal to 5 and less than 10 [sfixed64.gte_lt]
  2817. // sfixed64 other_value = 2 [(buf.validate.field).sfixed64 = { gte: 5, lt: 10 }];
  2818. //
  2819. // // value must be greater than or equal to 10 or less than 5 [sfixed64.gte_lt_exclusive]
  2820. // sfixed64 another_value = 3 [(buf.validate.field).sfixed64 = { gte: 10, lt: 5 }];
  2821. // }
  2822. // ```
  2823. sfixed64 gte = 5 [
  2824. (predefined).cel = {
  2825. id: "sfixed64.gte"
  2826. expression:
  2827. "!has(rules.lt) && !has(rules.lte) && this < rules.gte"
  2828. "? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
  2829. },
  2830. (predefined).cel = {
  2831. id: "sfixed64.gte_lt"
  2832. expression:
  2833. "has(rules.lt) && rules.lt >= rules.gte && (this >= rules.lt || this < rules.gte)"
  2834. "? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
  2835. },
  2836. (predefined).cel = {
  2837. id: "sfixed64.gte_lt_exclusive"
  2838. expression:
  2839. "has(rules.lt) && rules.lt < rules.gte && (rules.lt <= this && this < rules.gte)"
  2840. "? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
  2841. },
  2842. (predefined).cel = {
  2843. id: "sfixed64.gte_lte"
  2844. expression:
  2845. "has(rules.lte) && rules.lte >= rules.gte && (this > rules.lte || this < rules.gte)"
  2846. "? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  2847. },
  2848. (predefined).cel = {
  2849. id: "sfixed64.gte_lte_exclusive"
  2850. expression:
  2851. "has(rules.lte) && rules.lte < rules.gte && (rules.lte < this && this < rules.gte)"
  2852. "? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  2853. }
  2854. ];
  2855. }
  2856. // `in` requires the field value to be equal to one of the specified values.
  2857. // If the field value isn't one of the specified values, an error message is
  2858. // generated.
  2859. //
  2860. // ```proto
  2861. // message MySFixed64 {
  2862. // // value must be in list [1, 2, 3]
  2863. // sfixed64 value = 1 [(buf.validate.field).sfixed64 = { in: [1, 2, 3] }];
  2864. // }
  2865. // ```
  2866. repeated sfixed64 in = 6 [(predefined).cel = {
  2867. id: "sfixed64.in"
  2868. expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
  2869. }];
  2870. // `not_in` requires the field value to not be equal to any of the specified
  2871. // values. If the field value is one of the specified values, an error
  2872. // message is generated.
  2873. //
  2874. // ```proto
  2875. // message MySFixed64 {
  2876. // // value must not be in list [1, 2, 3]
  2877. // sfixed64 value = 1 [(buf.validate.field).sfixed64 = { not_in: [1, 2, 3] }];
  2878. // }
  2879. // ```
  2880. repeated sfixed64 not_in = 7 [(predefined).cel = {
  2881. id: "sfixed64.not_in"
  2882. expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''"
  2883. }];
  2884. // `example` specifies values that the field may have. These values SHOULD
  2885. // conform to other rules. `example` values will not impact validation
  2886. // but may be used as helpful guidance on how to populate the given field.
  2887. //
  2888. // ```proto
  2889. // message MySFixed64 {
  2890. // sfixed64 value = 1 [
  2891. // (buf.validate.field).sfixed64.example = 1,
  2892. // (buf.validate.field).sfixed64.example = 2
  2893. // ];
  2894. // }
  2895. // ```
  2896. repeated sfixed64 example = 8 [(predefined).cel = {
  2897. id: "sfixed64.example"
  2898. expression: "true"
  2899. }];
  2900. // Extension fields in this range that have the (buf.validate.predefined)
  2901. // option set will be treated as predefined field rules that can then be
  2902. // set on the field options of other fields to apply field rules.
  2903. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  2904. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  2905. // above this range are reserved for extension numbers that are not explicitly
  2906. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  2907. // above 99999 is discouraged due to the risk of conflicts.
  2908. //
  2909. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  2910. extensions 1000 to max;
  2911. }
  2912. // BoolRules describes the rules applied to `bool` values. These rules
  2913. // may also be applied to the `google.protobuf.BoolValue` Well-Known-Type.
  2914. message BoolRules {
  2915. // `const` requires the field value to exactly match the specified boolean value.
  2916. // If the field value doesn't match, an error message is generated.
  2917. //
  2918. // ```proto
  2919. // message MyBool {
  2920. // // value must equal true
  2921. // bool value = 1 [(buf.validate.field).bool.const = true];
  2922. // }
  2923. // ```
  2924. optional bool const = 1 [(predefined).cel = {
  2925. id: "bool.const"
  2926. expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
  2927. }];
  2928. // `example` specifies values that the field may have. These values SHOULD
  2929. // conform to other rules. `example` values will not impact validation
  2930. // but may be used as helpful guidance on how to populate the given field.
  2931. //
  2932. // ```proto
  2933. // message MyBool {
  2934. // bool value = 1 [
  2935. // (buf.validate.field).bool.example = 1,
  2936. // (buf.validate.field).bool.example = 2
  2937. // ];
  2938. // }
  2939. // ```
  2940. repeated bool example = 2 [(predefined).cel = {
  2941. id: "bool.example"
  2942. expression: "true"
  2943. }];
  2944. // Extension fields in this range that have the (buf.validate.predefined)
  2945. // option set will be treated as predefined field rules that can then be
  2946. // set on the field options of other fields to apply field rules.
  2947. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  2948. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  2949. // above this range are reserved for extension numbers that are not explicitly
  2950. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  2951. // above 99999 is discouraged due to the risk of conflicts.
  2952. //
  2953. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  2954. extensions 1000 to max;
  2955. }
  2956. // StringRules describes the rules applied to `string` values These
  2957. // rules may also be applied to the `google.protobuf.StringValue` Well-Known-Type.
  2958. message StringRules {
  2959. // `const` requires the field value to exactly match the specified value. If
  2960. // the field value doesn't match, an error message is generated.
  2961. //
  2962. // ```proto
  2963. // message MyString {
  2964. // // value must equal `hello`
  2965. // string value = 1 [(buf.validate.field).string.const = "hello"];
  2966. // }
  2967. // ```
  2968. optional string const = 1 [(predefined).cel = {
  2969. id: "string.const"
  2970. expression: "this != getField(rules, 'const') ? 'value must equal `%s`'.format([getField(rules, 'const')]) : ''"
  2971. }];
  2972. // `len` dictates that the field value must have the specified
  2973. // number of characters (Unicode code points), which may differ from the number
  2974. // of bytes in the string. If the field value does not meet the specified
  2975. // length, an error message will be generated.
  2976. //
  2977. // ```proto
  2978. // message MyString {
  2979. // // value length must be 5 characters
  2980. // string value = 1 [(buf.validate.field).string.len = 5];
  2981. // }
  2982. // ```
  2983. optional uint64 len = 19 [(predefined).cel = {
  2984. id: "string.len"
  2985. expression: "uint(this.size()) != rules.len ? 'value length must be %s characters'.format([rules.len]) : ''"
  2986. }];
  2987. // `min_len` specifies that the field value must have at least the specified
  2988. // number of characters (Unicode code points), which may differ from the number
  2989. // of bytes in the string. If the field value contains fewer characters, an error
  2990. // message will be generated.
  2991. //
  2992. // ```proto
  2993. // message MyString {
  2994. // // value length must be at least 3 characters
  2995. // string value = 1 [(buf.validate.field).string.min_len = 3];
  2996. // }
  2997. // ```
  2998. optional uint64 min_len = 2 [(predefined).cel = {
  2999. id: "string.min_len"
  3000. expression: "uint(this.size()) < rules.min_len ? 'value length must be at least %s characters'.format([rules.min_len]) : ''"
  3001. }];
  3002. // `max_len` specifies that the field value must have no more than the specified
  3003. // number of characters (Unicode code points), which may differ from the
  3004. // number of bytes in the string. If the field value contains more characters,
  3005. // an error message will be generated.
  3006. //
  3007. // ```proto
  3008. // message MyString {
  3009. // // value length must be at most 10 characters
  3010. // string value = 1 [(buf.validate.field).string.max_len = 10];
  3011. // }
  3012. // ```
  3013. optional uint64 max_len = 3 [(predefined).cel = {
  3014. id: "string.max_len"
  3015. expression: "uint(this.size()) > rules.max_len ? 'value length must be at most %s characters'.format([rules.max_len]) : ''"
  3016. }];
  3017. // `len_bytes` dictates that the field value must have the specified number of
  3018. // bytes. If the field value does not match the specified length in bytes,
  3019. // an error message will be generated.
  3020. //
  3021. // ```proto
  3022. // message MyString {
  3023. // // value length must be 6 bytes
  3024. // string value = 1 [(buf.validate.field).string.len_bytes = 6];
  3025. // }
  3026. // ```
  3027. optional uint64 len_bytes = 20 [(predefined).cel = {
  3028. id: "string.len_bytes"
  3029. expression: "uint(bytes(this).size()) != rules.len_bytes ? 'value length must be %s bytes'.format([rules.len_bytes]) : ''"
  3030. }];
  3031. // `min_bytes` specifies that the field value must have at least the specified
  3032. // number of bytes. If the field value contains fewer bytes, an error message
  3033. // will be generated.
  3034. //
  3035. // ```proto
  3036. // message MyString {
  3037. // // value length must be at least 4 bytes
  3038. // string value = 1 [(buf.validate.field).string.min_bytes = 4];
  3039. // }
  3040. //
  3041. // ```
  3042. optional uint64 min_bytes = 4 [(predefined).cel = {
  3043. id: "string.min_bytes"
  3044. expression: "uint(bytes(this).size()) < rules.min_bytes ? 'value length must be at least %s bytes'.format([rules.min_bytes]) : ''"
  3045. }];
  3046. // `max_bytes` specifies that the field value must have no more than the
  3047. //specified number of bytes. If the field value contains more bytes, an
  3048. // error message will be generated.
  3049. //
  3050. // ```proto
  3051. // message MyString {
  3052. // // value length must be at most 8 bytes
  3053. // string value = 1 [(buf.validate.field).string.max_bytes = 8];
  3054. // }
  3055. // ```
  3056. optional uint64 max_bytes = 5 [(predefined).cel = {
  3057. id: "string.max_bytes"
  3058. expression: "uint(bytes(this).size()) > rules.max_bytes ? 'value length must be at most %s bytes'.format([rules.max_bytes]) : ''"
  3059. }];
  3060. // `pattern` specifies that the field value must match the specified
  3061. // regular expression (RE2 syntax), with the expression provided without any
  3062. // delimiters. If the field value doesn't match the regular expression, an
  3063. // error message will be generated.
  3064. //
  3065. // ```proto
  3066. // message MyString {
  3067. // // value does not match regex pattern `^[a-zA-Z]//$`
  3068. // string value = 1 [(buf.validate.field).string.pattern = "^[a-zA-Z]//$"];
  3069. // }
  3070. // ```
  3071. optional string pattern = 6 [(predefined).cel = {
  3072. id: "string.pattern"
  3073. expression: "!this.matches(rules.pattern) ? 'value does not match regex pattern `%s`'.format([rules.pattern]) : ''"
  3074. }];
  3075. // `prefix` specifies that the field value must have the
  3076. //specified substring at the beginning of the string. If the field value
  3077. // doesn't start with the specified prefix, an error message will be
  3078. // generated.
  3079. //
  3080. // ```proto
  3081. // message MyString {
  3082. // // value does not have prefix `pre`
  3083. // string value = 1 [(buf.validate.field).string.prefix = "pre"];
  3084. // }
  3085. // ```
  3086. optional string prefix = 7 [(predefined).cel = {
  3087. id: "string.prefix"
  3088. expression: "!this.startsWith(rules.prefix) ? 'value does not have prefix `%s`'.format([rules.prefix]) : ''"
  3089. }];
  3090. // `suffix` specifies that the field value must have the
  3091. //specified substring at the end of the string. If the field value doesn't
  3092. // end with the specified suffix, an error message will be generated.
  3093. //
  3094. // ```proto
  3095. // message MyString {
  3096. // // value does not have suffix `post`
  3097. // string value = 1 [(buf.validate.field).string.suffix = "post"];
  3098. // }
  3099. // ```
  3100. optional string suffix = 8 [(predefined).cel = {
  3101. id: "string.suffix"
  3102. expression: "!this.endsWith(rules.suffix) ? 'value does not have suffix `%s`'.format([rules.suffix]) : ''"
  3103. }];
  3104. // `contains` specifies that the field value must have the
  3105. //specified substring anywhere in the string. If the field value doesn't
  3106. // contain the specified substring, an error message will be generated.
  3107. //
  3108. // ```proto
  3109. // message MyString {
  3110. // // value does not contain substring `inside`.
  3111. // string value = 1 [(buf.validate.field).string.contains = "inside"];
  3112. // }
  3113. // ```
  3114. optional string contains = 9 [(predefined).cel = {
  3115. id: "string.contains"
  3116. expression: "!this.contains(rules.contains) ? 'value does not contain substring `%s`'.format([rules.contains]) : ''"
  3117. }];
  3118. // `not_contains` specifies that the field value must not have the
  3119. //specified substring anywhere in the string. If the field value contains
  3120. // the specified substring, an error message will be generated.
  3121. //
  3122. // ```proto
  3123. // message MyString {
  3124. // // value contains substring `inside`.
  3125. // string value = 1 [(buf.validate.field).string.not_contains = "inside"];
  3126. // }
  3127. // ```
  3128. optional string not_contains = 23 [(predefined).cel = {
  3129. id: "string.not_contains"
  3130. expression: "this.contains(rules.not_contains) ? 'value contains substring `%s`'.format([rules.not_contains]) : ''"
  3131. }];
  3132. // `in` specifies that the field value must be equal to one of the specified
  3133. // values. If the field value isn't one of the specified values, an error
  3134. // message will be generated.
  3135. //
  3136. // ```proto
  3137. // message MyString {
  3138. // // value must be in list ["apple", "banana"]
  3139. // string value = 1 [(buf.validate.field).string.in = "apple", (buf.validate.field).string.in = "banana"];
  3140. // }
  3141. // ```
  3142. repeated string in = 10 [(predefined).cel = {
  3143. id: "string.in"
  3144. expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
  3145. }];
  3146. // `not_in` specifies that the field value cannot be equal to any
  3147. // of the specified values. If the field value is one of the specified values,
  3148. // an error message will be generated.
  3149. // ```proto
  3150. // message MyString {
  3151. // // value must not be in list ["orange", "grape"]
  3152. // string value = 1 [(buf.validate.field).string.not_in = "orange", (buf.validate.field).string.not_in = "grape"];
  3153. // }
  3154. // ```
  3155. repeated string not_in = 11 [(predefined).cel = {
  3156. id: "string.not_in"
  3157. expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''"
  3158. }];
  3159. // `WellKnown` rules provide advanced rules against common string
  3160. // patterns.
  3161. oneof well_known {
  3162. // `email` specifies that the field value must be a valid email address, for
  3163. // example "foo@example.com".
  3164. //
  3165. // Conforms to the definition for a valid email address from the [HTML standard](https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address).
  3166. // Note that this standard willfully deviates from [RFC 5322](https://datatracker.ietf.org/doc/html/rfc5322),
  3167. // which allows many unexpected forms of email addresses and will easily match
  3168. // a typographical error.
  3169. //
  3170. // If the field value isn't a valid email address, an error message will be generated.
  3171. //
  3172. // ```proto
  3173. // message MyString {
  3174. // // value must be a valid email address
  3175. // string value = 1 [(buf.validate.field).string.email = true];
  3176. // }
  3177. // ```
  3178. bool email = 12 [
  3179. (predefined).cel = {
  3180. id: "string.email"
  3181. message: "value must be a valid email address"
  3182. expression: "!rules.email || this == '' || this.isEmail()"
  3183. },
  3184. (predefined).cel = {
  3185. id: "string.email_empty"
  3186. message: "value is empty, which is not a valid email address"
  3187. expression: "!rules.email || this != ''"
  3188. }
  3189. ];
  3190. // `hostname` specifies that the field value must be a valid hostname, for
  3191. // example "foo.example.com".
  3192. //
  3193. // A valid hostname follows the rules below:
  3194. // - The name consists of one or more labels, separated by a dot (".").
  3195. // - Each label can be 1 to 63 alphanumeric characters.
  3196. // - A label can contain hyphens ("-"), but must not start or end with a hyphen.
  3197. // - The right-most label must not be digits only.
  3198. // - The name can have a trailing dot—for example, "foo.example.com.".
  3199. // - The name can be 253 characters at most, excluding the optional trailing dot.
  3200. //
  3201. // If the field value isn't a valid hostname, an error message will be generated.
  3202. //
  3203. // ```proto
  3204. // message MyString {
  3205. // // value must be a valid hostname
  3206. // string value = 1 [(buf.validate.field).string.hostname = true];
  3207. // }
  3208. // ```
  3209. bool hostname = 13 [
  3210. (predefined).cel = {
  3211. id: "string.hostname"
  3212. message: "value must be a valid hostname"
  3213. expression: "!rules.hostname || this == '' || this.isHostname()"
  3214. },
  3215. (predefined).cel = {
  3216. id: "string.hostname_empty"
  3217. message: "value is empty, which is not a valid hostname"
  3218. expression: "!rules.hostname || this != ''"
  3219. }
  3220. ];
  3221. // `ip` specifies that the field value must be a valid IP (v4 or v6) address.
  3222. //
  3223. // IPv4 addresses are expected in the dotted decimal format—for example, "192.168.5.21".
  3224. // IPv6 addresses are expected in their text representation—for example, "::1",
  3225. // or "2001:0DB8:ABCD:0012::0".
  3226. //
  3227. // Both formats are well-defined in the internet standard [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986).
  3228. // Zone identifiers for IPv6 addresses (for example, "fe80::a%en1") are supported.
  3229. //
  3230. // If the field value isn't a valid IP address, an error message will be
  3231. // generated.
  3232. //
  3233. // ```proto
  3234. // message MyString {
  3235. // // value must be a valid IP address
  3236. // string value = 1 [(buf.validate.field).string.ip = true];
  3237. // }
  3238. // ```
  3239. bool ip = 14 [
  3240. (predefined).cel = {
  3241. id: "string.ip"
  3242. message: "value must be a valid IP address"
  3243. expression: "!rules.ip || this == '' || this.isIp()"
  3244. },
  3245. (predefined).cel = {
  3246. id: "string.ip_empty"
  3247. message: "value is empty, which is not a valid IP address"
  3248. expression: "!rules.ip || this != ''"
  3249. }
  3250. ];
  3251. // `ipv4` specifies that the field value must be a valid IPv4 address—for
  3252. // example "192.168.5.21". If the field value isn't a valid IPv4 address, an
  3253. // error message will be generated.
  3254. //
  3255. // ```proto
  3256. // message MyString {
  3257. // // value must be a valid IPv4 address
  3258. // string value = 1 [(buf.validate.field).string.ipv4 = true];
  3259. // }
  3260. // ```
  3261. bool ipv4 = 15 [
  3262. (predefined).cel = {
  3263. id: "string.ipv4"
  3264. message: "value must be a valid IPv4 address"
  3265. expression: "!rules.ipv4 || this == '' || this.isIp(4)"
  3266. },
  3267. (predefined).cel = {
  3268. id: "string.ipv4_empty"
  3269. message: "value is empty, which is not a valid IPv4 address"
  3270. expression: "!rules.ipv4 || this != ''"
  3271. }
  3272. ];
  3273. // `ipv6` specifies that the field value must be a valid IPv6 address—for
  3274. // example "::1", or "d7a:115c:a1e0:ab12:4843:cd96:626b:430b". If the field
  3275. // value is not a valid IPv6 address, an error message will be generated.
  3276. //
  3277. // ```proto
  3278. // message MyString {
  3279. // // value must be a valid IPv6 address
  3280. // string value = 1 [(buf.validate.field).string.ipv6 = true];
  3281. // }
  3282. // ```
  3283. bool ipv6 = 16 [
  3284. (predefined).cel = {
  3285. id: "string.ipv6"
  3286. message: "value must be a valid IPv6 address"
  3287. expression: "!rules.ipv6 || this == '' || this.isIp(6)"
  3288. },
  3289. (predefined).cel = {
  3290. id: "string.ipv6_empty"
  3291. message: "value is empty, which is not a valid IPv6 address"
  3292. expression: "!rules.ipv6 || this != ''"
  3293. }
  3294. ];
  3295. // `uri` specifies that the field value must be a valid URI, for example
  3296. // "https://example.com/foo/bar?baz=quux#frag".
  3297. //
  3298. // URI is defined in the internet standard [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986).
  3299. // Zone Identifiers in IPv6 address literals are supported ([RFC 6874](https://datatracker.ietf.org/doc/html/rfc6874)).
  3300. //
  3301. // If the field value isn't a valid URI, an error message will be generated.
  3302. //
  3303. // ```proto
  3304. // message MyString {
  3305. // // value must be a valid URI
  3306. // string value = 1 [(buf.validate.field).string.uri = true];
  3307. // }
  3308. // ```
  3309. bool uri = 17 [
  3310. (predefined).cel = {
  3311. id: "string.uri"
  3312. message: "value must be a valid URI"
  3313. expression: "!rules.uri || this == '' || this.isUri()"
  3314. },
  3315. (predefined).cel = {
  3316. id: "string.uri_empty"
  3317. message: "value is empty, which is not a valid URI"
  3318. expression: "!rules.uri || this != ''"
  3319. }
  3320. ];
  3321. // `uri_ref` specifies that the field value must be a valid URI Reference—either
  3322. // a URI such as "https://example.com/foo/bar?baz=quux#frag", or a Relative
  3323. // Reference such as "./foo/bar?query".
  3324. //
  3325. // URI, URI Reference, and Relative Reference are defined in the internet
  3326. // standard [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986). Zone
  3327. // Identifiers in IPv6 address literals are supported ([RFC 6874](https://datatracker.ietf.org/doc/html/rfc6874)).
  3328. //
  3329. // If the field value isn't a valid URI Reference, an error message will be
  3330. // generated.
  3331. //
  3332. // ```proto
  3333. // message MyString {
  3334. // // value must be a valid URI Reference
  3335. // string value = 1 [(buf.validate.field).string.uri_ref = true];
  3336. // }
  3337. // ```
  3338. bool uri_ref = 18 [(predefined).cel = {
  3339. id: "string.uri_ref"
  3340. message: "value must be a valid URI Reference"
  3341. expression: "!rules.uri_ref || this.isUriRef()"
  3342. }];
  3343. // `address` specifies that the field value must be either a valid hostname
  3344. // (for example, "example.com"), or a valid IP (v4 or v6) address (for example,
  3345. // "192.168.0.1", or "::1"). If the field value isn't a valid hostname or IP,
  3346. // an error message will be generated.
  3347. //
  3348. // ```proto
  3349. // message MyString {
  3350. // // value must be a valid hostname, or ip address
  3351. // string value = 1 [(buf.validate.field).string.address = true];
  3352. // }
  3353. // ```
  3354. bool address = 21 [
  3355. (predefined).cel = {
  3356. id: "string.address"
  3357. message: "value must be a valid hostname, or ip address"
  3358. expression: "!rules.address || this == '' || this.isHostname() || this.isIp()"
  3359. },
  3360. (predefined).cel = {
  3361. id: "string.address_empty"
  3362. message: "value is empty, which is not a valid hostname, or ip address"
  3363. expression: "!rules.address || this != ''"
  3364. }
  3365. ];
  3366. // `uuid` specifies that the field value must be a valid UUID as defined by
  3367. // [RFC 4122](https://datatracker.ietf.org/doc/html/rfc4122#section-4.1.2). If the
  3368. // field value isn't a valid UUID, an error message will be generated.
  3369. //
  3370. // ```proto
  3371. // message MyString {
  3372. // // value must be a valid UUID
  3373. // string value = 1 [(buf.validate.field).string.uuid = true];
  3374. // }
  3375. // ```
  3376. bool uuid = 22 [
  3377. (predefined).cel = {
  3378. id: "string.uuid"
  3379. message: "value must be a valid UUID"
  3380. expression: "!rules.uuid || this == '' || this.matches('^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$')"
  3381. },
  3382. (predefined).cel = {
  3383. id: "string.uuid_empty"
  3384. message: "value is empty, which is not a valid UUID"
  3385. expression: "!rules.uuid || this != ''"
  3386. }
  3387. ];
  3388. // `tuuid` (trimmed UUID) specifies that the field value must be a valid UUID as
  3389. // defined by [RFC 4122](https://datatracker.ietf.org/doc/html/rfc4122#section-4.1.2) with all dashes
  3390. // omitted. If the field value isn't a valid UUID without dashes, an error message
  3391. // will be generated.
  3392. //
  3393. // ```proto
  3394. // message MyString {
  3395. // // value must be a valid trimmed UUID
  3396. // string value = 1 [(buf.validate.field).string.tuuid = true];
  3397. // }
  3398. // ```
  3399. bool tuuid = 33 [
  3400. (predefined).cel = {
  3401. id: "string.tuuid"
  3402. message: "value must be a valid trimmed UUID"
  3403. expression: "!rules.tuuid || this == '' || this.matches('^[0-9a-fA-F]{32}$')"
  3404. },
  3405. (predefined).cel = {
  3406. id: "string.tuuid_empty"
  3407. message: "value is empty, which is not a valid trimmed UUID"
  3408. expression: "!rules.tuuid || this != ''"
  3409. }
  3410. ];
  3411. // `ip_with_prefixlen` specifies that the field value must be a valid IP
  3412. // (v4 or v6) address with prefix length—for example, "192.168.5.21/16" or
  3413. // "2001:0DB8:ABCD:0012::F1/64". If the field value isn't a valid IP with
  3414. // prefix length, an error message will be generated.
  3415. //
  3416. // ```proto
  3417. // message MyString {
  3418. // // value must be a valid IP with prefix length
  3419. // string value = 1 [(buf.validate.field).string.ip_with_prefixlen = true];
  3420. // }
  3421. // ```
  3422. bool ip_with_prefixlen = 26 [
  3423. (predefined).cel = {
  3424. id: "string.ip_with_prefixlen"
  3425. message: "value must be a valid IP prefix"
  3426. expression: "!rules.ip_with_prefixlen || this == '' || this.isIpPrefix()"
  3427. },
  3428. (predefined).cel = {
  3429. id: "string.ip_with_prefixlen_empty"
  3430. message: "value is empty, which is not a valid IP prefix"
  3431. expression: "!rules.ip_with_prefixlen || this != ''"
  3432. }
  3433. ];
  3434. // `ipv4_with_prefixlen` specifies that the field value must be a valid
  3435. // IPv4 address with prefix length—for example, "192.168.5.21/16". If the
  3436. // field value isn't a valid IPv4 address with prefix length, an error
  3437. // message will be generated.
  3438. //
  3439. // ```proto
  3440. // message MyString {
  3441. // // value must be a valid IPv4 address with prefix length
  3442. // string value = 1 [(buf.validate.field).string.ipv4_with_prefixlen = true];
  3443. // }
  3444. // ```
  3445. bool ipv4_with_prefixlen = 27 [
  3446. (predefined).cel = {
  3447. id: "string.ipv4_with_prefixlen"
  3448. message: "value must be a valid IPv4 address with prefix length"
  3449. expression: "!rules.ipv4_with_prefixlen || this == '' || this.isIpPrefix(4)"
  3450. },
  3451. (predefined).cel = {
  3452. id: "string.ipv4_with_prefixlen_empty"
  3453. message: "value is empty, which is not a valid IPv4 address with prefix length"
  3454. expression: "!rules.ipv4_with_prefixlen || this != ''"
  3455. }
  3456. ];
  3457. // `ipv6_with_prefixlen` specifies that the field value must be a valid
  3458. // IPv6 address with prefix length—for example, "2001:0DB8:ABCD:0012::F1/64".
  3459. // If the field value is not a valid IPv6 address with prefix length,
  3460. // an error message will be generated.
  3461. //
  3462. // ```proto
  3463. // message MyString {
  3464. // // value must be a valid IPv6 address prefix length
  3465. // string value = 1 [(buf.validate.field).string.ipv6_with_prefixlen = true];
  3466. // }
  3467. // ```
  3468. bool ipv6_with_prefixlen = 28 [
  3469. (predefined).cel = {
  3470. id: "string.ipv6_with_prefixlen"
  3471. message: "value must be a valid IPv6 address with prefix length"
  3472. expression: "!rules.ipv6_with_prefixlen || this == '' || this.isIpPrefix(6)"
  3473. },
  3474. (predefined).cel = {
  3475. id: "string.ipv6_with_prefixlen_empty"
  3476. message: "value is empty, which is not a valid IPv6 address with prefix length"
  3477. expression: "!rules.ipv6_with_prefixlen || this != ''"
  3478. }
  3479. ];
  3480. // `ip_prefix` specifies that the field value must be a valid IP (v4 or v6)
  3481. // prefix—for example, "192.168.0.0/16" or "2001:0DB8:ABCD:0012::0/64".
  3482. //
  3483. // The prefix must have all zeros for the unmasked bits. For example,
  3484. // "2001:0DB8:ABCD:0012::0/64" designates the left-most 64 bits for the
  3485. // prefix, and the remaining 64 bits must be zero.
  3486. //
  3487. // If the field value isn't a valid IP prefix, an error message will be
  3488. // generated.
  3489. //
  3490. // ```proto
  3491. // message MyString {
  3492. // // value must be a valid IP prefix
  3493. // string value = 1 [(buf.validate.field).string.ip_prefix = true];
  3494. // }
  3495. // ```
  3496. bool ip_prefix = 29 [
  3497. (predefined).cel = {
  3498. id: "string.ip_prefix"
  3499. message: "value must be a valid IP prefix"
  3500. expression: "!rules.ip_prefix || this == '' || this.isIpPrefix(true)"
  3501. },
  3502. (predefined).cel = {
  3503. id: "string.ip_prefix_empty"
  3504. message: "value is empty, which is not a valid IP prefix"
  3505. expression: "!rules.ip_prefix || this != ''"
  3506. }
  3507. ];
  3508. // `ipv4_prefix` specifies that the field value must be a valid IPv4
  3509. // prefix, for example "192.168.0.0/16".
  3510. //
  3511. // The prefix must have all zeros for the unmasked bits. For example,
  3512. // "192.168.0.0/16" designates the left-most 16 bits for the prefix,
  3513. // and the remaining 16 bits must be zero.
  3514. //
  3515. // If the field value isn't a valid IPv4 prefix, an error message
  3516. // will be generated.
  3517. //
  3518. // ```proto
  3519. // message MyString {
  3520. // // value must be a valid IPv4 prefix
  3521. // string value = 1 [(buf.validate.field).string.ipv4_prefix = true];
  3522. // }
  3523. // ```
  3524. bool ipv4_prefix = 30 [
  3525. (predefined).cel = {
  3526. id: "string.ipv4_prefix"
  3527. message: "value must be a valid IPv4 prefix"
  3528. expression: "!rules.ipv4_prefix || this == '' || this.isIpPrefix(4, true)"
  3529. },
  3530. (predefined).cel = {
  3531. id: "string.ipv4_prefix_empty"
  3532. message: "value is empty, which is not a valid IPv4 prefix"
  3533. expression: "!rules.ipv4_prefix || this != ''"
  3534. }
  3535. ];
  3536. // `ipv6_prefix` specifies that the field value must be a valid IPv6 prefix—for
  3537. // example, "2001:0DB8:ABCD:0012::0/64".
  3538. //
  3539. // The prefix must have all zeros for the unmasked bits. For example,
  3540. // "2001:0DB8:ABCD:0012::0/64" designates the left-most 64 bits for the
  3541. // prefix, and the remaining 64 bits must be zero.
  3542. //
  3543. // If the field value is not a valid IPv6 prefix, an error message will be
  3544. // generated.
  3545. //
  3546. // ```proto
  3547. // message MyString {
  3548. // // value must be a valid IPv6 prefix
  3549. // string value = 1 [(buf.validate.field).string.ipv6_prefix = true];
  3550. // }
  3551. // ```
  3552. bool ipv6_prefix = 31 [
  3553. (predefined).cel = {
  3554. id: "string.ipv6_prefix"
  3555. message: "value must be a valid IPv6 prefix"
  3556. expression: "!rules.ipv6_prefix || this == '' || this.isIpPrefix(6, true)"
  3557. },
  3558. (predefined).cel = {
  3559. id: "string.ipv6_prefix_empty"
  3560. message: "value is empty, which is not a valid IPv6 prefix"
  3561. expression: "!rules.ipv6_prefix || this != ''"
  3562. }
  3563. ];
  3564. // `host_and_port` specifies that the field value must be valid host/port
  3565. // pair—for example, "example.com:8080".
  3566. //
  3567. // The host can be one of:
  3568. //- An IPv4 address in dotted decimal format—for example, "192.168.5.21".
  3569. //- An IPv6 address enclosed in square brackets—for example, "[2001:0DB8:ABCD:0012::F1]".
  3570. //- A hostname—for example, "example.com".
  3571. //
  3572. // The port is separated by a colon. It must be non-empty, with a decimal number
  3573. // in the range of 0-65535, inclusive.
  3574. bool host_and_port = 32 [
  3575. (predefined).cel = {
  3576. id: "string.host_and_port"
  3577. message: "value must be a valid host (hostname or IP address) and port pair"
  3578. expression: "!rules.host_and_port || this == '' || this.isHostAndPort(true)"
  3579. },
  3580. (predefined).cel = {
  3581. id: "string.host_and_port_empty"
  3582. message: "value is empty, which is not a valid host and port pair"
  3583. expression: "!rules.host_and_port || this != ''"
  3584. }
  3585. ];
  3586. // `well_known_regex` specifies a common well-known pattern
  3587. // defined as a regex. If the field value doesn't match the well-known
  3588. // regex, an error message will be generated.
  3589. //
  3590. // ```proto
  3591. // message MyString {
  3592. // // value must be a valid HTTP header value
  3593. // string value = 1 [(buf.validate.field).string.well_known_regex = KNOWN_REGEX_HTTP_HEADER_VALUE];
  3594. // }
  3595. // ```
  3596. //
  3597. // #### KnownRegex
  3598. //
  3599. // `well_known_regex` contains some well-known patterns.
  3600. //
  3601. // | Name | Number | Description |
  3602. // |-------------------------------|--------|-------------------------------------------|
  3603. // | KNOWN_REGEX_UNSPECIFIED | 0 | |
  3604. // | KNOWN_REGEX_HTTP_HEADER_NAME | 1 | HTTP header name as defined by [RFC 7230](https://datatracker.ietf.org/doc/html/rfc7230#section-3.2) |
  3605. // | KNOWN_REGEX_HTTP_HEADER_VALUE | 2 | HTTP header value as defined by [RFC 7230](https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.4) |
  3606. KnownRegex well_known_regex = 24 [
  3607. (predefined).cel = {
  3608. id: "string.well_known_regex.header_name"
  3609. message: "value must be a valid HTTP header name"
  3610. expression:
  3611. "rules.well_known_regex != 1 || this == '' || this.matches(!has(rules.strict) || rules.strict ?"
  3612. "'^:?[0-9a-zA-Z!#$%&\\'*+-.^_|~\\x60]+$' :"
  3613. "'^[^\\u0000\\u000A\\u000D]+$')"
  3614. },
  3615. (predefined).cel = {
  3616. id: "string.well_known_regex.header_name_empty"
  3617. message: "value is empty, which is not a valid HTTP header name"
  3618. expression: "rules.well_known_regex != 1 || this != ''"
  3619. },
  3620. (predefined).cel = {
  3621. id: "string.well_known_regex.header_value"
  3622. message: "value must be a valid HTTP header value"
  3623. expression:
  3624. "rules.well_known_regex != 2 || this.matches(!has(rules.strict) || rules.strict ?"
  3625. "'^[^\\u0000-\\u0008\\u000A-\\u001F\\u007F]*$' :"
  3626. "'^[^\\u0000\\u000A\\u000D]*$')"
  3627. }
  3628. ];
  3629. }
  3630. // This applies to regexes `HTTP_HEADER_NAME` and `HTTP_HEADER_VALUE` to
  3631. // enable strict header validation. By default, this is true, and HTTP header
  3632. // validations are [RFC-compliant](https://datatracker.ietf.org/doc/html/rfc7230#section-3). Setting to false will enable looser
  3633. // validations that only disallow `\r\n\0` characters, which can be used to
  3634. // bypass header matching rules.
  3635. //
  3636. // ```proto
  3637. // message MyString {
  3638. // // The field `value` must have be a valid HTTP headers, but not enforced with strict rules.
  3639. // string value = 1 [(buf.validate.field).string.strict = false];
  3640. // }
  3641. // ```
  3642. optional bool strict = 25;
  3643. // `example` specifies values that the field may have. These values SHOULD
  3644. // conform to other rules. `example` values will not impact validation
  3645. // but may be used as helpful guidance on how to populate the given field.
  3646. //
  3647. // ```proto
  3648. // message MyString {
  3649. // string value = 1 [
  3650. // (buf.validate.field).string.example = "hello",
  3651. // (buf.validate.field).string.example = "world"
  3652. // ];
  3653. // }
  3654. // ```
  3655. repeated string example = 34 [(predefined).cel = {
  3656. id: "string.example"
  3657. expression: "true"
  3658. }];
  3659. // Extension fields in this range that have the (buf.validate.predefined)
  3660. // option set will be treated as predefined field rules that can then be
  3661. // set on the field options of other fields to apply field rules.
  3662. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  3663. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  3664. // above this range are reserved for extension numbers that are not explicitly
  3665. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  3666. // above 99999 is discouraged due to the risk of conflicts.
  3667. //
  3668. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  3669. extensions 1000 to max;
  3670. }
  3671. // KnownRegex contains some well-known patterns.
  3672. enum KnownRegex {
  3673. KNOWN_REGEX_UNSPECIFIED = 0;
  3674. // HTTP header name as defined by [RFC 7230](https://datatracker.ietf.org/doc/html/rfc7230#section-3.2).
  3675. KNOWN_REGEX_HTTP_HEADER_NAME = 1;
  3676. // HTTP header value as defined by [RFC 7230](https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.4).
  3677. KNOWN_REGEX_HTTP_HEADER_VALUE = 2;
  3678. }
  3679. // BytesRules describe the rules applied to `bytes` values. These rules
  3680. // may also be applied to the `google.protobuf.BytesValue` Well-Known-Type.
  3681. message BytesRules {
  3682. // `const` requires the field value to exactly match the specified bytes
  3683. // value. If the field value doesn't match, an error message is generated.
  3684. //
  3685. // ```proto
  3686. // message MyBytes {
  3687. // // value must be "\x01\x02\x03\x04"
  3688. // bytes value = 1 [(buf.validate.field).bytes.const = "\x01\x02\x03\x04"];
  3689. // }
  3690. // ```
  3691. optional bytes const = 1 [(predefined).cel = {
  3692. id: "bytes.const"
  3693. expression: "this != getField(rules, 'const') ? 'value must be %x'.format([getField(rules, 'const')]) : ''"
  3694. }];
  3695. // `len` requires the field value to have the specified length in bytes.
  3696. // If the field value doesn't match, an error message is generated.
  3697. //
  3698. // ```proto
  3699. // message MyBytes {
  3700. // // value length must be 4 bytes.
  3701. // optional bytes value = 1 [(buf.validate.field).bytes.len = 4];
  3702. // }
  3703. // ```
  3704. optional uint64 len = 13 [(predefined).cel = {
  3705. id: "bytes.len"
  3706. expression: "uint(this.size()) != rules.len ? 'value length must be %s bytes'.format([rules.len]) : ''"
  3707. }];
  3708. // `min_len` requires the field value to have at least the specified minimum
  3709. // length in bytes.
  3710. // If the field value doesn't meet the requirement, an error message is generated.
  3711. //
  3712. // ```proto
  3713. // message MyBytes {
  3714. // // value length must be at least 2 bytes.
  3715. // optional bytes value = 1 [(buf.validate.field).bytes.min_len = 2];
  3716. // }
  3717. // ```
  3718. optional uint64 min_len = 2 [(predefined).cel = {
  3719. id: "bytes.min_len"
  3720. expression: "uint(this.size()) < rules.min_len ? 'value length must be at least %s bytes'.format([rules.min_len]) : ''"
  3721. }];
  3722. // `max_len` requires the field value to have at most the specified maximum
  3723. // length in bytes.
  3724. // If the field value exceeds the requirement, an error message is generated.
  3725. //
  3726. // ```proto
  3727. // message MyBytes {
  3728. // // value must be at most 6 bytes.
  3729. // optional bytes value = 1 [(buf.validate.field).bytes.max_len = 6];
  3730. // }
  3731. // ```
  3732. optional uint64 max_len = 3 [(predefined).cel = {
  3733. id: "bytes.max_len"
  3734. expression: "uint(this.size()) > rules.max_len ? 'value must be at most %s bytes'.format([rules.max_len]) : ''"
  3735. }];
  3736. // `pattern` requires the field value to match the specified regular
  3737. // expression ([RE2 syntax](https://github.com/google/re2/wiki/Syntax)).
  3738. // The value of the field must be valid UTF-8 or validation will fail with a
  3739. // runtime error.
  3740. // If the field value doesn't match the pattern, an error message is generated.
  3741. //
  3742. // ```proto
  3743. // message MyBytes {
  3744. // // value must match regex pattern "^[a-zA-Z0-9]+$".
  3745. // optional bytes value = 1 [(buf.validate.field).bytes.pattern = "^[a-zA-Z0-9]+$"];
  3746. // }
  3747. // ```
  3748. optional string pattern = 4 [(predefined).cel = {
  3749. id: "bytes.pattern"
  3750. expression: "!string(this).matches(rules.pattern) ? 'value must match regex pattern `%s`'.format([rules.pattern]) : ''"
  3751. }];
  3752. // `prefix` requires the field value to have the specified bytes at the
  3753. // beginning of the string.
  3754. // If the field value doesn't meet the requirement, an error message is generated.
  3755. //
  3756. // ```proto
  3757. // message MyBytes {
  3758. // // value does not have prefix \x01\x02
  3759. // optional bytes value = 1 [(buf.validate.field).bytes.prefix = "\x01\x02"];
  3760. // }
  3761. // ```
  3762. optional bytes prefix = 5 [(predefined).cel = {
  3763. id: "bytes.prefix"
  3764. expression: "!this.startsWith(rules.prefix) ? 'value does not have prefix %x'.format([rules.prefix]) : ''"
  3765. }];
  3766. // `suffix` requires the field value to have the specified bytes at the end
  3767. // of the string.
  3768. // If the field value doesn't meet the requirement, an error message is generated.
  3769. //
  3770. // ```proto
  3771. // message MyBytes {
  3772. // // value does not have suffix \x03\x04
  3773. // optional bytes value = 1 [(buf.validate.field).bytes.suffix = "\x03\x04"];
  3774. // }
  3775. // ```
  3776. optional bytes suffix = 6 [(predefined).cel = {
  3777. id: "bytes.suffix"
  3778. expression: "!this.endsWith(rules.suffix) ? 'value does not have suffix %x'.format([rules.suffix]) : ''"
  3779. }];
  3780. // `contains` requires the field value to have the specified bytes anywhere in
  3781. // the string.
  3782. // If the field value doesn't meet the requirement, an error message is generated.
  3783. //
  3784. // ```protobuf
  3785. // message MyBytes {
  3786. // // value does not contain \x02\x03
  3787. // optional bytes value = 1 [(buf.validate.field).bytes.contains = "\x02\x03"];
  3788. // }
  3789. // ```
  3790. optional bytes contains = 7 [(predefined).cel = {
  3791. id: "bytes.contains"
  3792. expression: "!this.contains(rules.contains) ? 'value does not contain %x'.format([rules.contains]) : ''"
  3793. }];
  3794. // `in` requires the field value to be equal to one of the specified
  3795. // values. If the field value doesn't match any of the specified values, an
  3796. // error message is generated.
  3797. //
  3798. // ```protobuf
  3799. // message MyBytes {
  3800. // // value must in ["\x01\x02", "\x02\x03", "\x03\x04"]
  3801. // optional bytes value = 1 [(buf.validate.field).bytes.in = {"\x01\x02", "\x02\x03", "\x03\x04"}];
  3802. // }
  3803. // ```
  3804. repeated bytes in = 8 [(predefined).cel = {
  3805. id: "bytes.in"
  3806. expression: "getField(rules, 'in').size() > 0 && !(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
  3807. }];
  3808. // `not_in` requires the field value to be not equal to any of the specified
  3809. // values.
  3810. // If the field value matches any of the specified values, an error message is
  3811. // generated.
  3812. //
  3813. // ```proto
  3814. // message MyBytes {
  3815. // // value must not in ["\x01\x02", "\x02\x03", "\x03\x04"]
  3816. // optional bytes value = 1 [(buf.validate.field).bytes.not_in = {"\x01\x02", "\x02\x03", "\x03\x04"}];
  3817. // }
  3818. // ```
  3819. repeated bytes not_in = 9 [(predefined).cel = {
  3820. id: "bytes.not_in"
  3821. expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''"
  3822. }];
  3823. // WellKnown rules provide advanced rules against common byte
  3824. // patterns
  3825. oneof well_known {
  3826. // `ip` ensures that the field `value` is a valid IP address (v4 or v6) in byte format.
  3827. // If the field value doesn't meet this rule, an error message is generated.
  3828. //
  3829. // ```proto
  3830. // message MyBytes {
  3831. // // value must be a valid IP address
  3832. // optional bytes value = 1 [(buf.validate.field).bytes.ip = true];
  3833. // }
  3834. // ```
  3835. bool ip = 10 [
  3836. (predefined).cel = {
  3837. id: "bytes.ip"
  3838. message: "value must be a valid IP address"
  3839. expression: "!rules.ip || this.size() == 0 || this.size() == 4 || this.size() == 16"
  3840. },
  3841. (predefined).cel = {
  3842. id: "bytes.ip_empty"
  3843. message: "value is empty, which is not a valid IP address"
  3844. expression: "!rules.ip || this.size() != 0"
  3845. }
  3846. ];
  3847. // `ipv4` ensures that the field `value` is a valid IPv4 address in byte format.
  3848. // If the field value doesn't meet this rule, an error message is generated.
  3849. //
  3850. // ```proto
  3851. // message MyBytes {
  3852. // // value must be a valid IPv4 address
  3853. // optional bytes value = 1 [(buf.validate.field).bytes.ipv4 = true];
  3854. // }
  3855. // ```
  3856. bool ipv4 = 11 [
  3857. (predefined).cel = {
  3858. id: "bytes.ipv4"
  3859. message: "value must be a valid IPv4 address"
  3860. expression: "!rules.ipv4 || this.size() == 0 || this.size() == 4"
  3861. },
  3862. (predefined).cel = {
  3863. id: "bytes.ipv4_empty"
  3864. message: "value is empty, which is not a valid IPv4 address"
  3865. expression: "!rules.ipv4 || this.size() != 0"
  3866. }
  3867. ];
  3868. // `ipv6` ensures that the field `value` is a valid IPv6 address in byte format.
  3869. // If the field value doesn't meet this rule, an error message is generated.
  3870. // ```proto
  3871. // message MyBytes {
  3872. // // value must be a valid IPv6 address
  3873. // optional bytes value = 1 [(buf.validate.field).bytes.ipv6 = true];
  3874. // }
  3875. // ```
  3876. bool ipv6 = 12 [
  3877. (predefined).cel = {
  3878. id: "bytes.ipv6"
  3879. message: "value must be a valid IPv6 address"
  3880. expression: "!rules.ipv6 || this.size() == 0 || this.size() == 16"
  3881. },
  3882. (predefined).cel = {
  3883. id: "bytes.ipv6_empty"
  3884. message: "value is empty, which is not a valid IPv6 address"
  3885. expression: "!rules.ipv6 || this.size() != 0"
  3886. }
  3887. ];
  3888. }
  3889. // `example` specifies values that the field may have. These values SHOULD
  3890. // conform to other rules. `example` values will not impact validation
  3891. // but may be used as helpful guidance on how to populate the given field.
  3892. //
  3893. // ```proto
  3894. // message MyBytes {
  3895. // bytes value = 1 [
  3896. // (buf.validate.field).bytes.example = "\x01\x02",
  3897. // (buf.validate.field).bytes.example = "\x02\x03"
  3898. // ];
  3899. // }
  3900. // ```
  3901. repeated bytes example = 14 [(predefined).cel = {
  3902. id: "bytes.example"
  3903. expression: "true"
  3904. }];
  3905. // Extension fields in this range that have the (buf.validate.predefined)
  3906. // option set will be treated as predefined field rules that can then be
  3907. // set on the field options of other fields to apply field rules.
  3908. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  3909. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  3910. // above this range are reserved for extension numbers that are not explicitly
  3911. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  3912. // above 99999 is discouraged due to the risk of conflicts.
  3913. //
  3914. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  3915. extensions 1000 to max;
  3916. }
  3917. // EnumRules describe the rules applied to `enum` values.
  3918. message EnumRules {
  3919. // `const` requires the field value to exactly match the specified enum value.
  3920. // If the field value doesn't match, an error message is generated.
  3921. //
  3922. // ```proto
  3923. // enum MyEnum {
  3924. // MY_ENUM_UNSPECIFIED = 0;
  3925. // MY_ENUM_VALUE1 = 1;
  3926. // MY_ENUM_VALUE2 = 2;
  3927. // }
  3928. //
  3929. // message MyMessage {
  3930. // // The field `value` must be exactly MY_ENUM_VALUE1.
  3931. // MyEnum value = 1 [(buf.validate.field).enum.const = 1];
  3932. // }
  3933. // ```
  3934. optional int32 const = 1 [(predefined).cel = {
  3935. id: "enum.const"
  3936. expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
  3937. }];
  3938. // `defined_only` requires the field value to be one of the defined values for
  3939. // this enum, failing on any undefined value.
  3940. //
  3941. // ```proto
  3942. // enum MyEnum {
  3943. // MY_ENUM_UNSPECIFIED = 0;
  3944. // MY_ENUM_VALUE1 = 1;
  3945. // MY_ENUM_VALUE2 = 2;
  3946. // }
  3947. //
  3948. // message MyMessage {
  3949. // // The field `value` must be a defined value of MyEnum.
  3950. // MyEnum value = 1 [(buf.validate.field).enum.defined_only = true];
  3951. // }
  3952. // ```
  3953. optional bool defined_only = 2;
  3954. // `in` requires the field value to be equal to one of the
  3955. //specified enum values. If the field value doesn't match any of the
  3956. //specified values, an error message is generated.
  3957. //
  3958. // ```proto
  3959. // enum MyEnum {
  3960. // MY_ENUM_UNSPECIFIED = 0;
  3961. // MY_ENUM_VALUE1 = 1;
  3962. // MY_ENUM_VALUE2 = 2;
  3963. // }
  3964. //
  3965. // message MyMessage {
  3966. // // The field `value` must be equal to one of the specified values.
  3967. // MyEnum value = 1 [(buf.validate.field).enum = { in: [1, 2]}];
  3968. // }
  3969. // ```
  3970. repeated int32 in = 3 [(predefined).cel = {
  3971. id: "enum.in"
  3972. expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
  3973. }];
  3974. // `not_in` requires the field value to be not equal to any of the
  3975. //specified enum values. If the field value matches one of the specified
  3976. // values, an error message is generated.
  3977. //
  3978. // ```proto
  3979. // enum MyEnum {
  3980. // MY_ENUM_UNSPECIFIED = 0;
  3981. // MY_ENUM_VALUE1 = 1;
  3982. // MY_ENUM_VALUE2 = 2;
  3983. // }
  3984. //
  3985. // message MyMessage {
  3986. // // The field `value` must not be equal to any of the specified values.
  3987. // MyEnum value = 1 [(buf.validate.field).enum = { not_in: [1, 2]}];
  3988. // }
  3989. // ```
  3990. repeated int32 not_in = 4 [(predefined).cel = {
  3991. id: "enum.not_in"
  3992. expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''"
  3993. }];
  3994. // `example` specifies values that the field may have. These values SHOULD
  3995. // conform to other rules. `example` values will not impact validation
  3996. // but may be used as helpful guidance on how to populate the given field.
  3997. //
  3998. // ```proto
  3999. // enum MyEnum {
  4000. // MY_ENUM_UNSPECIFIED = 0;
  4001. // MY_ENUM_VALUE1 = 1;
  4002. // MY_ENUM_VALUE2 = 2;
  4003. // }
  4004. //
  4005. // message MyMessage {
  4006. // (buf.validate.field).enum.example = 1,
  4007. // (buf.validate.field).enum.example = 2
  4008. // }
  4009. // ```
  4010. repeated int32 example = 5 [(predefined).cel = {
  4011. id: "enum.example"
  4012. expression: "true"
  4013. }];
  4014. // Extension fields in this range that have the (buf.validate.predefined)
  4015. // option set will be treated as predefined field rules that can then be
  4016. // set on the field options of other fields to apply field rules.
  4017. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  4018. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  4019. // above this range are reserved for extension numbers that are not explicitly
  4020. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  4021. // above 99999 is discouraged due to the risk of conflicts.
  4022. //
  4023. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  4024. extensions 1000 to max;
  4025. }
  4026. // RepeatedRules describe the rules applied to `repeated` values.
  4027. message RepeatedRules {
  4028. // `min_items` requires that this field must contain at least the specified
  4029. // minimum number of items.
  4030. //
  4031. // Note that `min_items = 1` is equivalent to setting a field as `required`.
  4032. //
  4033. // ```proto
  4034. // message MyRepeated {
  4035. // // value must contain at least 2 items
  4036. // repeated string value = 1 [(buf.validate.field).repeated.min_items = 2];
  4037. // }
  4038. // ```
  4039. optional uint64 min_items = 1 [(predefined).cel = {
  4040. id: "repeated.min_items"
  4041. expression: "uint(this.size()) < rules.min_items ? 'value must contain at least %d item(s)'.format([rules.min_items]) : ''"
  4042. }];
  4043. // `max_items` denotes that this field must not exceed a
  4044. // certain number of items as the upper limit. If the field contains more
  4045. // items than specified, an error message will be generated, requiring the
  4046. // field to maintain no more than the specified number of items.
  4047. //
  4048. // ```proto
  4049. // message MyRepeated {
  4050. // // value must contain no more than 3 item(s)
  4051. // repeated string value = 1 [(buf.validate.field).repeated.max_items = 3];
  4052. // }
  4053. // ```
  4054. optional uint64 max_items = 2 [(predefined).cel = {
  4055. id: "repeated.max_items"
  4056. expression: "uint(this.size()) > rules.max_items ? 'value must contain no more than %s item(s)'.format([rules.max_items]) : ''"
  4057. }];
  4058. // `unique` indicates that all elements in this field must
  4059. // be unique. This rule is strictly applicable to scalar and enum
  4060. // types, with message types not being supported.
  4061. //
  4062. // ```proto
  4063. // message MyRepeated {
  4064. // // repeated value must contain unique items
  4065. // repeated string value = 1 [(buf.validate.field).repeated.unique = true];
  4066. // }
  4067. // ```
  4068. optional bool unique = 3 [(predefined).cel = {
  4069. id: "repeated.unique"
  4070. message: "repeated value must contain unique items"
  4071. expression: "!rules.unique || this.unique()"
  4072. }];
  4073. // `items` details the rules to be applied to each item
  4074. // in the field. Even for repeated message fields, validation is executed
  4075. // against each item unless `ignore` is specified.
  4076. //
  4077. // ```proto
  4078. // message MyRepeated {
  4079. // // The items in the field `value` must follow the specified rules.
  4080. // repeated string value = 1 [(buf.validate.field).repeated.items = {
  4081. // string: {
  4082. // min_len: 3
  4083. // max_len: 10
  4084. // }
  4085. // }];
  4086. // }
  4087. // ```
  4088. //
  4089. // Note that the `required` rule does not apply. Repeated items
  4090. // cannot be unset.
  4091. optional FieldRules items = 4;
  4092. // Extension fields in this range that have the (buf.validate.predefined)
  4093. // option set will be treated as predefined field rules that can then be
  4094. // set on the field options of other fields to apply field rules.
  4095. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  4096. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  4097. // above this range are reserved for extension numbers that are not explicitly
  4098. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  4099. // above 99999 is discouraged due to the risk of conflicts.
  4100. //
  4101. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  4102. extensions 1000 to max;
  4103. }
  4104. // MapRules describe the rules applied to `map` values.
  4105. message MapRules {
  4106. // Specifies the minimum number of key-value pairs allowed. If the field has
  4107. // fewer key-value pairs than specified, an error message is generated.
  4108. //
  4109. // ```proto
  4110. // message MyMap {
  4111. // // The field `value` must have at least 2 key-value pairs.
  4112. // map<string, string> value = 1 [(buf.validate.field).map.min_pairs = 2];
  4113. // }
  4114. // ```
  4115. optional uint64 min_pairs = 1 [(predefined).cel = {
  4116. id: "map.min_pairs"
  4117. expression: "uint(this.size()) < rules.min_pairs ? 'map must be at least %d entries'.format([rules.min_pairs]) : ''"
  4118. }];
  4119. // Specifies the maximum number of key-value pairs allowed. If the field has
  4120. // more key-value pairs than specified, an error message is generated.
  4121. //
  4122. // ```proto
  4123. // message MyMap {
  4124. // // The field `value` must have at most 3 key-value pairs.
  4125. // map<string, string> value = 1 [(buf.validate.field).map.max_pairs = 3];
  4126. // }
  4127. // ```
  4128. optional uint64 max_pairs = 2 [(predefined).cel = {
  4129. id: "map.max_pairs"
  4130. expression: "uint(this.size()) > rules.max_pairs ? 'map must be at most %d entries'.format([rules.max_pairs]) : ''"
  4131. }];
  4132. // Specifies the rules to be applied to each key in the field.
  4133. //
  4134. // ```proto
  4135. // message MyMap {
  4136. // // The keys in the field `value` must follow the specified rules.
  4137. // map<string, string> value = 1 [(buf.validate.field).map.keys = {
  4138. // string: {
  4139. // min_len: 3
  4140. // max_len: 10
  4141. // }
  4142. // }];
  4143. // }
  4144. // ```
  4145. //
  4146. // Note that the `required` rule does not apply. Map keys cannot be unset.
  4147. optional FieldRules keys = 4;
  4148. // Specifies the rules to be applied to the value of each key in the
  4149. // field. Message values will still have their validations evaluated unless
  4150. // `ignore` is specified.
  4151. //
  4152. // ```proto
  4153. // message MyMap {
  4154. // // The values in the field `value` must follow the specified rules.
  4155. // map<string, string> value = 1 [(buf.validate.field).map.values = {
  4156. // string: {
  4157. // min_len: 5
  4158. // max_len: 20
  4159. // }
  4160. // }];
  4161. // }
  4162. // ```
  4163. // Note that the `required` rule does not apply. Map values cannot be unset.
  4164. optional FieldRules values = 5;
  4165. // Extension fields in this range that have the (buf.validate.predefined)
  4166. // option set will be treated as predefined field rules that can then be
  4167. // set on the field options of other fields to apply field rules.
  4168. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  4169. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  4170. // above this range are reserved for extension numbers that are not explicitly
  4171. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  4172. // above 99999 is discouraged due to the risk of conflicts.
  4173. //
  4174. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  4175. extensions 1000 to max;
  4176. }
  4177. // AnyRules describe rules applied exclusively to the `google.protobuf.Any` well-known type.
  4178. message AnyRules {
  4179. // `in` requires the field's `type_url` to be equal to one of the
  4180. //specified values. If it doesn't match any of the specified values, an error
  4181. // message is generated.
  4182. //
  4183. // ```proto
  4184. // message MyAny {
  4185. // // The `value` field must have a `type_url` equal to one of the specified values.
  4186. // google.protobuf.Any value = 1 [(buf.validate.field).any = {
  4187. // in: ["type.googleapis.com/MyType1", "type.googleapis.com/MyType2"]
  4188. // }];
  4189. // }
  4190. // ```
  4191. repeated string in = 2;
  4192. // 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.
  4193. //
  4194. // ```proto
  4195. // message MyAny {
  4196. // // The `value` field must not have a `type_url` equal to any of the specified values.
  4197. // google.protobuf.Any value = 1 [(buf.validate.field).any = {
  4198. // not_in: ["type.googleapis.com/ForbiddenType1", "type.googleapis.com/ForbiddenType2"]
  4199. // }];
  4200. // }
  4201. // ```
  4202. repeated string not_in = 3;
  4203. }
  4204. // DurationRules describe the rules applied exclusively to the `google.protobuf.Duration` well-known type.
  4205. message DurationRules {
  4206. // `const` dictates that the field must match the specified value of the `google.protobuf.Duration` type exactly.
  4207. // If the field's value deviates from the specified value, an error message
  4208. // will be generated.
  4209. //
  4210. // ```proto
  4211. // message MyDuration {
  4212. // // value must equal 5s
  4213. // google.protobuf.Duration value = 1 [(buf.validate.field).duration.const = "5s"];
  4214. // }
  4215. // ```
  4216. optional google.protobuf.Duration const = 2 [(predefined).cel = {
  4217. id: "duration.const"
  4218. expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
  4219. }];
  4220. oneof less_than {
  4221. // `lt` stipulates that the field must be less than the specified value of the `google.protobuf.Duration` type,
  4222. // exclusive. If the field's value is greater than or equal to the specified
  4223. // value, an error message will be generated.
  4224. //
  4225. // ```proto
  4226. // message MyDuration {
  4227. // // value must be less than 5s
  4228. // google.protobuf.Duration value = 1 [(buf.validate.field).duration.lt = "5s"];
  4229. // }
  4230. // ```
  4231. google.protobuf.Duration lt = 3 [(predefined).cel = {
  4232. id: "duration.lt"
  4233. expression:
  4234. "!has(rules.gte) && !has(rules.gt) && this >= rules.lt"
  4235. "? 'value must be less than %s'.format([rules.lt]) : ''"
  4236. }];
  4237. // `lte` indicates that the field must be less than or equal to the specified
  4238. // value of the `google.protobuf.Duration` type, inclusive. If the field's value is greater than the specified value,
  4239. // an error message will be generated.
  4240. //
  4241. // ```proto
  4242. // message MyDuration {
  4243. // // value must be less than or equal to 10s
  4244. // google.protobuf.Duration value = 1 [(buf.validate.field).duration.lte = "10s"];
  4245. // }
  4246. // ```
  4247. google.protobuf.Duration lte = 4 [(predefined).cel = {
  4248. id: "duration.lte"
  4249. expression:
  4250. "!has(rules.gte) && !has(rules.gt) && this > rules.lte"
  4251. "? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
  4252. }];
  4253. }
  4254. oneof greater_than {
  4255. // `gt` requires the duration field value to be greater than the specified
  4256. // value (exclusive). If the value of `gt` is larger than a specified `lt`
  4257. // or `lte`, the range is reversed, and the field value must be outside the
  4258. // specified range. If the field value doesn't meet the required conditions,
  4259. // an error message is generated.
  4260. //
  4261. // ```proto
  4262. // message MyDuration {
  4263. // // duration must be greater than 5s [duration.gt]
  4264. // google.protobuf.Duration value = 1 [(buf.validate.field).duration.gt = { seconds: 5 }];
  4265. //
  4266. // // duration must be greater than 5s and less than 10s [duration.gt_lt]
  4267. // google.protobuf.Duration another_value = 2 [(buf.validate.field).duration = { gt: { seconds: 5 }, lt: { seconds: 10 } }];
  4268. //
  4269. // // duration must be greater than 10s or less than 5s [duration.gt_lt_exclusive]
  4270. // google.protobuf.Duration other_value = 3 [(buf.validate.field).duration = { gt: { seconds: 10 }, lt: { seconds: 5 } }];
  4271. // }
  4272. // ```
  4273. google.protobuf.Duration gt = 5 [
  4274. (predefined).cel = {
  4275. id: "duration.gt"
  4276. expression:
  4277. "!has(rules.lt) && !has(rules.lte) && this <= rules.gt"
  4278. "? 'value must be greater than %s'.format([rules.gt]) : ''"
  4279. },
  4280. (predefined).cel = {
  4281. id: "duration.gt_lt"
  4282. expression:
  4283. "has(rules.lt) && rules.lt >= rules.gt && (this >= rules.lt || this <= rules.gt)"
  4284. "? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
  4285. },
  4286. (predefined).cel = {
  4287. id: "duration.gt_lt_exclusive"
  4288. expression:
  4289. "has(rules.lt) && rules.lt < rules.gt && (rules.lt <= this && this <= rules.gt)"
  4290. "? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
  4291. },
  4292. (predefined).cel = {
  4293. id: "duration.gt_lte"
  4294. expression:
  4295. "has(rules.lte) && rules.lte >= rules.gt && (this > rules.lte || this <= rules.gt)"
  4296. "? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  4297. },
  4298. (predefined).cel = {
  4299. id: "duration.gt_lte_exclusive"
  4300. expression:
  4301. "has(rules.lte) && rules.lte < rules.gt && (rules.lte < this && this <= rules.gt)"
  4302. "? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  4303. }
  4304. ];
  4305. // `gte` requires the duration field value to be greater than or equal to the
  4306. // specified value (exclusive). If the value of `gte` is larger than a
  4307. // specified `lt` or `lte`, the range is reversed, and the field value must
  4308. // be outside the specified range. If the field value doesn't meet the
  4309. // required conditions, an error message is generated.
  4310. //
  4311. // ```proto
  4312. // message MyDuration {
  4313. // // duration must be greater than or equal to 5s [duration.gte]
  4314. // google.protobuf.Duration value = 1 [(buf.validate.field).duration.gte = { seconds: 5 }];
  4315. //
  4316. // // duration must be greater than or equal to 5s and less than 10s [duration.gte_lt]
  4317. // google.protobuf.Duration another_value = 2 [(buf.validate.field).duration = { gte: { seconds: 5 }, lt: { seconds: 10 } }];
  4318. //
  4319. // // duration must be greater than or equal to 10s or less than 5s [duration.gte_lt_exclusive]
  4320. // google.protobuf.Duration other_value = 3 [(buf.validate.field).duration = { gte: { seconds: 10 }, lt: { seconds: 5 } }];
  4321. // }
  4322. // ```
  4323. google.protobuf.Duration gte = 6 [
  4324. (predefined).cel = {
  4325. id: "duration.gte"
  4326. expression:
  4327. "!has(rules.lt) && !has(rules.lte) && this < rules.gte"
  4328. "? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
  4329. },
  4330. (predefined).cel = {
  4331. id: "duration.gte_lt"
  4332. expression:
  4333. "has(rules.lt) && rules.lt >= rules.gte && (this >= rules.lt || this < rules.gte)"
  4334. "? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
  4335. },
  4336. (predefined).cel = {
  4337. id: "duration.gte_lt_exclusive"
  4338. expression:
  4339. "has(rules.lt) && rules.lt < rules.gte && (rules.lt <= this && this < rules.gte)"
  4340. "? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
  4341. },
  4342. (predefined).cel = {
  4343. id: "duration.gte_lte"
  4344. expression:
  4345. "has(rules.lte) && rules.lte >= rules.gte && (this > rules.lte || this < rules.gte)"
  4346. "? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  4347. },
  4348. (predefined).cel = {
  4349. id: "duration.gte_lte_exclusive"
  4350. expression:
  4351. "has(rules.lte) && rules.lte < rules.gte && (rules.lte < this && this < rules.gte)"
  4352. "? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  4353. }
  4354. ];
  4355. }
  4356. // `in` asserts that the field must be equal to one of the specified values of the `google.protobuf.Duration` type.
  4357. // If the field's value doesn't correspond to any of the specified values,
  4358. // an error message will be generated.
  4359. //
  4360. // ```proto
  4361. // message MyDuration {
  4362. // // value must be in list [1s, 2s, 3s]
  4363. // google.protobuf.Duration value = 1 [(buf.validate.field).duration.in = ["1s", "2s", "3s"]];
  4364. // }
  4365. // ```
  4366. repeated google.protobuf.Duration in = 7 [(predefined).cel = {
  4367. id: "duration.in"
  4368. expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
  4369. }];
  4370. // `not_in` denotes that the field must not be equal to
  4371. // any of the specified values of the `google.protobuf.Duration` type.
  4372. // If the field's value matches any of these values, an error message will be
  4373. // generated.
  4374. //
  4375. // ```proto
  4376. // message MyDuration {
  4377. // // value must not be in list [1s, 2s, 3s]
  4378. // google.protobuf.Duration value = 1 [(buf.validate.field).duration.not_in = ["1s", "2s", "3s"]];
  4379. // }
  4380. // ```
  4381. repeated google.protobuf.Duration not_in = 8 [(predefined).cel = {
  4382. id: "duration.not_in"
  4383. expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''"
  4384. }];
  4385. // `example` specifies values that the field may have. These values SHOULD
  4386. // conform to other rules. `example` values will not impact validation
  4387. // but may be used as helpful guidance on how to populate the given field.
  4388. //
  4389. // ```proto
  4390. // message MyDuration {
  4391. // google.protobuf.Duration value = 1 [
  4392. // (buf.validate.field).duration.example = { seconds: 1 },
  4393. // (buf.validate.field).duration.example = { seconds: 2 },
  4394. // ];
  4395. // }
  4396. // ```
  4397. repeated google.protobuf.Duration example = 9 [(predefined).cel = {
  4398. id: "duration.example"
  4399. expression: "true"
  4400. }];
  4401. // Extension fields in this range that have the (buf.validate.predefined)
  4402. // option set will be treated as predefined field rules that can then be
  4403. // set on the field options of other fields to apply field rules.
  4404. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  4405. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  4406. // above this range are reserved for extension numbers that are not explicitly
  4407. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  4408. // above 99999 is discouraged due to the risk of conflicts.
  4409. //
  4410. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  4411. extensions 1000 to max;
  4412. }
  4413. // TimestampRules describe the rules applied exclusively to the `google.protobuf.Timestamp` well-known type.
  4414. message TimestampRules {
  4415. // `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.
  4416. //
  4417. // ```proto
  4418. // message MyTimestamp {
  4419. // // value must equal 2023-05-03T10:00:00Z
  4420. // google.protobuf.Timestamp created_at = 1 [(buf.validate.field).timestamp.const = {seconds: 1727998800}];
  4421. // }
  4422. // ```
  4423. optional google.protobuf.Timestamp const = 2 [(predefined).cel = {
  4424. id: "timestamp.const"
  4425. expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
  4426. }];
  4427. oneof less_than {
  4428. // 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.
  4429. //
  4430. // ```proto
  4431. // message MyDuration {
  4432. // // duration must be less than 'P3D' [duration.lt]
  4433. // google.protobuf.Duration value = 1 [(buf.validate.field).duration.lt = { seconds: 259200 }];
  4434. // }
  4435. // ```
  4436. google.protobuf.Timestamp lt = 3 [(predefined).cel = {
  4437. id: "timestamp.lt"
  4438. expression:
  4439. "!has(rules.gte) && !has(rules.gt) && this >= rules.lt"
  4440. "? 'value must be less than %s'.format([rules.lt]) : ''"
  4441. }];
  4442. // 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.
  4443. //
  4444. // ```proto
  4445. // message MyTimestamp {
  4446. // // timestamp must be less than or equal to '2023-05-14T00:00:00Z' [timestamp.lte]
  4447. // google.protobuf.Timestamp value = 1 [(buf.validate.field).timestamp.lte = { seconds: 1678867200 }];
  4448. // }
  4449. // ```
  4450. google.protobuf.Timestamp lte = 4 [(predefined).cel = {
  4451. id: "timestamp.lte"
  4452. expression:
  4453. "!has(rules.gte) && !has(rules.gt) && this > rules.lte"
  4454. "? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
  4455. }];
  4456. // `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.
  4457. //
  4458. // ```proto
  4459. // message MyTimestamp {
  4460. // // value must be less than now
  4461. // google.protobuf.Timestamp created_at = 1 [(buf.validate.field).timestamp.lt_now = true];
  4462. // }
  4463. // ```
  4464. bool lt_now = 7 [(predefined).cel = {
  4465. id: "timestamp.lt_now"
  4466. expression: "(rules.lt_now && this > now) ? 'value must be less than now' : ''"
  4467. }];
  4468. }
  4469. oneof greater_than {
  4470. // `gt` requires the timestamp field value to be greater than the specified
  4471. // value (exclusive). If the value of `gt` is larger than a specified `lt`
  4472. // or `lte`, the range is reversed, and the field value must be outside the
  4473. // specified range. If the field value doesn't meet the required conditions,
  4474. // an error message is generated.
  4475. //
  4476. // ```proto
  4477. // message MyTimestamp {
  4478. // // timestamp must be greater than '2023-01-01T00:00:00Z' [timestamp.gt]
  4479. // google.protobuf.Timestamp value = 1 [(buf.validate.field).timestamp.gt = { seconds: 1672444800 }];
  4480. //
  4481. // // timestamp must be greater than '2023-01-01T00:00:00Z' and less than '2023-01-02T00:00:00Z' [timestamp.gt_lt]
  4482. // google.protobuf.Timestamp another_value = 2 [(buf.validate.field).timestamp = { gt: { seconds: 1672444800 }, lt: { seconds: 1672531200 } }];
  4483. //
  4484. // // timestamp must be greater than '2023-01-02T00:00:00Z' or less than '2023-01-01T00:00:00Z' [timestamp.gt_lt_exclusive]
  4485. // google.protobuf.Timestamp other_value = 3 [(buf.validate.field).timestamp = { gt: { seconds: 1672531200 }, lt: { seconds: 1672444800 } }];
  4486. // }
  4487. // ```
  4488. google.protobuf.Timestamp gt = 5 [
  4489. (predefined).cel = {
  4490. id: "timestamp.gt"
  4491. expression:
  4492. "!has(rules.lt) && !has(rules.lte) && this <= rules.gt"
  4493. "? 'value must be greater than %s'.format([rules.gt]) : ''"
  4494. },
  4495. (predefined).cel = {
  4496. id: "timestamp.gt_lt"
  4497. expression:
  4498. "has(rules.lt) && rules.lt >= rules.gt && (this >= rules.lt || this <= rules.gt)"
  4499. "? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
  4500. },
  4501. (predefined).cel = {
  4502. id: "timestamp.gt_lt_exclusive"
  4503. expression:
  4504. "has(rules.lt) && rules.lt < rules.gt && (rules.lt <= this && this <= rules.gt)"
  4505. "? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
  4506. },
  4507. (predefined).cel = {
  4508. id: "timestamp.gt_lte"
  4509. expression:
  4510. "has(rules.lte) && rules.lte >= rules.gt && (this > rules.lte || this <= rules.gt)"
  4511. "? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  4512. },
  4513. (predefined).cel = {
  4514. id: "timestamp.gt_lte_exclusive"
  4515. expression:
  4516. "has(rules.lte) && rules.lte < rules.gt && (rules.lte < this && this <= rules.gt)"
  4517. "? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
  4518. }
  4519. ];
  4520. // `gte` requires the timestamp field value to be greater than or equal to the
  4521. // specified value (exclusive). If the value of `gte` is larger than a
  4522. // specified `lt` or `lte`, the range is reversed, and the field value
  4523. // must be outside the specified range. If the field value doesn't meet
  4524. // the required conditions, an error message is generated.
  4525. //
  4526. // ```proto
  4527. // message MyTimestamp {
  4528. // // timestamp must be greater than or equal to '2023-01-01T00:00:00Z' [timestamp.gte]
  4529. // google.protobuf.Timestamp value = 1 [(buf.validate.field).timestamp.gte = { seconds: 1672444800 }];
  4530. //
  4531. // // timestamp must be greater than or equal to '2023-01-01T00:00:00Z' and less than '2023-01-02T00:00:00Z' [timestamp.gte_lt]
  4532. // google.protobuf.Timestamp another_value = 2 [(buf.validate.field).timestamp = { gte: { seconds: 1672444800 }, lt: { seconds: 1672531200 } }];
  4533. //
  4534. // // 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]
  4535. // google.protobuf.Timestamp other_value = 3 [(buf.validate.field).timestamp = { gte: { seconds: 1672531200 }, lt: { seconds: 1672444800 } }];
  4536. // }
  4537. // ```
  4538. google.protobuf.Timestamp gte = 6 [
  4539. (predefined).cel = {
  4540. id: "timestamp.gte"
  4541. expression:
  4542. "!has(rules.lt) && !has(rules.lte) && this < rules.gte"
  4543. "? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
  4544. },
  4545. (predefined).cel = {
  4546. id: "timestamp.gte_lt"
  4547. expression:
  4548. "has(rules.lt) && rules.lt >= rules.gte && (this >= rules.lt || this < rules.gte)"
  4549. "? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
  4550. },
  4551. (predefined).cel = {
  4552. id: "timestamp.gte_lt_exclusive"
  4553. expression:
  4554. "has(rules.lt) && rules.lt < rules.gte && (rules.lt <= this && this < rules.gte)"
  4555. "? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
  4556. },
  4557. (predefined).cel = {
  4558. id: "timestamp.gte_lte"
  4559. expression:
  4560. "has(rules.lte) && rules.lte >= rules.gte && (this > rules.lte || this < rules.gte)"
  4561. "? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  4562. },
  4563. (predefined).cel = {
  4564. id: "timestamp.gte_lte_exclusive"
  4565. expression:
  4566. "has(rules.lte) && rules.lte < rules.gte && (rules.lte < this && this < rules.gte)"
  4567. "? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
  4568. }
  4569. ];
  4570. // `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.
  4571. //
  4572. // ```proto
  4573. // message MyTimestamp {
  4574. // // value must be greater than now
  4575. // google.protobuf.Timestamp created_at = 1 [(buf.validate.field).timestamp.gt_now = true];
  4576. // }
  4577. // ```
  4578. bool gt_now = 8 [(predefined).cel = {
  4579. id: "timestamp.gt_now"
  4580. expression: "(rules.gt_now && this < now) ? 'value must be greater than now' : ''"
  4581. }];
  4582. }
  4583. // `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.
  4584. //
  4585. // ```proto
  4586. // message MyTimestamp {
  4587. // // value must be within 1 hour of now
  4588. // google.protobuf.Timestamp created_at = 1 [(buf.validate.field).timestamp.within = {seconds: 3600}];
  4589. // }
  4590. // ```
  4591. optional google.protobuf.Duration within = 9 [(predefined).cel = {
  4592. id: "timestamp.within"
  4593. expression: "this < now-rules.within || this > now+rules.within ? 'value must be within %s of now'.format([rules.within]) : ''"
  4594. }];
  4595. // `example` specifies values that the field may have. These values SHOULD
  4596. // conform to other rules. `example` values will not impact validation
  4597. // but may be used as helpful guidance on how to populate the given field.
  4598. //
  4599. // ```proto
  4600. // message MyTimestamp {
  4601. // google.protobuf.Timestamp value = 1 [
  4602. // (buf.validate.field).timestamp.example = { seconds: 1672444800 },
  4603. // (buf.validate.field).timestamp.example = { seconds: 1672531200 },
  4604. // ];
  4605. // }
  4606. // ```
  4607. repeated google.protobuf.Timestamp example = 10 [(predefined).cel = {
  4608. id: "timestamp.example"
  4609. expression: "true"
  4610. }];
  4611. // Extension fields in this range that have the (buf.validate.predefined)
  4612. // option set will be treated as predefined field rules that can then be
  4613. // set on the field options of other fields to apply field rules.
  4614. // Extension numbers 1000 to 99999 are reserved for extension numbers that are
  4615. // defined in the [Protobuf Global Extension Registry][1]. Extension numbers
  4616. // above this range are reserved for extension numbers that are not explicitly
  4617. // assigned. For rules defined in publicly-consumed schemas, use of extensions
  4618. // above 99999 is discouraged due to the risk of conflicts.
  4619. //
  4620. // [1]: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md
  4621. extensions 1000 to max;
  4622. }
  4623. // `Violations` is a collection of `Violation` messages. This message type is returned by
  4624. // Protovalidate when a proto message fails to meet the requirements set by the `Rule` validation rules.
  4625. // Each individual violation is represented by a `Violation` message.
  4626. message Violations {
  4627. // `violations` is a repeated field that contains all the `Violation` messages corresponding to the violations detected.
  4628. repeated Violation violations = 1;
  4629. }
  4630. // `Violation` represents a single instance where a validation rule, expressed
  4631. // as a `Rule`, was not met. It provides information about the field that
  4632. // caused the violation, the specific rule that wasn't fulfilled, and a
  4633. // human-readable error message.
  4634. //
  4635. // For example, consider the following message:
  4636. //
  4637. // ```proto
  4638. // message User {
  4639. // int32 age = 1 [(buf.validate.field).cel = {
  4640. // id: "user.age",
  4641. // expression: "this < 18 ? 'User must be at least 18 years old' : ''",
  4642. // }];
  4643. // }
  4644. // ```
  4645. //
  4646. // It could produce the following violation:
  4647. //
  4648. // ```json
  4649. // {
  4650. // "ruleId": "user.age",
  4651. // "message": "User must be at least 18 years old",
  4652. // "field": {
  4653. // "elements": [
  4654. // {
  4655. // "fieldNumber": 1,
  4656. // "fieldName": "age",
  4657. // "fieldType": "TYPE_INT32"
  4658. // }
  4659. // ]
  4660. // },
  4661. // "rule": {
  4662. // "elements": [
  4663. // {
  4664. // "fieldNumber": 23,
  4665. // "fieldName": "cel",
  4666. // "fieldType": "TYPE_MESSAGE",
  4667. // "index": "0"
  4668. // }
  4669. // ]
  4670. // }
  4671. // }
  4672. // ```
  4673. message Violation {
  4674. // `field` is a machine-readable path to the field that failed validation.
  4675. // 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.
  4676. //
  4677. // For example, consider the following message:
  4678. //
  4679. // ```proto
  4680. // message Message {
  4681. // bool a = 1 [(buf.validate.field).required = true];
  4682. // }
  4683. // ```
  4684. //
  4685. // It could produce the following violation:
  4686. //
  4687. // ```textproto
  4688. // violation {
  4689. // field { element { field_number: 1, field_name: "a", field_type: 8 } }
  4690. // ...
  4691. // }
  4692. // ```
  4693. optional FieldPath field = 5;
  4694. // `rule` is a machine-readable path that points to the specific rule that failed validation.
  4695. // This will be a nested field starting from the FieldRules of the field that failed validation.
  4696. // For custom rules, this will provide the path of the rule, e.g. `cel[0]`.
  4697. //
  4698. // For example, consider the following message:
  4699. //
  4700. // ```proto
  4701. // message Message {
  4702. // bool a = 1 [(buf.validate.field).required = true];
  4703. // bool b = 2 [(buf.validate.field).cel = {
  4704. // id: "custom_rule",
  4705. // expression: "!this ? 'b must be true': ''"
  4706. // }]
  4707. // }
  4708. // ```
  4709. //
  4710. // It could produce the following violations:
  4711. //
  4712. // ```textproto
  4713. // violation {
  4714. // rule { element { field_number: 25, field_name: "required", field_type: 8 } }
  4715. // ...
  4716. // }
  4717. // violation {
  4718. // rule { element { field_number: 23, field_name: "cel", field_type: 11, index: 0 } }
  4719. // ...
  4720. // }
  4721. // ```
  4722. optional FieldPath rule = 6;
  4723. // `rule_id` is the unique identifier of the `Rule` that was not fulfilled.
  4724. // This is the same `id` that was specified in the `Rule` message, allowing easy tracing of which rule was violated.
  4725. optional string rule_id = 2;
  4726. // `message` is a human-readable error message that describes the nature of the violation.
  4727. // This can be the default error message from the violated `Rule`, or it can be a custom message that gives more context about the violation.
  4728. optional string message = 3;
  4729. // `for_key` indicates whether the violation was caused by a map key, rather than a value.
  4730. optional bool for_key = 4;
  4731. reserved 1;
  4732. reserved "field_path";
  4733. }
  4734. // `FieldPath` provides a path to a nested protobuf field.
  4735. //
  4736. // This message provides enough information to render a dotted field path even without protobuf descriptors.
  4737. // It also provides enough information to resolve a nested field through unknown wire data.
  4738. message FieldPath {
  4739. // `elements` contains each element of the path, starting from the root and recursing downward.
  4740. repeated FieldPathElement elements = 1;
  4741. }
  4742. // `FieldPathElement` provides enough information to nest through a single protobuf field.
  4743. //
  4744. // If the selected field is a map or repeated field, the `subscript` value selects a specific element from it.
  4745. // A path that refers to a value nested under a map key or repeated field index will have a `subscript` value.
  4746. // The `field_type` field allows unambiguous resolution of a field even if descriptors are not available.
  4747. message FieldPathElement {
  4748. // `field_number` is the field number this path element refers to.
  4749. optional int32 field_number = 1;
  4750. // `field_name` contains the field name this path element refers to.
  4751. // This can be used to display a human-readable path even if the field number is unknown.
  4752. optional string field_name = 2;
  4753. // `field_type` specifies the type of this field. When using reflection, this value is not needed.
  4754. //
  4755. // This value is provided to make it possible to traverse unknown fields through wire data.
  4756. // When traversing wire data, be mindful of both packed[1] and delimited[2] encoding schemes.
  4757. //
  4758. // [1]: https://protobuf.dev/programming-guides/encoding/#packed
  4759. // [2]: https://protobuf.dev/programming-guides/encoding/#groups
  4760. //
  4761. // N.B.: Although groups are deprecated, the corresponding delimited encoding scheme is not, and
  4762. // can be explicitly used in Protocol Buffers 2023 Edition.
  4763. optional google.protobuf.FieldDescriptorProto.Type field_type = 3;
  4764. // `key_type` specifies the map key type of this field. This value is useful when traversing
  4765. // unknown fields through wire data: specifically, it allows handling the differences between
  4766. // different integer encodings.
  4767. optional google.protobuf.FieldDescriptorProto.Type key_type = 4;
  4768. // `value_type` specifies map value type of this field. This is useful if you want to display a
  4769. // value inside unknown fields through wire data.
  4770. optional google.protobuf.FieldDescriptorProto.Type value_type = 5;
  4771. // `subscript` contains a repeated index or map key, if this path element nests into a repeated or map field.
  4772. oneof subscript {
  4773. // `index` specifies a 0-based index into a repeated field.
  4774. uint64 index = 6;
  4775. // `bool_key` specifies a map key of type bool.
  4776. bool bool_key = 7;
  4777. // `int_key` specifies a map key of type int32, int64, sint32, sint64, sfixed32 or sfixed64.
  4778. int64 int_key = 8;
  4779. // `uint_key` specifies a map key of type uint32, uint64, fixed32 or fixed64.
  4780. uint64 uint_key = 9;
  4781. // `string_key` specifies a map key of type string.
  4782. string string_key = 10;
  4783. }
  4784. }