{"id":29623813,"url":"https://github.com/mikemitterer/objectvalidator.dart","last_synced_at":"2025-07-21T05:08:07.233Z","repository":{"id":56835754,"uuid":"113169204","full_name":"MikeMitterer/objectvalidator.dart","owner":"MikeMitterer","description":null,"archived":false,"fork":false,"pushed_at":"2019-01-30T15:37:34.000Z","size":122,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-16T06:44:38.269Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MikeMitterer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-05T10:43:29.000Z","updated_at":"2019-10-06T23:57:21.000Z","dependencies_parsed_at":"2022-09-02T03:40:43.651Z","dependency_job_id":null,"html_url":"https://github.com/MikeMitterer/objectvalidator.dart","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/MikeMitterer/objectvalidator.dart","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MikeMitterer%2Fobjectvalidator.dart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MikeMitterer%2Fobjectvalidator.dart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MikeMitterer%2Fobjectvalidator.dart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MikeMitterer%2Fobjectvalidator.dart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MikeMitterer","download_url":"https://codeload.github.com/MikeMitterer/objectvalidator.dart/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MikeMitterer%2Fobjectvalidator.dart/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266242072,"owners_count":23898102,"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","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-07-21T05:08:06.357Z","updated_at":"2025-07-21T05:08:07.227Z","avatar_url":"https://github.com/MikeMitterer.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"## ObjectValidator\n\u003e Object-Validator for Dart\n\n### Usage\n\nDefine your class you want to validate and implement the `Verifiable\u003cAnotherPerson\u003e` interface\n\n```dart\nclass AnotherPerson implements Verifiable\u003cAnotherPerson\u003e {\n    final int _age;\n\n    AnotherPerson(this._age);\n\n    int get age =\u003e _age;\n    \n    @override\n    void validate({ifInvalid = throwViolationException}) =\u003e isAnotherPersonValid(this, ifInvalid: ifInvalid);\n}\n\nvoid isAnotherPersonValid(final AnotherPerson ap,\n    { void Function(final AnotherPerson obj,final ObjectValidator ov) ifInvalid = throwViolationException }) {\n\n    final ov = ObjectValidator();\n\n    ov.verify(ap.age, Range(15, 55, onError: (final Range range)\n        =\u003e (final invalidValue)\n            =\u003e l10n(\"Age must be between ${range.start} and ${range.end} but was ${invalidValue.toString()}!\")));\n\n    ifInvalid(ap,ov);\n}\n```\n\nIf you want to check your object for being valid - it looks like this:\n\n```dart\n        test('\u003e AnotherPerson should be between 15 and 55 years old', () {\n            final person = AnotherPerson(55);\n            expect(() =\u003e person.validate(), isNot(throwsException));\n        }); \n\n        test('\u003e AnotherPerson must be between 15 and 55 years old and fails', () {\n            final person = AnotherPerson(99);\n            expect(() =\u003e person.validate(), throwsException);\n\n            try {\n                person.validate();\n            } on ViolationException catch(e) {\n                violations.addAll(e.violations);\n            }\n\n            expect(violations.length, 1);\n            expect(violations.first, \"Age must be between 15 and 55 but was 99!\");\n        }); \n\n        test('\u003e AnotherPerson - check with onError instead of Exception', () {\n            final person = AnotherPerson(99);\n\n            person.validate(ifInvalid: (final AnotherPerson ap, final ObjectValidator ov)\n                =\u003e violations.addAll(ov.violations));\n\n            expect(violations.length, 1);\n            expect(violations.first, \"Age must be between 15 and 55 but was 99!\");\n        }); \n        test('\u003e AnotherPerson - check with global function', () {\n            final person = AnotherPerson(99);\n\n            // If you use 'isAnotherPersonValid' it's not necessary to \n            // implement the 'Verifiable\u003cAnotherPerson\u003e' interface for 'AnotherPerson' \n            isAnotherPersonValid(person,ifInvalid: (final AnotherPerson ap, final ObjectValidator ov)\n                =\u003e violations.addAll(ov.violations));\n\n            expect(violations.length, 1);\n            expect(violations.first, \"Age must be between 15 and 55 but was 99!\");\n        }); \n        \n```\n\nFor more - check out my tests...\n\n## Features and bugs\nPlease file feature requests and bugs at the [issue tracker](https://github.com/MikeMitterer/objectvalidator.dart/issues).\n\n### License\n\n    Copyright 2019 Michael Mitterer, IT-Consulting and Development Limited,\n    Austrian Branch\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, \n    software distributed under the License is distributed on an \n    \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, \n    either express or implied. See the License for the specific language \n    governing permissions and limitations under the License.\n    \nIf this plugin is helpful for you - please [(Circle)](http://gplus.mikemitterer.at/) me.\n\n[1]: https://github.com/MikeMitterer/objectvalidator.dart/issues\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikemitterer%2Fobjectvalidator.dart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikemitterer%2Fobjectvalidator.dart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikemitterer%2Fobjectvalidator.dart/lists"}