{"id":19985888,"url":"https://github.com/aeberdinelli/schemy-reference-support","last_synced_at":"2026-04-14T06:33:39.425Z","repository":{"id":144044995,"uuid":"400872458","full_name":"aeberdinelli/schemy-reference-support","owner":"aeberdinelli","description":"Add reference support to Schemy","archived":false,"fork":false,"pushed_at":"2021-09-07T02:35:14.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-12T11:30:43.423Z","etag":null,"topics":["javascript","json","node","schema","schemy","validation"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/schemy-reference-support","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aeberdinelli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-08-28T19:17:36.000Z","updated_at":"2021-09-07T02:35:17.000Z","dependencies_parsed_at":"2023-04-22T14:34:58.111Z","dependency_job_id":null,"html_url":"https://github.com/aeberdinelli/schemy-reference-support","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aeberdinelli%2Fschemy-reference-support","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aeberdinelli%2Fschemy-reference-support/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aeberdinelli%2Fschemy-reference-support/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aeberdinelli%2Fschemy-reference-support/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aeberdinelli","download_url":"https://codeload.github.com/aeberdinelli/schemy-reference-support/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241419693,"owners_count":19959962,"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":["javascript","json","node","schema","schemy","validation"],"created_at":"2024-11-13T04:26:42.874Z","updated_at":"2026-04-14T06:33:39.395Z","avatar_url":"https://github.com/aeberdinelli.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Reference support\n## Introduction \nThis [Schemy](https://github.com/aeberdinelli/schemy) plugin adds the functionality to reference values from within a schema using `Schemy.$ref()`.\n\n## Install\n- `npm install --save schemy-reference-support`\n\n## Usage\nAdd the plugin to Schemy:\n\n```javascript\nconst Schemy = require('schemy');\nconst SchemyReferenceSupport = require('schemy-reference-support');\n\n// Load the plugin into Schemy\nSchemy.extend(SchemyReferenceSupport);\n\n// Now you can use Schemy.$ref(propertyName)\n```\n\n## Examples\n### In property settings\nWe can use a previously defined property within the definition of the schema. In the following example we set the max elements for an array using the `maxItems` property.\n\n```javascript\nconst schema = new Schemy({\n    maxItems: {\n        type: Number,\n        required: true\n    },\n    items: {\n        type: [String],\n        max: Schemy.$ref('maxItems')\n    }\n});\n\nschema.validate({\n    maxItems: 1,\n    items: ['one','two']\n}); // =\u003e false\n\nschema.getValidationErrors(); // =\u003e [ 'Property items must contain no more than 1 elements' ]\n```\n\n### Direct reference\nWe can also reference directly to a property if we want two properties to match. This is useful for password confirmation:\n\n```javascript\nconst schema = new Schemy({\n    username: String,\n    password: String,\n    confirm: Schemy.$ref('password')\n});\n\nschema.validate({\n    username: 'schemy',\n    password: 'password1',\n    confirm: 'password2'\n}); // =\u003e false\n\nschema.getValidationErrors(); // =\u003e [ 'Property confirm does not match referenced value: password' ]\n```\n\n\n## Notes\n- Requires Schemy version **\u003e= 3.2.1**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faeberdinelli%2Fschemy-reference-support","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faeberdinelli%2Fschemy-reference-support","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faeberdinelli%2Fschemy-reference-support/lists"}