Comments (7)
If user wants to generate code with unsupported well known validator for some specific language, library could generate code which raises Not implemented error.
Yep! We do that already π https://github.com/lyft/protoc-gen-validate/blob/master/templates/cc/register.go
from protoc-gen-validate.
Why not use the existing regular expression support?
from protoc-gen-validate.
Sure, that's what I did as workaround. But due to your logic protoc-gen-validate
library shouldn't implement any well-known formats validations. All of them could be done with regexp. Just remove all of them π But it is not user-friendly I think π
I see next advantages from using golang standard library for mac validation:
- Usage of
net.ParseMAC()
gives great improvement in code readability. If you write regexp with all checks from standard function regexp will look horrible. - Users would not implement this regexp again and again. This will lead to avoiding bunch of mistakes on users' side.
- All validations will be implemented by proven function, which follows standards.
from protoc-gen-validate.
I'm not opposed to including rules for well-known formats, my concern is about cross-language support. The Go standard library is a lot more comprehensive than the C++ standard library, which I don't believe includes any sort of ParseMAC
-like utility function. To implement the validation in C++, we'd need to either depend on a library that includes such a function or write our own utility function. The problem with these is that either the library or utility function would have to be linked into every library that uses the validation code, regardless of whether or not the validation rules included MAC address validation. The problem gets worse as more languages are added (#108 adds Java as a third target language).
It might be possible to get the usability properties of saying something like (validation.rules).string.format = MAC_ADDRESS
(not currently possible) in a more language-independent way by having a set of well-known regexes, where MAC_ADDRESS maps to the appropriate one. The language-specific backends would then insert these regexes in the correct places. That addresses your second point and maybe the third, though the regex behind the nice rule declaration would still be ugly.
from protoc-gen-validate.
As @akonradi describes, this is actually a current problem with the well known string formats. The original set of them was taken from the JSON schema rules and implemented in Go using the advanced utilities of its standard library. I believe if you attempt to use most of them in C++ they'll currently blow up as unimplemented (or possibly be ignored, I don't remember).
I do believe the vast majority of them can be solved using regex (either explicitly by the end user or hidden away behind a well-known string rule); it's not too important to me how readable the generated code is, just that it is correct and is readable/ergonomic to apply the rule as an option in the IDLs.
from protoc-gen-validate.
All that said, I'm not opposed to having this added.
from protoc-gen-validate.
@akonradi, @rodaine
Thank you guys for explanation!
Looks like this is a common issue with cross languages libraries. As a proposal I think that the good approach here is to have different documentation for each language with different well known validators support. If user wants to generate code with unsupported well known validator for some specific language, library could generate code which raises Not implemented
error. Then you won't restrict of cool function usage in one language when it is not implemented in another. As well library developer will have opportunity to add unimplemented functionality support with regexp later for some specific language.
from protoc-gen-validate.
Related Issues (20)
- RFC 6531 for Email validation HOT 2
- Add warning if PGV is executed with protovalidate annotations
- Flaky java tests HOT 1
- Is there any way to use validation inside a grpc middleware? HOT 1
- Repeated email validation is not working
- Use static linking on AMD64
- Pre-built binaries are missing from v1.0.3
- Issue with protoc-gen-validate: Unknown Option "(validate.rules)" Error HOT 1
- Issus with GLIBC version using the java implementation HOT 1
- Protoc does not generate validation codeοΌHow to solve it? HOT 1
- Does custom constraint not support ignore_empty?
- Use another email validation library in Python?
- Proposal: Enhance embedded message errors HOT 2
- Support i18n for error message HOT 1
- I tried to add protovalidate dependency in pom.xml , but it gives error as import validate.proto not found HOT 7
- Map & Repeated Values get the required validation constraint rule added HOT 2
- Not able to run bazel build due to missing zlib version HOT 1
- Custom validator in java to integrate in proto HOT 1
- incorrect pkg used when importing pkg with the same name HOT 1
- Validating unique prop value within array? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protoc-gen-validate.