{"id":18174560,"url":"https://github.com/udamir/allof-merge","last_synced_at":"2025-04-03T05:30:38.092Z","repository":{"id":176146901,"uuid":"654923338","full_name":"udamir/allof-merge","owner":"udamir","description":"Simplify your JsonSchema by combining allOf safely.","archived":false,"fork":false,"pushed_at":"2025-04-02T21:59:22.000Z","size":804,"stargazers_count":19,"open_issues_count":2,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T22:30:31.460Z","etag":null,"topics":["allof","json","json-schema","merge","si","simplicity"],"latest_commit_sha":null,"homepage":"","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/udamir.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":"2023-06-17T10:45:41.000Z","updated_at":"2025-04-02T21:59:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"bd8a397d-aa72-4fb8-86cb-4cd3fc5c3125","html_url":"https://github.com/udamir/allof-merge","commit_stats":null,"previous_names":["udamir/allof-merge"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udamir%2Fallof-merge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udamir%2Fallof-merge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udamir%2Fallof-merge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udamir%2Fallof-merge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/udamir","download_url":"https://codeload.github.com/udamir/allof-merge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246905811,"owners_count":20852818,"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":["allof","json","json-schema","merge","si","simplicity"],"created_at":"2024-11-02T16:03:34.590Z","updated_at":"2025-04-03T05:30:38.080Z","avatar_url":"https://github.com/udamir.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# allof-merge\n\u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/v/allof-merge\"\u003e \u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/dm/allof-merge?label=npm\"\u003e ![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/udamir/allof-merge/ci.yml)\n \u003cimg alt=\"npm type definitions\" src=\"https://img.shields.io/npm/types/allof-merge\"\u003e ![Coveralls branch](https://img.shields.io/coverallsCoverage/github/udamir/allof-merge) \u003cimg alt=\"GitHub\" src=\"https://img.shields.io/github/license/udamir/allof-merge\"\u003e\n\nMerge schemas with allOf into a more readable composed schema free from allOf.\n\n## Features\n- Safe merging of schemas combined with allOf in whole document\n- Fastest implmentation - up to x3 times faster then other popular libraries\n- Merged schema does not validate more or less than the original schema\n- Removes almost all logical impossibilities\n- Correctly merge additionalProperties, patternProperties and properties taking into account common validations\n- Correctly merge items and additionalItems taking into account common validations\n- Supports custom rules to merge other document types and JsonSchema versions\n- Supports input with circular references (javaScript references)\n- Supports $refs and circular $refs either (internal references only)\n- Correctly merge of $refs with sibling content (optionally)\n- Correctly merge of combinaries (anyOf, oneOf) with sibling content (optionally)\n- Typescript syntax support out of the box\n- No dependencies (except json-crawl), can be used in nodejs or browser\n\n## Works perfectly with specifications:\n\n- [JsonSchema](https://json-schema.org/draft/2020-12/json-schema-core.html)\n- [OpenApi 3.x](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md)\n- [GraphApi](https://github.com/udamir/graphapi)\n- ~~Swagger 2.x~~ (roadmap)\n- ~~AsyncApi 2.x~~ (roadmap)\n- ~~AsyncApi 3.x~~ (roadmap)\n\n## Other libraries\nThere are some libraries that can merge schemas combined with allOf. One of the most popular is [mokkabonna/json-schema-merge-allof](https://www.npmjs.com/package/json-schema-merge-allof), but it has some limitatons: Does not support circular $refs and no Typescript syntax out of the box.\n\n## External $ref\nIf schema contains an external $ref, you should bundle it via [api-ref-bundler](https://github.com/udamir/api-ref-bundler) first.\n\n## Installation\n```SH\nnpm install allof-merge --save\n```\n\n## Usage\n\n### Nodejs\n```ts\nimport { merge } from 'allof-merge'\n\nconst data = {\n  type: ['object', 'null'],\n  additionalProperties: {\n    type: 'string',\n    minLength: 5\n  },\n  allOf: [{\n    type: ['array', 'object'],\n    additionalProperties: {\n      type: 'string',\n      minLength: 10,\n      maxLength: 20\n    }\n  }]\n}\n\nconst onMergeError = (msg) =\u003e {\n  throw new Error(msg)\n}\n\nconst merged = merge(data, { onMergeError })\n\nconsole.log(merged)\n// {\n//   type: 'object',\n//   additionalProperties: {\n//     type: 'string',\n//     minLength: 10,\n//     maxLength: 20\n//   }\n// }\n\n```\n\n### Browsers\n\nA browser version of `allof-merge` is also available via CDN:\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/allof-merge@latest/browser/allof-merge.min.js\"\u003e\u003c/script\u003e\n```\n\nReference `allof-merge.min.js` in your HTML and use the global variable `AllOfMerge`.\n```HTML\n\u003cscript\u003e\n  var merged = AllOfMerge.merge({ /* ... */ })\n\u003c/script\u003e\n```\n\n## Documentation\n\n### `merge(data: any, options?: MergeOptions)`\nCreate a copy of `data` with merged allOf schemas:\n\n\n### Merge options\n```ts\ninterface MergeOptions {\n  // source document if merging only part of it\n  // (optional) default = data\n  source?: any          \n  \n  // custom merge rules\n  // (optional) default = auto select based on the input (jsonSchemaMergeRules, openApiMergeRules, graphapiMergeRules)\n  rules?: MergeRules    \n\n  // merge $ref with sibling content\n  // (optional) default = false\n  mergeRefSibling?: boolean  \n\n  // merge anyOf/oneOf with sibling content\n  // (optional) default = false\n  mergeCombinarySibling?: boolean  \n\n  // Merge error hook, called on any merge conflicts\n  onMergeError?: (message: string, path: JsonPath, values: any[]) =\u003e void\n\n  // Ref resolve error hook, called on broken ref\n  onRefResolveError?: (message: string, path: JsonPath, ref: string) =\u003e void\n}\n```\n\n### Supported rules\nYou can find supported rules in the src/rules directory of this repository:\n- `jsonSchemaMergeRules(version: \"draft-04\" | \"draft-06\")`\n- `openApiMergeRules(version: \"3.0.x\" | \"3.1.x\")`\n- `graphapiMergeRules`\n\n## Benchmark\n```\nallof-merge x 657 ops/sec ±2.35% (90 runs sampled)\njson-schema-merge-allof x 217 ops/sec ±2.03% (86 runs sampled)\nFastest is allof-merge\n```\n\nCheck yourself:\n```SH\nnpm run benchmark\n```\n\n## Contributing\nWhen contributing, keep in mind that it is an objective of `allof-merge` to have no additional package dependencies.\n\nPlease run the unit tests before submitting your PR: `yarn test`. Hopefully your PR includes additional unit tests to illustrate your change/modification!\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fudamir%2Fallof-merge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fudamir%2Fallof-merge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fudamir%2Fallof-merge/lists"}