{"id":26671080,"url":"https://github.com/systopia/opis-json-schema-ext","last_synced_at":"2025-04-12T04:08:10.555Z","repository":{"id":41100696,"uuid":"499125150","full_name":"systopia/opis-json-schema-ext","owner":"systopia","description":"Extension for Opis JSON Schema with additional keywords and validation error translator.","archived":false,"fork":false,"pushed_at":"2025-04-08T10:32:01.000Z","size":182,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-12T04:07:38.529Z","etag":null,"topics":["json-schema","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/systopia.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":"2022-06-02T12:24:32.000Z","updated_at":"2025-04-08T10:32:04.000Z","dependencies_parsed_at":"2022-09-09T02:32:05.944Z","dependency_job_id":"dcb6e2da-1f9b-4c7e-a1da-126ed3c36d03","html_url":"https://github.com/systopia/opis-json-schema-ext","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systopia%2Fopis-json-schema-ext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systopia%2Fopis-json-schema-ext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systopia%2Fopis-json-schema-ext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systopia%2Fopis-json-schema-ext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/systopia","download_url":"https://codeload.github.com/systopia/opis-json-schema-ext/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248514225,"owners_count":21116903,"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":["json-schema","php"],"created_at":"2025-03-25T23:32:29.483Z","updated_at":"2025-04-12T04:08:10.548Z","avatar_url":"https://github.com/systopia.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Systopia Opis JSON Schema Extension\n\nThis is an extension for [Opis JSON Schema](https://opis.io/json-schema/).\n\n## Keywords\n\nThe following additional keywords are provided:\n\n* `$calculate`\n* `evaluate`\n* `maxDate`\n* `minDate`\n* `noIntersect` An array must not contain intersecting intervals.\n* `$order` Order arrays. (Only performed, if array has no violations.)\n* `precision`\n* `$tag` Tagged data can be fetched from a data container after validation.\n* `$validations`\n* `$limitValidation` Allows to limit validation under specifiable conditions. See [below](#limit-validation).\n\nSee [tests](tests/) for how to use them.\n\nThe [`SystopiaValidator`](./src/SystopiaValidator.php) already provides those\nkeywords. To use them in a different validator class you might want to use\n[`SystopiaSchemaParser`](./src/Parsers/SystopiaSchemaParser.php) or\n[`SystopiaVocabulary`](./src/Parsers/SystopiaVocabulary.php).\n\n### Limit validation\n\nThe keyword `$limitValidation` allows to limit validation under specifiable\nconditions. The reason behind this keyword was to persist forms in an incomplete\nstate. This can also be achieved with the `if-then-else` keywords, though it\ndramatically increases the size of the schema and is error-prone (at least for\ncomplex schemas).\n\nThe structure of the `$limitValidation` keyword is:\n```json\n{\n  \"condition\": JSON Schema,\n  \"rules\": [\n    {\n      \"keyword\": JSON Schema,\n      \"keywordValue\": JSON Schema,\n      \"value\": JSON Schema,\n      \"calculatedValueUsedViolatedData\": boolean|null,\n      \"validate\": boolean\n    }\n  ],\n  \"schema\": JSON Schema\n}\n```\n\n`rules` can have an indefinite number of entries.\n\nIf the schema at `condition` is matched, limited validation is performed. It is\napplied on the keywords at the same depth and the keywords below. If it's not\nset, the result of the condition evaluation on a higher level is used. If the\n`$limitValidation` keyword is not used at a higher level, `false` is used as\nfallback.\n\nThe properties of a rule have the following defaults:\n* `keyword`, `keywordValue`, `value`: `true`\n* `calculatedValueUsedViolatedData`: `null`\n* `validate`: `false`\n\nTo the entries in `rules` the [default rules](#default-rules) are always\nappended. To prevent the execution of the default rules a rule with just the\n`validate` property can be used (`{ \"validate\": false }` or\n`{ \"validate\": true }`).\n\n`schema` has the default value `true`.\n\nIf the specified condition is matched, the rules are applied in case of a\nviolation of a keyword at the same depth or of a keyword below. In case of a\nviolation it will be iterated over the rules until a matching rule is found. If\nthe `validate` property of that rule is false the violation will be ignored.\n\nThe rule matching is done like this:\n\n* The violated keyword (e.g. `type`) is matched against the schema in `keyword`.\n* The value of the violated keyword is matched against the schema in `keywordValue`.\n* The invalid value is matched against the schema in `value`.\n\nAll schemas must be matched for a rule to be matched. If\n`calculatedValueUsedViolatedData` is not `null`, the value has to be calculated\n(with the `$calculate` keyword) and must or must not have used violated data\ndepending on the actual value of `calculatedValueUsedViolatedData`. Violated\ndata is used, if the calculation references a value that has a validation error\n(including ignored ones).\n\nThe keyword `schema` allows to specify a schema that is validated additionally,\nif the condition is matched. This allows for example to require some properties\non limited validation: `\"schema\": { \"required\": [\"foo\", \"bar\"] }`.\n\nExample:\n```json\n{\n  \"$limitValidation\": {\n    \"condition\": {\n      \"properties\": {\n        \"action\": { \"const\": \"save\" }\n      }\n    },\n    \"rules\": [\n      {\n        \"keyword\": { \"const\": \"type\" },\n        \"keywordValue\": { \"not\": { \"const\": \"string\" } },\n        \"value\": { \"type\": [\"number\", \"bool\"] },\n        \"validate\": true\n      },\n      {\n        \"validate\": false\n      }\n    ],\n    \"schema\": {\n      \"required\": [\"example\"]\n    }\n  }\n}\n```\n\nThis means that if the property `action` is set to `\"save\"`, limited validation\nis applied. The rules say that only violations are treated as such, if these\nconditions are met:\n\n* The violated keyword is `type`.\n* The value of the violated keyword is not `\"string\"`.\n* The validated value is neither a number nor a boolean.\n\nAll other violations are ignored because of the second rule.\n\nAdditionally, the property `example` is required, if `action` is `\"save\"`.\n\n#### Default rules\n\nThe default rules are:\n\n```json\n[\n  {\n    \"value\": { \"const\": null }\n  },\n  {\n    \"keyword\": { \"not\": { \"const\": \"type\" } },\n    \"value\": { \"enum\": [false, \"\"] }\n  },\n  {\n    \"keyword\": {\n      \"enum\": [\n        \"minLength\",\n        \"minItems\",\n        \"minContains\",\n        \"minProperties\",\n        \"required\",\n        \"dependentRequired\"\n      ]\n    }\n  },\n  {\n    \"calculatedValueUsedViolatedData\": true\n  },\n  {\n    \"validate\": true\n  }\n]\n```\n\nThe rules mean:\n\n1. No violation error, if the validated value is `null`.\n2. No violation error, if the violated keyword is not `type` and the validated value is `false` or `\"\"` (empty string).\n3. No violation error, if the validated keyword is one of:\n   `minLength`, `minItems`, `minContains`, `minProperties`, `required`, `dependentRequired`\n4. No violation error, if value is calculated and calculation used data with violations (including ignored ones).\n5. Every other validation without limitation.\n\n## Empty array to object conversion\n\nIf the option `convertEmptyArrays` is set to `true` (disabled by default), empty\narrays will be  converted to objects if the schema type contains `object`, but\nnot `array`. This might be necessary if the data to validate was already\ndecoded.\n\n## Translation\n\nThis extension allows to translate `ValidationError`s:\n\nFirst create an instance of `TranslatorInterface`:\n\n```php\n$translator = new Translator($locale, $messages);\n```\n\nIf there is a localisation in the `messages` directory you can use:\n\n```php\n$translator = TranslatorFactory::createTranslator($locale);\n```\n\nThen create an instance of `ErrorTranslator`:\n\n```php\n$errorTranslator = new ErrorTranslator($translator);\n```\n\nLet the `ErrorTranslator` translate a validation error:\n\n```php\necho $errorTranslator-\u003etrans($error);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystopia%2Fopis-json-schema-ext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsystopia%2Fopis-json-schema-ext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystopia%2Fopis-json-schema-ext/lists"}