{"id":24387180,"url":"https://github.com/hyperweb-io/json-schema-patch","last_synced_at":"2025-03-12T19:45:27.469Z","repository":{"id":240212816,"uuid":"801991842","full_name":"hyperweb-io/json-schema-patch","owner":"hyperweb-io","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-26T20:53:10.000Z","size":68,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-13T00:18:17.125Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/hyperweb-io.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":"2024-05-17T09:58:37.000Z","updated_at":"2025-01-17T23:39:59.000Z","dependencies_parsed_at":"2024-05-17T11:25:12.989Z","dependency_job_id":"125be1f3-649b-4977-9078-f08ed91ab160","html_url":"https://github.com/hyperweb-io/json-schema-patch","commit_stats":null,"previous_names":["cosmology-tech/json-schema-patch","hyperweb-io/json-schema-patch"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperweb-io%2Fjson-schema-patch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperweb-io%2Fjson-schema-patch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperweb-io%2Fjson-schema-patch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperweb-io%2Fjson-schema-patch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyperweb-io","download_url":"https://codeload.github.com/hyperweb-io/json-schema-patch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243285602,"owners_count":20266846,"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":"2025-01-19T12:41:34.464Z","updated_at":"2025-03-12T19:45:27.460Z","avatar_url":"https://github.com/hyperweb-io.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json-schema-patch\n\n`json-schema-patch` provides a dynamic way to modify JSON schemas by applying a series of operations that can add, remove, or replace properties and definitions within the schema.\n\n## Features\n\n- Add, remove, and replace properties within a JSON schema.\n- Manage schema `$defs` with operations to add and remove definitions.\n- Automatically handle dependencies and cleanup for removed definitions.\n\n## Installation\n\n```bash\nnpm install json-schema-patch\n```\n\n## Usage\n\n### import the `JSONSchemaPatch` class\n\n```js\nimport { JSONSchemaPatch } from 'json-schema-patch';\n```\n\n### Create an instance\n\n```js\nconst schema = {\n  $defs: {\n    asset: { type: \"object\", properties: { id: { type: \"number\" } } },\n    product: { type: \"object\", properties: { name: { type: \"string\" } } }\n  },\n  properties: {\n    name: { type: \"string\" },\n    item: {\n      allOf: [\n        { $ref: \"#/$defs/asset\" },\n        { $ref: \"#/$defs/product\" }\n      ]\n    },\n    equipment: {\n      allOf: [\n        { $ref: \"#/$defs/asset\" }\n      ]\n    }\n  },\n  required: [\"name\", \"item\", \"equipment\"]\n};\n\nconst patcher = new JSONSchemaPatch(schema);\n```\n\n### Applying Operations\n\n```js\n// Add a new definition\npatcher.addDefinition('newDef', { type: \"object\", properties: { newProp: { type: \"string\" } } });\n\n// Remove a definition and clean up references\npatcher.removeDefinition('asset');\n\n// Add a new property\npatcher.addProperty('/properties', 'newProp', { type: \"number\" });\n\n// Remove a property\npatcher.removeProperty('/properties', 'item');\n\n// Apply all prepared operations and finalize changes\npatcher.applyPatch();\n\nconsole.log(schema);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperweb-io%2Fjson-schema-patch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperweb-io%2Fjson-schema-patch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperweb-io%2Fjson-schema-patch/lists"}