{"id":15037794,"url":"https://github.com/digiacomo/fluidvalidator","last_synced_at":"2025-04-09T23:32:53.331Z","repository":{"id":56911531,"uuid":"51255499","full_name":"digiacomo/FluidValidator","owner":"digiacomo","description":"General purpose validation system for objects, nested objects, enumerables written in Swift","archived":false,"fork":false,"pushed_at":"2019-11-25T22:39:28.000Z","size":113,"stargazers_count":85,"open_issues_count":1,"forks_count":4,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-31T09:19:53.665Z","etag":null,"topics":["ios-swift","swift-3","validation","validation-library"],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/digiacomo.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}},"created_at":"2016-02-07T16:49:32.000Z","updated_at":"2023-09-22T13:33:29.000Z","dependencies_parsed_at":"2022-08-21T03:20:10.292Z","dependency_job_id":null,"html_url":"https://github.com/digiacomo/FluidValidator","commit_stats":null,"previous_names":["frograin/fluidvalidator"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digiacomo%2FFluidValidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digiacomo%2FFluidValidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digiacomo%2FFluidValidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digiacomo%2FFluidValidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/digiacomo","download_url":"https://codeload.github.com/digiacomo/FluidValidator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248129966,"owners_count":21052670,"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":["ios-swift","swift-3","validation","validation-library"],"created_at":"2024-09-24T20:35:44.513Z","updated_at":"2025-04-09T23:32:53.281Z","avatar_url":"https://github.com/digiacomo.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FluidValidator\n\n[![CI Status](http://img.shields.io/travis/FrogRain/FluidValidator.svg?style=flat)](https://travis-ci.org/FrogRain/FluidValidator)\n[![Version](https://img.shields.io/cocoapods/v/FluidValidator.svg?style=flat)](http://cocoapods.org/pods/FluidValidator)\n[![License](https://img.shields.io/cocoapods/l/FluidValidator.svg?style=flat)](http://cocoapods.org/pods/FluidValidator)\n[![Platform](https://img.shields.io/cocoapods/p/FluidValidator.svg?style=flat)](http://cocoapods.org/pods/FluidValidator)\n\n## Description\nFluidValidator is intended to encapsulate validation logic. The API was designed with FluentValidation (https://github.com/JeremySkinner/FluentValidation) and Rails Validation as reference.\n  Currently offers validation of simple objects, complex objects (object graph), enumerables. Localized error messages. You can easly override base behaviors and/or build your own reusable validation rules.\n\n## Usage\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Requirements\nNo special requirements\n\n## Installation\n\nFluidValidator is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"FluidValidator\"\n```\n\n## Usage\n### A simple object\nGiven this object:\n\n```swift\n\nimport Foundation\n\nclass Home {\n    var isLocked:Bool?\n    var number:Int?\n    var ownerName:String?\n}\n```\n\nCreate a custom validator extending AbstractValidator specifing target class Example:\n\n```swift\n\nimport Foundation\nimport FluidValidator\n\nclass HomeValidator : AbstractValidator\u003cHome\u003e {\n    override init() {\n        super.init()\n               \n        self.addValidation(withName: \"number\") { (context) -\u003e (Any?) in\n            context.number\n        }.addRule(GreaterThan(limit: 3, includeLimit: false))\n        \n        self.addValidation(withName: \"ownerName\") { (context) -\u003e (Any?) in\n            context.ownerName\n        }.addRule(BeNotEmpty())\n        \n        self.addValidation(withName: \"isLocked\") { (context) -\u003e (Any?) in\n            context.isLocked\n        }.addRule(BeTrue())\n    }\n}\n```\n### Nested Objects\nGiven this more complex object:\n```swift\nimport Foundation\n\nclass Home {\n    var isLocked:Bool?\n    var number:Int?\n    var ownerName:String?\n    var garage: Garage?\n}\nclass Garage {\n  var isOpen: Bool?\n  var maxCars: Int?\n}\n```\nThe corresponding validator would be implemented this way:\n```swift\nimport Foundation\nimport FluidValidator\n\nclass GarageValidator: AbstractValidator\u003cGarage\u003e {\n    override init() {\n        super.init()\n        \n        self.addValidation(withName: \"isOpen\") { (context) -\u003e Any? in\n            context.isOpen\n        }.addRule(BeTrue())\n        \n        self.addValidation(withName: \"maxCars\") { (context) -\u003e Any? in\n            context.maxCars\n        }.addRule(LessThan(limit: 2, includeLimit: true))\n    }\n}\n\nclass HomeValidator : AbstractValidator\u003cHome\u003e {\n    override init() {\n        super.init()\n        \n        ...\n        self.addValidation(withName: \"garage\") { (context) -\u003e (Any?) in\n            context.garage\n        }.addRule(GarageValidator())\n    }\n}\n```\n\n### Run validations and get result\n\nregardless of your validators complexity, you can run validation process and extract error messages (if any) as showed here\n\n```swift\n\n    let garage = Garage()\n    garage.isOpen = false\n\n    let home = Home()\n    home.isLocked = true\n    home.ownerName = \"John Doe\"\n    home.number = 2\n    home.garage = garage\n\n    let homeValidator = HomeValidator()\n    let result = homeValidator.validate(home)\n    let failMessage = homeValidator.allErrors()\n```\n\n### Get fail messages\n```swift\nfailMessage.failMessageForPath(\"number\")?.errors.first?.compact\nfailMessage.failMessageForPath(\"number\")?.errors.first?.extended\n\nfailMessage.failMessageForPath(\"garage\")?.errors.first?.compact\nfailMessage.failMessageForPath(\"garage.isOpen\")?.errors.first?.extended\n```\nThe errors array contains ErrorMessage objects which in turn contains compact and extended error message.\n\nTake a look at Unit Test classes to figure out other features\n\n\n\n## Author\n\nFrogRain, info@frograin.com\n\n## License\n\nFluidValidator is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigiacomo%2Ffluidvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigiacomo%2Ffluidvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigiacomo%2Ffluidvalidator/lists"}