{"_id":"@fastify/merge-json-schemas@0.2.2","bugs":{"url":"https://github.com/fastify/merge-json-schemas/issues"},"dist":{"shasum":"2f461fe22ff405d8fd0d46463871a362559f7cfc","tarball":"http://registry-npm.ywwl.com/@fastify/merge-json-schemas/download/@fastify/merge-json-schemas-0.2.2.tgz","fileCount":54,"integrity":"sha512-d/gx9sRbUCVgGRGzma46wLcwiY8noTqO2Nmjg/vbTARxHRE5bdh5PIL8s97Lt1X7ScRWRW52eVYxwIoPwIdVUA==","signatures":[{"sig":"MEYCIQC2qfySUKhPBOeUNEiqIdymsXc/QjHv1uTF/M8IMkkaagIhAL0OoyZpKoj52aGsqZsXaQRBEVpjzPxflPA7uBeVXRHH","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC7JkIBxsu2LSV4aNyL1yC+VSlaslNFip9qa0hNn7dNPwIhAJOcJshJ1XmyVH8+nZARgl3P1e1ECnoSF1eSdRtAKFcZ"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@fastify%2fmerge-json-schemas@0.2.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":104760,"size":13392,"noattachment":false,"key":"/@fastify/merge-json-schemas/-/@fastify/merge-json-schemas-0.2.2.tgz"},"main":"index.js","name":"@fastify/merge-json-schemas","type":"commonjs","types":"types/index.d.ts","author":{"name":"Ivan Tymoshenko","email":"ivan@tymoshenko.me"},"funding":[{"url":"https://github.com/sponsors/fastify","type":"github"},{"url":"https://opencollective.com/fastify","type":"opencollective"}],"gitHead":"9d855db675b409a5fcd993480d98feb80de9f4b8","license":"MIT","scripts":{"lint":"eslint","test":"npm run test:unit && npm run test:types","lint:fix":"eslint --fix","test:unit":"c8 --100 node --test","test:types":"tstyche"},"version":"0.2.2","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"3622d285-dec3-4b49-bff3-28cd41193877"}},"homepage":"https://github.com/fastify/merge-json-schemas#readme","keywords":["json","schema","merge","allOf"],"repository":{"url":"git+https://github.com/fastify/merge-json-schemas.git","type":"git"},"_npmVersion":"11.19.0","description":"Builds a logical conjunction (AND) of multiple JSON schemas","directories":{},"maintainers":[{"name":"eomm","email":"behemoth89@gmail.com"}],"_nodeVersion":"24.21.0","contributors":[{"name":"Matteo Collina","email":"hello@matteocollina.com"},{"url":"https://github.com/fdawgs","name":"Frazer Smith","email":"frazer.dev@icloud.com"},{"url":"https://heyhey.to/G","name":"Gürgün Dayıoğlu","email":"hey@gurgun.day"}],"dependencies":{"dequal":"^2.0.3"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^12.0.0","eslint":"^9.17.0","tstyche":"^7.0.0","neostandard":"^0.13.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/merge-json-schemas_0.2.2_1791628116150_0.14031023169728662"},"readme":"# @fastify/merge-json-schemas\n\n[![CI](https://github.com/fastify/merge-json-schemas/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/merge-json-schemas/actions/workflows/ci.yml)\n[![npm version](https://img.shields.io/npm/v/@fastify/merge-json-schemas)](https://www.npmjs.com/package/@fastify/merge-json-schemas)\n[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)\n\n__merge-json-schemas__ is a JavaScript library that builds a logical product (AND) for multiple [JSON schemas](https://json-schema.org/draft/2020-12/json-schema-core#name-introduction).\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [API](#api)\n  - [mergeSchemas(schemas, options)](#mergeschemasschemas-options)\n  - [resolvers](#resolvers)\n  - [defaultResolver](#defaultresolver)\n- [License](#license)\n\n<a name=\"installation\"></a>\n\n## Installation\n\n```bash\nnpm i @fastify/merge-json-schemas\n```\n\n<a name=\"usage\"></a>\n\n## Usage\n\n```javascript\nconst assert = require('node:assert')\nconst { mergeSchemas } = require('@fastify/merge-json-schemas');\n\nconst schema1 = {\n  $id: 'schema1',\n  type: 'object',\n  properties: {\n    foo: { type: 'string', enum: ['foo1', 'foo2'] },\n    bar: { type: 'string', minLength: 3 }\n  }\n}\n\nconst schema2 = {\n  $id: 'schema1',\n  type: 'object',\n  properties: {\n    foo: { type: 'string', enum: ['foo1', 'foo3'] },\n    bar: { type: 'string', minLength: 5 }\n  },\n  required: ['foo']\n}\n\nconst mergedSchema = mergeSchemas([schema1, schema2])\nassert.deepStrictEqual(mergedSchema, {\n  $id: 'schema1',\n  type: 'object',\n  properties: {\n    foo: { type: 'string', enum: ['foo1'] },\n    bar: { type: 'string', minLength: 5 }\n  },\n  required: ['foo']\n})\n```\n\n<a name=\"api\"></a>\n\n## API\n\n<a name=\"merge-schemas\"></a>\n\n#### mergeSchemas(schemas, options)\n\nBuilds a logical conjunction (AND) of multiple [JSON schemas](https://json-schema.org/draft/2020-12/json-schema-core#name-introduction).\n\n- `schemas` __\\<objects[]\\>__ - list of JSON schemas to merge\n- `options` __\\<object\\>__ - optional options\n  - `resolvers` __\\<object\\>__ - custom resolvers for JSON schema keywords. Each key is the name of a JSON schema keyword. Each value is a resolver function. See [keywordResolver](#keywordresolver-keyword-values-mergedschema-parentschemas-options)\n  - `defaultResolver` __\\<function\\>__ - custom default resolver for JSON schema keywords. See [keywordResolver](#keywordresolver-keyword-values-mergedschema-parentschemas-options)\n  - `onConflict` __\\<string\\>__ - action to take when a conflict is found. Used by the default `defaultResolver`. Default is `throw`. Possible values are:\n    - `throw` - throws an error multiple different schemas for the same keyword are found\n    - `ignore` - do nothing if multiple different schemas for the same keyword are found\n    - `first` - use the value of the first schema if multiple different schemas for the same keyword are found\n\n#### resolvers\n\nA list of default resolvers that __merge-json-schema__ uses to merge JSON schemas. You can override the default resolvers by passing a list of custom resolvers in the `options` argument of `mergeSchemas`. See [keywordResolver](#keywordresolver-keyword-values-mergedschema-parentschemas-options).\n\n#### defaultResolver\n\nA default resolver that __merge-json-schema__ uses to merge JSON schemas. Default resolver is used when no custom resolver is defined for a JSON schema keyword. By default, the default resolver works as follows:\n\n- If only one schema contains the keyword, the value of the keyword is used as the merged value\n- If multiple schemas contain the exact same value for the keyword, the value of the keyword is used as the merged value\n- If multiple schemas contain different values for the keyword, it throws an error\n\n#### keywordResolver (keyword, values, mergedSchema, parentSchemas, options)\n\n__merge-json-schema__ uses a set of resolvers to merge JSON schemas. Each resolver is associated with a JSON schema keyword. The resolver is called when the keyword is found in the schemas to merge. The resolver is called with the following arguments:\n\n- `keyword` __\\<string\\>__ - the name of the keyword to merge\n- `values` __\\<any[]\\>__ - the values of the keyword to merge. The length of the array is equal to the number of schemas to merge. If a schema does not contain the keyword, the value is `undefined`\n- `mergedSchema` __\\<object\\>__ - an instance of the merged schema\n- `parentSchemas` __\\<object[]\\>__ - the list of parent schemas\n- `options` __\\<object\\>__ - the options passed to `mergeSchemas`\n\nThe resolver must set the merged value of the `keyword` in the `mergedSchema` object.\n\n__Example:__ resolver for the `minNumber` keyword.\n\n```javascript\nfunction minNumberResolver (keyword, values, mergedSchema) {\n  mergedSchema[keyword] = Math.min(...values)\n}\n```\n\n<a name=\"license\"></a>\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","publish_time":1791628116264,"_cnpm_publish_time":1791628116264,"dist-tags":{"latest":"0.2.2"}}