https://github.com/devongovett/protobuf-validator
Validates objects against protocol buffer schemas
https://github.com/devongovett/protobuf-validator
Last synced: 9 months ago
JSON representation
Validates objects against protocol buffer schemas
- Host: GitHub
- URL: https://github.com/devongovett/protobuf-validator
- Owner: devongovett
- Created: 2015-12-06T03:33:13.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-06-20T22:20:55.000Z (about 9 years ago)
- Last Synced: 2025-08-25T08:46:08.013Z (10 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 57
- Watchers: 5
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# protobuf-validator
Validates objects against protocol buffer schemas
## Motivation
Even if you don't use the binary serialization format,
[Protocol Buffer IDL](https://developers.google.com/protocol-buffers/docs/proto3) is still a nice
data modeling language, allowing you to define messages with typed fields, required/optional constraints, etc.
This module allows you to validate JavaScript objects against protobuf schemas, which is useful if you
have a JSON API but need to validate user submitted objects, for example.
## Example
Assuming you have a file called `models.proto`:
```protobuf
message Person {
required string name = 0;
optional int32 age = 1;
}
```
```javascript
var validate = require('protobuf-validator')('models.proto');
// valid
validate('Person', {
name: 'Devon'
});
// throws "Person.name must be a valid string value"
validate('Person', {
name: 123
});
```
## License
MIT