# @fastify/merge-json-schemas
[](https://github.com/fastify/merge-json-schemas/actions/workflows/ci.yml)
[](https://www.npmjs.com/package/@fastify/merge-json-schemas)
[](https://github.com/neostandard/neostandard)
__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).
- [Installation](#installation)
- [Usage](#usage)
- [API](#api)
- [mergeSchemas(schemas, options)](#mergeschemasschemas-options)
- [resolvers](#resolvers)
- [defaultResolver](#defaultresolver)
- [License](#license)
## Installation
```bash
npm i @fastify/merge-json-schemas
```
## Usage
```javascript
const assert = require('node:assert')
const { mergeSchemas } = require('@fastify/merge-json-schemas');
const schema1 = {
$id: 'schema1',
type: 'object',
properties: {
foo: { type: 'string', enum: ['foo1', 'foo2'] },
bar: { type: 'string', minLength: 3 }
}
}
const schema2 = {
$id: 'schema1',
type: 'object',
properties: {
foo: { type: 'string', enum: ['foo1', 'foo3'] },
bar: { type: 'string', minLength: 5 }
},
required: ['foo']
}
const mergedSchema = mergeSchemas([schema1, schema2])
assert.deepStrictEqual(mergedSchema, {
$id: 'schema1',
type: 'object',
properties: {
foo: { type: 'string', enum: ['foo1'] },
bar: { type: 'string', minLength: 5 }
},
required: ['foo']
})
```
## API
#### mergeSchemas(schemas, options)
Builds a logical conjunction (AND) of multiple [JSON schemas](https://json-schema.org/draft/2020-12/json-schema-core#name-introduction).
- `schemas` __\__ - list of JSON schemas to merge
- `options` __\