{"id":28389209,"url":"https://github.com/elixir-protobuf/protoc-gen-validate","last_synced_at":"2025-10-25T22:16:01.192Z","repository":{"id":103222032,"uuid":"248995091","full_name":"elixir-protobuf/protoc-gen-validate","owner":"elixir-protobuf","description":"WIP","archived":false,"fork":false,"pushed_at":"2022-10-09T09:22:02.000Z","size":55,"stargazers_count":10,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-27T16:48:06.255Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elixir-protobuf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-03-21T14:40:23.000Z","updated_at":"2023-01-09T20:59:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"59653481-64f1-4f62-93a7-853b010ad9b3","html_url":"https://github.com/elixir-protobuf/protoc-gen-validate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/elixir-protobuf/protoc-gen-validate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-protobuf%2Fprotoc-gen-validate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-protobuf%2Fprotoc-gen-validate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-protobuf%2Fprotoc-gen-validate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-protobuf%2Fprotoc-gen-validate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elixir-protobuf","download_url":"https://codeload.github.com/elixir-protobuf/protoc-gen-validate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-protobuf%2Fprotoc-gen-validate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278277319,"owners_count":25960424,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-31T00:37:51.538Z","updated_at":"2025-10-04T06:32:44.087Z","avatar_url":"https://github.com/elixir-protobuf.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ProtoValidator\n\nElixir implementation of https://github.com/envoyproxy/protoc-gen-validate\n\n## Installation\n\n```elixir\ndef deps do\n  [\n    {:proto_validator, \"~\u003e 0.1.0\"}\n  ]\nend\n```\n\n## Usage\nDevelopers import the ProtoValidator and annotate the messages and fields in their proto files with constraint rules:\n\n``` Elixir\npackage examplepb\n\nmessage User {\n  uint64 id    = 1 [(validate.rules) = {\n    uint64: {gt: 0, lt: 90},\n    message: {required: true}\n  }];\n\n  string email = 2 [(validate.rules).message.required = true];\n\n  GENDER gender = 3;\n\n  message Phone {\n    string phone_number = 1 [(validate.rules) = {\n      uint64: {gt: 1000, lt: 2000}, \n      message: {required: true}\n    }];\n  }\n\n  repeated Phone phones = 4 [(validate.rules).repeated.min_items = 1];\n\n  repeated uint64 following_ids = 5 [(validate.rules).repeated = {\n    min_items: 0,\n    unique: true,\n    items: {uint64: {gt: 0, lt: 90}}\n  }];\n}\n```\nThen ProtoValidator will generate the validator modules for messages that have constraint rules automatically like:\n``` Elixir\ndefmodule ProtoValidator.Gen.Examplepb.User do\n  @moduledoc false\n  use ProtoValidator, entity: Examplepb.User\n\n  validate(:id, required: true, uint64: [gt: 0, lt: 90])\n  validate(:email, required: true)\n  validate(:phones, repeated: [min_items: 1])\n\n  validate(:following_ids,\n    repeated: [items: [uint64: [gt: 0, lt: 90]], min_items: 0, unique: true]\n  )\nend\n\ndefmodule ProtoValidator.Gen.Examplepb.User.Phone do\n  @moduledoc false\n  use ProtoValidator, entity: Examplepb.User.Phone\n\n  validate(:phone_number, required: true, uint64: [gt: 1000, lt: 2000])\nend\n```\nThen both `\u0026ProtoValidator.validate/1` and `\u0026ProtoValidator.Gen.Examplepb.User/1` can be used to do the validation.\n``` Elixir\nuser = Examplepb.User.new()\n{:error, _} = ProtoValidator.validate(user)\nusers = %{user | id: 1}\n{:error, _} = ProtoValidator.validate(user)\nusers = %{user | email: \"user@example.com\"}\n:ok = ProtoValidator.validate(user)\n:ok = ProtoValidator.Gen.Examplepb.User.validate(user)\n```\n## Notes\nCurrently only those rules are supported:\n``` protobuf\nmessage MessageRules {\n    // Required specifies that this field must be set\n    optional bool required = 2;\n}\n\n// UInt64Rules describes the constraints applied to `uint64` values\nmessage UInt64Rules {\n    // Lt specifies that this field must be less than the specified value,\n    // exclusive\n    optional uint64 lt = 2;\n    // Gt specifies that this field must be greater than the specified value,\n    // exclusive. If the value of Gt is larger than a specified Lt or Lte, the\n    // range is reversed.\n    optional uint64 gt = 4;\n}\nmessage RepeatedRules {\n    // MinItems specifies that this field must have the specified number of\n    // items at a minimum\n    optional uint64 min_items = 1;\n\n    // MaxItems specifies that this field must have the specified number of\n    // items at a maximum\n    optional uint64 max_items = 2;\n\n    // Unique specifies that all elements in this field must be unique. This\n    // contraint is only applicable to scalar and enum types (messages are not\n    // supported).\n    optional bool   unique    = 3;\n\n    // Items specifies the contraints to be applied to each item in the field.\n    // Repeated message fields will still execute validation against each item\n    // unless skip is specified here.\n    optional FieldRules items = 4;\n}\n```\n\n## How it works\n\nRefer: https://github.com/envoyproxy/protoc-gen-validate\n\n1. Google's Protobuf messages(like google.protobuf.MessageOptions) are extended with\nvalidating rules(validate.proto)\n2. Your protobuf messages can use validate.proto to define validation options\n3. This plugin generate validating code when called by protoc. The code can be called\nto validate messages\n4. Then you can validate your structs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-protobuf%2Fprotoc-gen-validate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felixir-protobuf%2Fprotoc-gen-validate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-protobuf%2Fprotoc-gen-validate/lists"}