{"id":27624299,"url":"https://github.com/veupathdb/lib-jpath-request-validation","last_synced_at":"2026-04-28T18:08:01.497Z","repository":{"id":287454427,"uuid":"964782088","full_name":"VEuPathDB/lib-jpath-request-validation","owner":"VEuPathDB","description":"Tools for validating JSON requests in JaxRS container services.","archived":false,"fork":false,"pushed_at":"2025-04-11T20:00:35.000Z","size":82,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-04-11T20:39:13.878Z","etag":null,"topics":["jaxrs","json","validation"],"latest_commit_sha":null,"homepage":"https://veupathdb.github.io/lib-jpath-request-validation/","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VEuPathDB.png","metadata":{"files":{"readme":"readme.adoc","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-11T19:22:12.000Z","updated_at":"2025-04-11T20:00:38.000Z","dependencies_parsed_at":"2025-04-11T20:49:46.321Z","dependency_job_id":null,"html_url":"https://github.com/VEuPathDB/lib-jpath-request-validation","commit_stats":null,"previous_names":["veupathdb/lib-jpath-request-validation"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VEuPathDB%2Flib-jpath-request-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VEuPathDB%2Flib-jpath-request-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VEuPathDB%2Flib-jpath-request-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VEuPathDB%2Flib-jpath-request-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VEuPathDB","download_url":"https://codeload.github.com/VEuPathDB/lib-jpath-request-validation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250424350,"owners_count":21428354,"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":["jaxrs","json","validation"],"created_at":"2025-04-23T11:28:25.563Z","updated_at":"2026-04-28T18:08:01.491Z","avatar_url":"https://github.com/VEuPathDB.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"= JSON Request Validation\n:source-highlighter: highlight.js\n:highlightjs-theme: github\n:library-version: 0.1.1\n:gh-group: VEuPathDB\n:gh-name: lib-jpath-request-validation\n:lib-group: org.veupathdb.vdi\n\nA collection of tools for validating JSON requests and reporting validation\nfailures using JSON path notation.\n\nimage:https://img.shields.io/github/license/{gh-group}/{gh-name}[title=\"License\"]\nimage:https://img.shields.io/badge/docs-dokka-ff69b4[link=\"https://{gh-group}.github.io/{gh-name}\"]\n// image:https://img.shields.io/badge/docs-dokka-ff69b4[link=\"https://{gh-group}.github.io/{gh-name}/dokka\"]\n// image:https://img.shields.io/badge/docs-java-27ada4[link=\"https://{gh-group}.github.io/{gh-name}/javadoc\"]\nimage:https://img.shields.io/github/v/tag/{gh-group}/{gh-name}[GitHub tag (latest SemVer)]\n\nThis library is primarily intended for use with services using generated JaxRS\ntypes from link:https://github.com/VEuPathDB/raml-for-jax-rs[raml-for-jaxrs].\n\n== Usage\n\n[NOTE]\nThis library is primarily intended for use with, and is most convenient in\nKotlin, but it does support full interoperability with Java as well.\n\n.`build.gradle.kts`\n[source, kotlin, subs=\"attributes\"]\n----\ndependencies {\n  implementation(\"org.veupathdb.lib:jpath-request-validation:{library-version}\")\n}\n----\n\n=== Request Field Validation\n\n==== Kotlin\n\n[source, kotlin]\n----\nfun MyRequestBody.validate(): ValidationErrors {\n  val errors = ValidationErrors()\n\n  // ensure the \"name\" field on the request body is not null and has a length\n  // \u003e= 3 and \u003c= 24\n  name.reqCheckLength(JsonField.NAME, 3, 24, errors)\n\n  // if the \"description\" field is not null, ensure it has a length \u003c= 4000\n  description.optCheckMaxLength(JsonField.DESCRIPTION, 4000, errors)\n\n  // call the validate function on the \"options\" object of type MyOptionsField,\n  // passing in the name of the field to use when forming JSON paths to\n  // sub-fields.\n  options.validate(JsonField.OPTIONS, errors)\n\n  return errors\n}\n\nfun MyOptionsField.validate(jPath: String, errors: ValidationErrors) {\n  // make the subpath for the \"fields\" list ahead of time so we aren't doing\n  // string concat in the loop\n  val subPath = jPath..JsonField.FIELDS\n\n  // require that the \"fields\" array on the object is not null\n  fields.require(subPath, errors) {\n    // iterate through the strings in the \"fields\" array\n    forEachIndexed { i, field -\u003e\n      // ensure the fields are not blank\n      field.checkNonBlank(subPath, i, errors)\n    }\n  }\n}\n----\n\n==== Java\n\n[source, java]\n----\nimport static org.veupathdb.lib.request.validation.Validation.checkNonBlank;\nimport static org.veupathdb.lib.request.validation.Validation.optCheckMaxLength;\nimport static org.veupathdb.lib.request.validation.Validation.require;\nimport static org.veupathdb.lib.request.validation.Validation.reqCheckLength;\n\npublic ValidationErrors validate(MyRequestBody body) {\n  var errors = new ValidationErrors();\n\n  // ensure the \"name\" field on the request body is not null and has a length\n  // \u003e= 3 and \u003c= 24\n  reqCheckLength(body.name, JsonField.NAME, 3, 24, errors);\n\n  // if the \"description\" field is not null, ensure it has a length \u003c= 4000\n  optCheckMaxLength(body.description, JsonField.DESCRIPTION, 4000, errors);\n\n  // call the validate function with the \"options\" object of type\n  // MyOptionsField, including the name of the field to use when forming JSON\n  // paths to sub-fields.\n  validate(body.options, JsonField.OPTIONS, errors);\n}\n\nprivate validate(MyOptionsField options, String jPath, ValidationErrors errors) {\n  // make the subpath for the \"fields\" list ahead of time so we aren't doing\n  // string concat in the loop\n  var subPath = JPath.append(jPath, JsonField.FIELDS);\n\n  // require that the \"fields\" array on the object is not null\n  require(options.fields, subPath, errors, fields -\u003e {\n    // iterate through the strings in the \"fields\" array\n    for (var i = 0; i \u003c fields.size(); i++) {\n      // ensure the fields are not blank\n      checkNonBlank(fields.get(i), subPath, i, errors);\n    }\n  });\n}\n----\n\n=== Validation Output\n\nUsing the code samples above as the setup, the output could resemble the\nfollowing:\n\n[source, json]\n----\n{\n  \"byKey\": {\n    \"name\": [ \"must not be null\" ],\n    \"description\": [ \"exceeds the max allowed length of 4000 bytes\" ],\n    \"options.fields[1]\": [ \"must not be blank\" ],\n    \"options.fields[8]\": [ \"must not be blank\" ]\n  }\n}\n----\n\n== License\n\n----\n   Copyright 2023 VEuPathDB\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, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n----\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fveupathdb%2Flib-jpath-request-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fveupathdb%2Flib-jpath-request-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fveupathdb%2Flib-jpath-request-validation/lists"}