{"id":16696945,"url":"https://github.com/seratch/inputvalidator","last_synced_at":"2025-04-10T02:52:19.477Z","repository":{"id":57722686,"uuid":"4884897","full_name":"seratch/inputvalidator","owner":"seratch","description":"Scala Input Validator with quite readable DSL","archived":false,"fork":false,"pushed_at":"2013-12-31T03:19:34.000Z","size":342,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"develop","last_synced_at":"2025-03-24T04:22:21.766Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","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/seratch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-07-04T13:41:52.000Z","updated_at":"2020-11-25T13:43:46.000Z","dependencies_parsed_at":"2022-08-28T08:40:51.452Z","dependency_job_id":null,"html_url":"https://github.com/seratch/inputvalidator","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seratch%2Finputvalidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seratch%2Finputvalidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seratch%2Finputvalidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seratch%2Finputvalidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seratch","download_url":"https://codeload.github.com/seratch/inputvalidator/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248147104,"owners_count":21055478,"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":"2024-10-12T17:45:22.722Z","updated_at":"2025-04-10T02:52:19.450Z","avatar_url":"https://github.com/seratch.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# InputValidator\n\n## Important Notice\n\ninputvalidator is already in maintenance mode. So only bug fixes will be released and new features won't be implemented.\n\nNow I'm working harder on skinny-validator (it's a successor of inputvalidator and some APIs are refactored). skinny-validator is a part of skinny-framework but it doesn't depend on skinny. You can use skinny-validator anywhere as same as well as inputvalidator.\n\nhttps://github.com/skinny-framework/skinny-framework/tree/develop/validator\n\nhttp://skinny-framework.org/documentation/validator.html\n\n## Scala Input Validator with quite readable DSL\n\n```\nlibraryDependencies += \"com.github.seratch\" %% \"inputvalidator\" % \"[1.0,)\"\n```\n\nUse as follows:\n\n```scala\nimport inputvalidator._\n\ncase class Registration(id: Int, firstName: String, lastName: Option[String], gender: String)\n\nval validator = Validator {\n  input(\"id\" -\u003e 12345) is required \u0026 maxLength(4), // 1 error\n  input(\"first_name\" -\u003e \"\") is notNull \u0026 minLength(3), // 1 error\n  input(\"last_name\" -\u003e \"Kaz\") is checkAll(minLength(5), numeric), // 2 errors\n  input(\"gender\" -\u003e \"male\") is notEmpty\n\n}\n\nval res: String = validator.success {\n  inputs =\u003e inputs.string(\"first_name\")\n}.failure {\n  (inputs, errors) =\u003e \"Failed! : \" + errors\n}.apply()\n\nval form = validator.map { inputs =\u003e \n  Registration(\n    id        = inputs.int(\"id\"),\n    firstName = inputs.string(\"first_name\"),\n    lastName  = inputs.stringOpt(\"last_name\"),\n    gender    = inputs.string(\"gender\")\n  )\n}\n\nif (form.hasErrors) {\n  BadRequest(form.errors)\n} else {\n  val registration = form.get\n  User.create(registration)\n  Ok\n}\n```\n\nAccepting `Map` value is also simple:\n\n```scala\nval params: Map[String, Any] = request.getParameterMap()\n\nval v = Validator(params)(\n  inputKey(\"password\") is required,\n  inputKey(\"newPassword\") is (required and minLength(6)),\n  inputKey(\"reNewPassword\") is (required and minLength(6)),\n  input(\"pair\" -\u003e (params.get(\"newPassword\"), params.get(\"reNewPassword\"))) are same\n)\n```\n\n## Built-in Validations\n\nSee the following source code:\n\nhttps://github.com/seratch/inputvalidator/blob/master/library/src/main/scala/inputvalidator/BuiltinValidations.scala\n\nYour pull requests are always welcome.\n\n\n## Easily Extendable\n\nIf you need to add validations, it's quite simple.\n\nJust add new class which extends `inputvalidator.ValidationRule` as follows:\n\n```scala\nobject authenticated extends ValidationRule {\n  def name = \"authenticated\"\n  def isValid(v: Any) = {\n    val (username, password) = v.asInstanceOf[(String, String)]\n    UserService.authenticate(username, password).isDefined\n  }\n}\n\nval v = Valdiator(\n  input(\"username\" -\u003e username) is required,\n  input(\"passowrd\" -\u003e password) is required,\n  input(\"login\" -\u003e (username, password)) is authenticated\n)\n```\n\n\n## Message Binding\n\nSupports the standard way to use `messages.properties`.\n\n```scala\npost(\"login\") {\n  Validator(params)(\n    input(\"username\" -\u003e username) is required,\n    input(\"passowrd\" -\u003e password) is required,\n    input(\"login\" -\u003e (username, password)) is authenticated\n  ).success { inputs =\u003e\n    respond(status = 200, body = render(\"completed.ssp\"))\n  }.failure { (inputs, errors) =\u003e\n    respond(\n      status = 400, \n      body = render(\"input.ssp\",\n        \"useraname\" -\u003e inputs.get(\"username\"),\n        \"password\" -\u003e inputs.get(\"password\"),\n        \"errors\" -\u003e inputs.keys.flatMap { key =\u003e\n          errors.get(key).map { error =\u003e\n            Messages.get(key = error.name, params = key :: error.messageParams.toList).getOrElse(error.name)\n          }\n        }\n      )\n    )\n  }.apply()\n}\n```\n\n\n## Do the Same Everywhere\n\nFurthermore, this library does not depend on any other components. So you can do the same everywhere.\n\nPlease see the following examples.\n\n- Play framework 2.x Scala\n\nhttps://github.com/seratch/inputvalidator/tree/master/play-module\n\nhttps://github.com/seratch/inputvalidator/tree/master/samples/play20\n\n- Scalatra\n\nhttps://github.com/seratch/inputvalidator/tree/master/samples/scalatra\n\n- Circumflex\n\nhttps://github.com/seratch/inputvalidator/tree/master/samples/circumflex\n\n\n## License\n\nCopyright 2013 Kazuhiro Sera\n\nApache License, Version 2.0\n\nhttp://www.apache.org/licenses/LICENSE-2.0.html\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseratch%2Finputvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseratch%2Finputvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseratch%2Finputvalidator/lists"}