{"id":18022997,"url":"https://github.com/kanryu/validagen","last_synced_at":"2026-04-29T17:32:15.376Z","repository":{"id":216104437,"uuid":"740460902","full_name":"kanryu/validagen","owner":"kanryu","description":"A validator generator for structs/maps for your go applications.","archived":false,"fork":false,"pushed_at":"2024-01-14T12:25:36.000Z","size":3782,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-04T18:17:34.127Z","etag":null,"topics":["generator","go","openapi","ozzo-validation","validator"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kanryu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2024-01-08T11:50:09.000Z","updated_at":"2024-01-08T12:24:37.000Z","dependencies_parsed_at":"2024-01-14T09:44:35.570Z","dependency_job_id":"b9c8702a-0330-4d8a-bbfe-631a8db85b01","html_url":"https://github.com/kanryu/validagen","commit_stats":null,"previous_names":["kanryu/validagen"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/kanryu/validagen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanryu%2Fvalidagen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanryu%2Fvalidagen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanryu%2Fvalidagen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanryu%2Fvalidagen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kanryu","download_url":"https://codeload.github.com/kanryu/validagen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanryu%2Fvalidagen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32436614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T17:26:39.753Z","status":"ssl_error","status_checked_at":"2026-04-29T17:25:53.857Z","response_time":110,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["generator","go","openapi","ozzo-validation","validator"],"created_at":"2024-10-30T07:06:35.604Z","updated_at":"2026-04-29T17:32:15.361Z","avatar_url":"https://github.com/kanryu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Validagen\nA validator generator for structs/maps for your go applications.\n\n## Features\n- Simplicity\n- Efficient validators are automatically generated(for ozzo-validation/v4)\n- Prevent bugs by declaratively writing validator settings\n- Generating a validator for the struct automatically generated by oapi-codegen\n- Automatic generation of unit tests for validators\n\n## Install\n\n```bash\ngo install github.com/kanryu/validagen\n```\n\n## How to use\n\ne.g. There is a struct.\n\n```go\ntype Address struct {\n\tFood   string\n\tIncome float64\n\tMail   string\n\tPeople int\n\tStreet string\n\tState  string\n}\n\n```\n\nYou will write a toml as `example.toml`.\n\n```toml\n# Type: struct or map\nType=\"struct\"\n# MethodName: (optional) method name of the validator. Validate is default\n\n# Validators.XXX: Validator information for struct XXX\n[Validators.Address]\n# Name: (optional) struct identifier. key name is substituted as default\n# Package: (optional) Validator package name. strings.ToLower(Name) as default\nPackage = \"example\"\n# Receiver: (optional) receiver of the validator method\n# Dir: (optional) Directory to output validator source code. Package name is default\n# FileName: (optional) Validator file name. \"[ToSnake(Name)]_validator.go\" is the default\n# FileMode: (optional) file mode of the validator source code 0644 is default\n# Import: (optional) Add additional packages when validator source code imports them\n# Properties: validators for each field of struct\nProperties.Food.Type = \"string\"\nProperties.Food.Required = true\nProperties.Food.In = {String=[\"Cheeze\", \"Milk\", \"Meat\"]}\nProperties.Income.Type = \"float\"\nProperties.Income.Required = true\nProperties.Income.In = {Float=[1.1,2.2,3.3]}\nProperties.Mail.Type = \"string\"\nProperties.Mail.Required = true\nProperties.Mail.Email = true\nProperties.People.Type = \"int\"\nProperties.People.Required = true\nProperties.People.In = {Int=[1,2,3]}\nProperties.State.Type = \"string\"\nProperties.State.Required = true\nProperties.State.match = \"^[A-Z]{2}$\"\nProperties.Street.Type = \"string\"\nProperties.Street.Required = true\nProperties.Street.Length = [5,50]\n```\n\nYou will run validagen.\n\n```bash\nvalidagen generate example.toml\n```\n\nYou can find the validator as `example/address_validator.go`\n\n```go\n// Code generated by github.com/kanryu/validagen. DO NOT EDIT.\npackage example\n\nimport (\n\t\"regexp\"\n\t\"github.com/go-ozzo/ozzo-validation/v4/is\"\n\tvalidation \"github.com/go-ozzo/ozzo-validation/v4\"\n)\n\n// Validate validater for Address struct\nfunc (a Address) Validate() error {\n\treturn validation.ValidateStruct(\u0026a,\n\t\tvalidation.Field(\u0026a.Food, validation.In(\"Cheeze\", \"Milk\", \"Meat\"), validation.Required),\n\t\tvalidation.Field(\u0026a.Income, validation.In(1.1, 2.2, 3.3), validation.Required),\n\t\tvalidation.Field(\u0026a.Mail, validation.Required, is.Email),\n\t\tvalidation.Field(\u0026a.People, validation.In(1, 2, 3), validation.Required),\n\t\tvalidation.Field(\u0026a.State, validation.Match(regexp.MustCompile(\"^[A-Z]{2}$\")), validation.Required),\n\t\tvalidation.Field(\u0026a.Street, validation.Length(5,50), validation.Required),\n\t)\n}\n```\n\n## How to test\nYou can get also test for the validators.\n\nYou will add lines into the toml.\n\n```toml\n[Validators.Address.TestData]\n# Testing: flag of generating tests\nTesting = true\n# Valid: a map of valid data of the struct\nValid.Food = {String=[\"Cheeze\"]}\nValid.Income = {Float=[2.2]}\nValid.Mail = {String=[\"ab@example.com\"]}\nValid.People = {Int=[3]}\nValid.State = {String=[\"SF\"]}\nValid.Street = {String=[\"street\"]}\n# Invalid: amap of invalid data of the struct.\n# each failed test generate contains on invalid property value\nInvalid.Food = {String=[\"Cheezended\"]}\nInvalid.Income = {Float=[2.233]}\nInvalid.Mail = {String=[\"nil\"]}\nInvalid.People = {Int=[33]}\nInvalid.State = {String=[\"SFX\"]}\nInvalid.Street = {String=[\"fail\"]}\n```\n\nAfter you run validagen again, you can get test as `example/address_validator_test.go`.\n\n```go\npackage example\n\n\nimport (\n\t\"testing\"\n)\n\n// TestAddress_Validate a test suite for (a *Address)Validate()\nfunc TestAddress_Validate(t *testing.T) {\n\ttests := []struct {\n\t\tname    string\n\t\ta       Address\n\t\twantErr bool\n\t}{\n\t\t{wantErr: false, name: \"OK\", a: Address{Food:\"Cheeze\",Income:2.2,Mail:\"ab@example.com\",People:3,State:\"SF\",Street:\"street\"}},\n\t\t{wantErr: true, name: \"NG for Food\", a: Address{Food:\"Cheezended\",Income:2.2,Mail:\"ab@example.com\",People:3,State:\"SF\",Street:\"street\"}},\n\t\t{wantErr: true, name: \"NG for Income\", a: Address{Food:\"Cheeze\",Income:2.233,Mail:\"ab@example.com\",People:3,State:\"SF\",Street:\"street\"}},\n\t\t{wantErr: true, name: \"NG for Mail\", a: Address{Food:\"Cheeze\",Income:2.2,Mail:\"nil\",People:3,State:\"SF\",Street:\"street\"}},\n\t\t{wantErr: true, name: \"NG for People\", a: Address{Food:\"Cheeze\",Income:2.2,Mail:\"ab@example.com\",People:33,State:\"SF\",Street:\"street\"}},\n\t\t{wantErr: true, name: \"NG for State\", a: Address{Food:\"Cheeze\",Income:2.2,Mail:\"ab@example.com\",People:3,State:\"SFX\",Street:\"street\"}},\n\t\t{wantErr: true, name: \"NG for Street\", a: Address{Food:\"Cheeze\",Income:2.2,Mail:\"ab@example.com\",People:3,State:\"SF\",Street:\"fail\"}},\n\t}\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\terr := tt.a.Validate()\n\t\t\tif tt.wantErr {\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Fatalf(\"%q. wantErr %v, but actual err %v\", tt.name, tt.wantErr, err)\n\t\t\t\t}\n\t\t\t} else if err != nil {\n\t\t\t\tt.Fatalf(\"%q. wantErr %v, but actual err occured %+v\", tt.name, tt.wantErr, err)\n\t\t\t}\n\t\t})\n\t}\n}\n```\n\n## Author\nKATO Kanryu(k.kanryu@gmail.com)\n\n## License\nMIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanryu%2Fvalidagen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkanryu%2Fvalidagen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanryu%2Fvalidagen/lists"}