First commit
This commit is contained in:
164
node_modules/@fastify/merge-json-schemas/test/additional-items.test.js
generated
vendored
Normal file
164
node_modules/@fastify/merge-json-schemas/test/additional-items.test.js
generated
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and additionalItems = false keyword', () => {
|
||||
const schema1 = { type: 'array' }
|
||||
const schema2 = {
|
||||
type: 'array',
|
||||
additionalItems: false
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'array',
|
||||
additionalItems: false
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two schemas with boolean additionalItems', () => {
|
||||
const schema1 = {
|
||||
type: 'array',
|
||||
additionalItems: true
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'array',
|
||||
additionalItems: false
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'array',
|
||||
additionalItems: false
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge additionalItems schema with false value', () => {
|
||||
const schema1 = {
|
||||
type: 'array',
|
||||
additionalItems: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'array',
|
||||
additionalItems: false
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'array',
|
||||
additionalItems: false
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge additionalItems schema with true value', () => {
|
||||
const schema1 = {
|
||||
type: 'array',
|
||||
additionalItems: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'array',
|
||||
additionalItems: true
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'array',
|
||||
additionalItems: {
|
||||
type: 'string'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two additionalItems schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'array',
|
||||
additionalItems: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'array',
|
||||
additionalItems: {
|
||||
type: 'string', minLength: 1
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'array',
|
||||
additionalItems: {
|
||||
type: 'string', minLength: 1
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge additionalItems with items array', () => {
|
||||
const schema1 = {
|
||||
type: 'array',
|
||||
items: [
|
||||
{ type: 'string', const: 'foo1' },
|
||||
{ type: 'string', const: 'foo2' },
|
||||
{ type: 'string', const: 'foo3' }
|
||||
]
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'array',
|
||||
additionalItems: {
|
||||
type: 'string', minLength: 42
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'array',
|
||||
items: [
|
||||
{ type: 'string', const: 'foo1', minLength: 42 },
|
||||
{ type: 'string', const: 'foo2', minLength: 42 },
|
||||
{ type: 'string', const: 'foo3', minLength: 42 }
|
||||
],
|
||||
additionalItems: {
|
||||
type: 'string', minLength: 42
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge items array and additionalItems with items array', () => {
|
||||
const schema1 = {
|
||||
type: 'array',
|
||||
items: [
|
||||
{ type: 'string', const: 'foo1' },
|
||||
{ type: 'string', const: 'foo2' },
|
||||
{ type: 'string', const: 'foo3' }
|
||||
]
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'array',
|
||||
items: [
|
||||
{ type: 'string', minLength: 1 },
|
||||
{ type: 'string', minLength: 2 }
|
||||
],
|
||||
additionalItems: {
|
||||
type: 'string', minLength: 3
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'array',
|
||||
items: [
|
||||
{ type: 'string', const: 'foo1', minLength: 1 },
|
||||
{ type: 'string', const: 'foo2', minLength: 2 },
|
||||
{ type: 'string', const: 'foo3', minLength: 3 }
|
||||
],
|
||||
additionalItems: {
|
||||
type: 'string', minLength: 3
|
||||
}
|
||||
})
|
||||
})
|
||||
129
node_modules/@fastify/merge-json-schemas/test/additional-properties.test.js
generated
vendored
Normal file
129
node_modules/@fastify/merge-json-schemas/test/additional-properties.test.js
generated
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and additionalProperties=false keyword', () => {
|
||||
const schema1 = { type: 'object' }
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
additionalProperties: false
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
additionalProperties: false
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two schemas with boolean additionalProperties', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
additionalProperties: true
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
additionalProperties: false
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
additionalProperties: false
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge additionalProperties schema with false value', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
additionalProperties: false
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
additionalProperties: false
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge additionalProperties schema with true value', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
additionalProperties: true
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: 'string'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two additionalProperties schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: 'string', minLength: 1
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: 'string', minLength: 1
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two additionalProperties and properties schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: ['string', 'number'] }
|
||||
},
|
||||
additionalProperties: {
|
||||
type: 'string', minLength: 1
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' }
|
||||
},
|
||||
additionalProperties: {
|
||||
type: 'string', minLength: 1
|
||||
}
|
||||
})
|
||||
})
|
||||
43
node_modules/@fastify/merge-json-schemas/test/all-of.test.js
generated
vendored
Normal file
43
node_modules/@fastify/merge-json-schemas/test/all-of.test.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and allOf keyword', () => {
|
||||
const schema1 = {}
|
||||
const schema2 = {
|
||||
allOf: [
|
||||
{ type: 'string', const: 'foo' }
|
||||
]
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
allOf: [
|
||||
{ type: 'string', const: 'foo' }
|
||||
]
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge schemas with allOfs schemas', () => {
|
||||
const schema1 = {
|
||||
allOf: [
|
||||
{ type: 'number', minimum: 0 }
|
||||
]
|
||||
}
|
||||
const schema2 = {
|
||||
allOf: [
|
||||
{ type: 'string', const: 'foo' }
|
||||
]
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
allOf: [
|
||||
{ type: 'number', minimum: 0 },
|
||||
{ type: 'string', const: 'foo' }
|
||||
]
|
||||
})
|
||||
})
|
||||
81
node_modules/@fastify/merge-json-schemas/test/any-of.test.js
generated
vendored
Normal file
81
node_modules/@fastify/merge-json-schemas/test/any-of.test.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and anyOf keyword', () => {
|
||||
const schema1 = {}
|
||||
const schema2 = {
|
||||
anyOf: [
|
||||
{ type: 'string', const: 'foo' }
|
||||
]
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
anyOf: [
|
||||
{ type: 'string', const: 'foo' }
|
||||
]
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two schemas with anyOfs schemas', () => {
|
||||
const schema1 = {
|
||||
anyOf: [
|
||||
{ type: 'string', enum: ['foo1', 'foo2', 'foo3'] },
|
||||
{ type: 'string', enum: ['foo3', 'foo4', 'foo5'] }
|
||||
]
|
||||
}
|
||||
const schema2 = {
|
||||
anyOf: [
|
||||
{ type: 'string', enum: ['foo2', 'foo3', 'foo4'] },
|
||||
{ type: 'string', enum: ['foo3', 'foo6', 'foo7'] }
|
||||
]
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
anyOf: [
|
||||
{ type: 'string', enum: ['foo2', 'foo3'] },
|
||||
{ type: 'string', enum: ['foo3'] },
|
||||
{ type: 'string', enum: ['foo3', 'foo4'] },
|
||||
{ type: 'string', enum: ['foo3'] }
|
||||
]
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge three schemas with anyOfs schemas', () => {
|
||||
const schema1 = {
|
||||
anyOf: [
|
||||
{ type: 'string', enum: ['foo1', 'foo2', 'foo3', 'foo4'] },
|
||||
{ type: 'string', enum: ['foo3', 'foo4', 'foo5', 'foo7'] }
|
||||
]
|
||||
}
|
||||
const schema2 = {
|
||||
anyOf: [
|
||||
{ type: 'string', enum: ['foo2', 'foo3', 'foo4', 'foo5'] },
|
||||
{ type: 'string', enum: ['foo3', 'foo6', 'foo7', 'foo8'] }
|
||||
]
|
||||
}
|
||||
|
||||
const schema3 = {
|
||||
anyOf: [
|
||||
{ type: 'string', enum: ['foo1', 'foo3', 'foo5', 'foo7'] },
|
||||
{ type: 'string', enum: ['foo2', 'foo4', 'foo6', 'foo8'] }
|
||||
]
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2, schema3], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
anyOf: [
|
||||
{ type: 'string', enum: ['foo3'] },
|
||||
{ type: 'string', enum: ['foo2', 'foo4'] },
|
||||
{ type: 'string', enum: ['foo3'] },
|
||||
{ type: 'string', enum: ['foo3', 'foo5'] },
|
||||
{ type: 'string', enum: ['foo4'] },
|
||||
{ type: 'string', enum: ['foo3', 'foo7'] }
|
||||
]
|
||||
})
|
||||
})
|
||||
58
node_modules/@fastify/merge-json-schemas/test/const.test.js
generated
vendored
Normal file
58
node_modules/@fastify/merge-json-schemas/test/const.test.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and string const keyword', () => {
|
||||
const schema1 = { type: 'string' }
|
||||
const schema2 = { type: 'string', const: 'foo' }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', const: 'foo' })
|
||||
})
|
||||
|
||||
test('should merge equal string const keywords', () => {
|
||||
const schema1 = { type: 'string', const: 'foo' }
|
||||
const schema2 = { type: 'string', const: 'foo' }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', const: 'foo' })
|
||||
})
|
||||
|
||||
test('should merge equal object const keywords', () => {
|
||||
const schema1 = { type: 'string', const: { foo: 'bar' } }
|
||||
const schema2 = { type: 'string', const: { foo: 'bar' } }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', const: { foo: 'bar' } })
|
||||
})
|
||||
|
||||
test('should throw an error if const string values are different', () => {
|
||||
const schema1 = { type: 'string', const: 'foo' }
|
||||
const schema2 = { type: 'string', const: 'bar' }
|
||||
|
||||
assert.throws(() => {
|
||||
mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
}, {
|
||||
name: 'JsonSchemaMergeError',
|
||||
code: 'JSON_SCHEMA_MERGE_ERROR',
|
||||
message: 'Failed to merge "const" keyword schemas.',
|
||||
schemas: ['foo', 'bar']
|
||||
})
|
||||
})
|
||||
|
||||
test('should throw an error if const object values are different', () => {
|
||||
const schema1 = { type: 'object', const: { foo: 'bar' } }
|
||||
const schema2 = { type: 'object', const: { foo: 'baz' } }
|
||||
|
||||
assert.throws(() => {
|
||||
mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
}, {
|
||||
name: 'JsonSchemaMergeError',
|
||||
code: 'JSON_SCHEMA_MERGE_ERROR',
|
||||
message: 'Failed to merge "const" keyword schemas.',
|
||||
schemas: [{ foo: 'bar' }, { foo: 'baz' }]
|
||||
})
|
||||
})
|
||||
55
node_modules/@fastify/merge-json-schemas/test/contains.test.js
generated
vendored
Normal file
55
node_modules/@fastify/merge-json-schemas/test/contains.test.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and contains keyword', () => {
|
||||
const schema1 = {}
|
||||
const schema2 = {
|
||||
type: 'array',
|
||||
contains: {
|
||||
type: 'integer',
|
||||
minimum: 5
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'array',
|
||||
contains: {
|
||||
type: 'integer',
|
||||
minimum: 5
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two contains keyword schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'array',
|
||||
contains: {
|
||||
type: 'integer',
|
||||
minimum: 5,
|
||||
maximum: 14
|
||||
}
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'array',
|
||||
contains: {
|
||||
type: 'integer',
|
||||
minimum: 9,
|
||||
maximum: 10
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'array',
|
||||
contains: {
|
||||
type: 'integer',
|
||||
minimum: 9,
|
||||
maximum: 10
|
||||
}
|
||||
})
|
||||
})
|
||||
50
node_modules/@fastify/merge-json-schemas/test/custom-resolvers.test.js
generated
vendored
Normal file
50
node_modules/@fastify/merge-json-schemas/test/custom-resolvers.test.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should use a custom resolver instead of default one', () => {
|
||||
const schema1 = { type: 'string' }
|
||||
const schema2 = { type: 'number' }
|
||||
|
||||
const mergedSchema = mergeSchemas(
|
||||
[schema1, schema2],
|
||||
{
|
||||
resolvers: {
|
||||
type: (keyword, values, mergedSchema, schemas) => {
|
||||
assert.strictEqual(keyword, 'type')
|
||||
assert.deepStrictEqual(values, ['string', 'number'])
|
||||
assert.deepStrictEqual(schemas, [schema1, schema2])
|
||||
|
||||
mergedSchema[keyword] = 'custom-type'
|
||||
}
|
||||
},
|
||||
defaultResolver
|
||||
}
|
||||
)
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'custom-type' })
|
||||
})
|
||||
|
||||
test('should use a custom resolver for unknown keyword', () => {
|
||||
const schema1 = { customKeyword: 'string' }
|
||||
const schema2 = { customKeyword: 'number' }
|
||||
|
||||
const mergedSchema = mergeSchemas(
|
||||
[schema1, schema2],
|
||||
{
|
||||
resolvers: {
|
||||
customKeyword: (keyword, values, mergedSchema, schemas) => {
|
||||
assert.strictEqual(keyword, 'customKeyword')
|
||||
assert.deepStrictEqual(values, ['string', 'number'])
|
||||
assert.deepStrictEqual(schemas, [schema1, schema2])
|
||||
|
||||
mergedSchema[keyword] = 'custom-type'
|
||||
}
|
||||
},
|
||||
defaultResolver
|
||||
}
|
||||
)
|
||||
assert.deepStrictEqual(mergedSchema, { customKeyword: 'custom-type' })
|
||||
})
|
||||
111
node_modules/@fastify/merge-json-schemas/test/default-resolver.test.js
generated
vendored
Normal file
111
node_modules/@fastify/merge-json-schemas/test/default-resolver.test.js
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
|
||||
test('should merge an unknown keyword with an empty schema', () => {
|
||||
const schema1 = {}
|
||||
const schema2 = { customKeyword: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2])
|
||||
assert.deepStrictEqual(mergedSchema, { customKeyword: 42 })
|
||||
})
|
||||
|
||||
test('should merge two equal unknown keywords', () => {
|
||||
const schema1 = { customKeyword: 42 }
|
||||
const schema2 = { customKeyword: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2])
|
||||
assert.deepStrictEqual(mergedSchema, { customKeyword: 42 })
|
||||
})
|
||||
|
||||
test('should merge two equal unknown object keywords', () => {
|
||||
const schema1 = { type: 'string', customKeyword: { foo: 'bar' } }
|
||||
const schema2 = { type: 'string', customKeyword: { foo: 'bar' } }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2])
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'string',
|
||||
customKeyword: { foo: 'bar' }
|
||||
})
|
||||
})
|
||||
|
||||
test('should use custom defaultResolver if passed', () => {
|
||||
const schema1 = { type: 'string', customKeyword: 42 }
|
||||
const schema2 = { type: 'string', customKeyword: 43 }
|
||||
|
||||
const mergedSchema = mergeSchemas(
|
||||
[schema1, schema2],
|
||||
{
|
||||
defaultResolver: (keyword, values, mergedSchema, schemas) => {
|
||||
assert.strictEqual(keyword, 'customKeyword')
|
||||
assert.deepStrictEqual(values, [42, 43])
|
||||
assert.deepStrictEqual(schemas, [schema1, schema2])
|
||||
|
||||
mergedSchema.customKeyword = 'custom-value-42'
|
||||
}
|
||||
}
|
||||
)
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'string',
|
||||
customKeyword: 'custom-value-42'
|
||||
})
|
||||
})
|
||||
|
||||
test('should trow an error when merging two different unknown keywords', () => {
|
||||
const schema1 = { customKeyword: 42 }
|
||||
const schema2 = { customKeyword: 43 }
|
||||
|
||||
assert.throws(() => {
|
||||
mergeSchemas([schema1, schema2])
|
||||
}, {
|
||||
name: 'JsonSchemaMergeError',
|
||||
code: 'JSON_SCHEMA_MERGE_ERROR',
|
||||
message: 'Resolver for "customKeyword" keyword not found.',
|
||||
schemas: [42, 43]
|
||||
})
|
||||
})
|
||||
|
||||
test('should trow an error when merging two different unknown keywords with onConflict = throw', () => {
|
||||
const schema1 = { customKeyword: 42 }
|
||||
const schema2 = { customKeyword: 43 }
|
||||
|
||||
assert.throws(() => {
|
||||
mergeSchemas([schema1, schema2], { onConflict: 'throw' })
|
||||
}, {
|
||||
name: 'JsonSchemaMergeError',
|
||||
code: 'JSON_SCHEMA_MERGE_ERROR',
|
||||
message: 'Resolver for "customKeyword" keyword not found.',
|
||||
schemas: [42, 43]
|
||||
})
|
||||
})
|
||||
|
||||
test('should skip the keyword schemas if onConflict = skip', () => {
|
||||
const schema1 = { customKeyword: 42 }
|
||||
const schema2 = { customKeyword: 43 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { onConflict: 'skip' })
|
||||
assert.deepStrictEqual(mergedSchema, {})
|
||||
})
|
||||
|
||||
test('should pick first schema if onConflict = first', () => {
|
||||
const schema1 = { customKeyword: 42 }
|
||||
const schema2 = { customKeyword: 43 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { onConflict: 'first' })
|
||||
assert.deepStrictEqual(mergedSchema, { customKeyword: 42 })
|
||||
})
|
||||
|
||||
test('should throw an error if pass wrong onConflict value', () => {
|
||||
const schema1 = { customKeyword: 42 }
|
||||
const schema2 = { customKeyword: 43 }
|
||||
|
||||
assert.throws(() => {
|
||||
mergeSchemas([schema1, schema2], { onConflict: 'foo' })
|
||||
}, {
|
||||
name: 'JsonSchemaMergeError',
|
||||
code: 'JSON_SCHEMA_MERGE_ERROR',
|
||||
message: 'Invalid "onConflict" option: "foo".'
|
||||
})
|
||||
})
|
||||
50
node_modules/@fastify/merge-json-schemas/test/default.test.js
generated
vendored
Normal file
50
node_modules/@fastify/merge-json-schemas/test/default.test.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and string default keyword', () => {
|
||||
const schema1 = { type: 'string' }
|
||||
const schema2 = { type: 'string', default: 'foo' }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', default: 'foo' })
|
||||
})
|
||||
|
||||
test('should merge equal string default keywords', () => {
|
||||
const schema1 = { type: 'string', default: 'foo' }
|
||||
const schema2 = { type: 'string', default: 'foo' }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', default: 'foo' })
|
||||
})
|
||||
|
||||
test('should throw an error if default string values are different', () => {
|
||||
const schema1 = { type: 'string', default: 'foo' }
|
||||
const schema2 = { type: 'string', default: 'bar' }
|
||||
|
||||
assert.throws(() => {
|
||||
mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
}, {
|
||||
name: 'JsonSchemaMergeError',
|
||||
code: 'JSON_SCHEMA_MERGE_ERROR',
|
||||
message: 'Failed to merge "default" keyword schemas.',
|
||||
schemas: ['foo', 'bar']
|
||||
})
|
||||
})
|
||||
|
||||
test('should throw an error if default object values are different', () => {
|
||||
const schema1 = { type: 'object', default: { foo: 'bar' } }
|
||||
const schema2 = { type: 'object', default: { foo: 'baz' } }
|
||||
|
||||
assert.throws(() => {
|
||||
mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
}, {
|
||||
name: 'JsonSchemaMergeError',
|
||||
code: 'JSON_SCHEMA_MERGE_ERROR',
|
||||
message: 'Failed to merge "default" keyword schemas.',
|
||||
schemas: [{ foo: 'bar' }, { foo: 'baz' }]
|
||||
})
|
||||
})
|
||||
46
node_modules/@fastify/merge-json-schemas/test/definitions.test.js
generated
vendored
Normal file
46
node_modules/@fastify/merge-json-schemas/test/definitions.test.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and definitions keyword', () => {
|
||||
const schema1 = {}
|
||||
const schema2 = {
|
||||
definitions: {
|
||||
foo: { type: 'string', const: 'foo' }
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
definitions: {
|
||||
foo: { type: 'string', const: 'foo' }
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two definition schemas', () => {
|
||||
const schema1 = {
|
||||
definitions: {
|
||||
foo: { type: 'string', enum: ['foo', 'bar'] },
|
||||
bar: { type: 'string', enum: ['foo', 'bar'] }
|
||||
}
|
||||
}
|
||||
const schema2 = {
|
||||
definitions: {
|
||||
foo: { type: 'string', enum: ['foo'] },
|
||||
baz: { type: 'string' }
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
definitions: {
|
||||
foo: { type: 'string', enum: ['foo'] },
|
||||
bar: { type: 'string', enum: ['foo', 'bar'] },
|
||||
baz: { type: 'string' }
|
||||
}
|
||||
})
|
||||
})
|
||||
46
node_modules/@fastify/merge-json-schemas/test/defs.test.js
generated
vendored
Normal file
46
node_modules/@fastify/merge-json-schemas/test/defs.test.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and $defs keyword', () => {
|
||||
const schema1 = {}
|
||||
const schema2 = {
|
||||
$defs: {
|
||||
foo: { type: 'string', const: 'foo' }
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
$defs: {
|
||||
foo: { type: 'string', const: 'foo' }
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two definition schemas', () => {
|
||||
const schema1 = {
|
||||
$defs: {
|
||||
foo: { type: 'string', enum: ['foo', 'bar'] },
|
||||
bar: { type: 'string', enum: ['foo', 'bar'] }
|
||||
}
|
||||
}
|
||||
const schema2 = {
|
||||
$defs: {
|
||||
foo: { type: 'string', enum: ['foo'] },
|
||||
baz: { type: 'string' }
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
$defs: {
|
||||
foo: { type: 'string', enum: ['foo'] },
|
||||
bar: { type: 'string', enum: ['foo', 'bar'] },
|
||||
baz: { type: 'string' }
|
||||
}
|
||||
})
|
||||
})
|
||||
75
node_modules/@fastify/merge-json-schemas/test/dependencies.test.js
generated
vendored
Normal file
75
node_modules/@fastify/merge-json-schemas/test/dependencies.test.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and dependencies keyword', () => {
|
||||
const schema1 = {}
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'string' }
|
||||
},
|
||||
dependencies: {
|
||||
foo: ['bar']
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'string' }
|
||||
},
|
||||
dependencies: {
|
||||
foo: ['bar']
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two dependencies keyword schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'string' },
|
||||
que: { type: 'string' }
|
||||
},
|
||||
dependencies: {
|
||||
foo: ['bar', 'que'],
|
||||
bar: ['que']
|
||||
}
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'string' },
|
||||
baz: { type: 'string' }
|
||||
},
|
||||
dependencies: {
|
||||
foo: ['baz'],
|
||||
baz: ['foo']
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'string' },
|
||||
que: { type: 'string' },
|
||||
baz: { type: 'string' }
|
||||
},
|
||||
dependencies: {
|
||||
foo: ['bar', 'que', 'baz'],
|
||||
bar: ['que'],
|
||||
baz: ['foo']
|
||||
}
|
||||
})
|
||||
})
|
||||
75
node_modules/@fastify/merge-json-schemas/test/dependent-required.test.js
generated
vendored
Normal file
75
node_modules/@fastify/merge-json-schemas/test/dependent-required.test.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and dependentRequired keyword', () => {
|
||||
const schema1 = {}
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'string' }
|
||||
},
|
||||
dependentRequired: {
|
||||
foo: ['bar']
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'string' }
|
||||
},
|
||||
dependentRequired: {
|
||||
foo: ['bar']
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two dependentRequired keyword schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'string' },
|
||||
que: { type: 'string' }
|
||||
},
|
||||
dependentRequired: {
|
||||
foo: ['bar', 'que'],
|
||||
bar: ['que']
|
||||
}
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'string' },
|
||||
baz: { type: 'string' }
|
||||
},
|
||||
dependentRequired: {
|
||||
foo: ['baz'],
|
||||
baz: ['foo']
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'string' },
|
||||
que: { type: 'string' },
|
||||
baz: { type: 'string' }
|
||||
},
|
||||
dependentRequired: {
|
||||
foo: ['bar', 'que', 'baz'],
|
||||
bar: ['que'],
|
||||
baz: ['foo']
|
||||
}
|
||||
})
|
||||
})
|
||||
76
node_modules/@fastify/merge-json-schemas/test/dependent-schemas.test.js
generated
vendored
Normal file
76
node_modules/@fastify/merge-json-schemas/test/dependent-schemas.test.js
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and dependentRequired keyword', () => {
|
||||
const schema1 = {}
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'string' }
|
||||
},
|
||||
dependentSchemas: {
|
||||
foo: { required: ['bar'] }
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'string' }
|
||||
},
|
||||
dependentSchemas: {
|
||||
foo: { required: ['bar'] }
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two dependentRequired keyword schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'string' },
|
||||
que: { type: 'string' }
|
||||
},
|
||||
dependentSchemas: {
|
||||
foo: { required: ['bar', 'que'] },
|
||||
bar: { required: ['que'] }
|
||||
}
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'string' },
|
||||
baz: { type: 'string' }
|
||||
},
|
||||
dependentSchemas: {
|
||||
foo: { required: ['baz'] },
|
||||
baz: { required: ['foo'] }
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'string' },
|
||||
que: { type: 'string' },
|
||||
baz: { type: 'string' }
|
||||
},
|
||||
dependentSchemas: {
|
||||
foo: { required: ['bar', 'que', 'baz'] },
|
||||
bar: { required: ['que'] },
|
||||
baz: { required: ['foo'] }
|
||||
}
|
||||
})
|
||||
})
|
||||
44
node_modules/@fastify/merge-json-schemas/test/enum.test.js
generated
vendored
Normal file
44
node_modules/@fastify/merge-json-schemas/test/enum.test.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and string enum values', () => {
|
||||
const schema1 = { type: 'string' }
|
||||
const schema2 = { type: 'string', enum: ['foo', 'bar'] }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', enum: ['foo', 'bar'] })
|
||||
})
|
||||
|
||||
test('should merge equal string enum values', () => {
|
||||
const schema1 = { type: 'string', enum: ['foo', 'bar'] }
|
||||
const schema2 = { type: 'string', enum: ['foo', 'bar'] }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', enum: ['foo', 'bar'] })
|
||||
})
|
||||
|
||||
test('should merge different string enum values', () => {
|
||||
const schema1 = { type: 'string', enum: ['foo', 'bar'] }
|
||||
const schema2 = { type: 'string', enum: ['foo', 'baz'] }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', enum: ['foo'] })
|
||||
})
|
||||
|
||||
test('should throw an error if can not merge enum values', () => {
|
||||
const schema1 = { type: 'string', enum: ['foo', 'bar'] }
|
||||
const schema2 = { type: 'string', enum: ['baz', 'qux'] }
|
||||
|
||||
assert.throws(() => {
|
||||
mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
}, {
|
||||
name: 'JsonSchemaMergeError',
|
||||
code: 'JSON_SCHEMA_MERGE_ERROR',
|
||||
message: 'Failed to merge "enum" keyword schemas.',
|
||||
schemas: [['foo', 'bar'], ['baz', 'qux']]
|
||||
})
|
||||
})
|
||||
30
node_modules/@fastify/merge-json-schemas/test/exclusive-maximum.test.js
generated
vendored
Normal file
30
node_modules/@fastify/merge-json-schemas/test/exclusive-maximum.test.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and exclusiveMaximum keyword', () => {
|
||||
const schema1 = { type: 'number' }
|
||||
const schema2 = { type: 'number', exclusiveMaximum: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'number', exclusiveMaximum: 42 })
|
||||
})
|
||||
|
||||
test('should merge equal exclusiveMaximum values', () => {
|
||||
const schema1 = { type: 'number', exclusiveMaximum: 42 }
|
||||
const schema2 = { type: 'number', exclusiveMaximum: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'number', exclusiveMaximum: 42 })
|
||||
})
|
||||
|
||||
test('should merge different exclusiveMaximum values', () => {
|
||||
const schema1 = { type: 'integer', exclusiveMaximum: 42 }
|
||||
const schema2 = { type: 'integer', exclusiveMaximum: 43 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'integer', exclusiveMaximum: 42 })
|
||||
})
|
||||
30
node_modules/@fastify/merge-json-schemas/test/exclusive-minimum.test.js
generated
vendored
Normal file
30
node_modules/@fastify/merge-json-schemas/test/exclusive-minimum.test.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and exclusiveMinimum keyword', () => {
|
||||
const schema1 = { type: 'number' }
|
||||
const schema2 = { type: 'number', exclusiveMinimum: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'number', exclusiveMinimum: 42 })
|
||||
})
|
||||
|
||||
test('should merge equal exclusiveMinimum values', () => {
|
||||
const schema1 = { type: 'number', exclusiveMinimum: 42 }
|
||||
const schema2 = { type: 'number', exclusiveMinimum: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'number', exclusiveMinimum: 42 })
|
||||
})
|
||||
|
||||
test('should merge different exclusiveMinimum values', () => {
|
||||
const schema1 = { type: 'integer', exclusiveMinimum: 42 }
|
||||
const schema2 = { type: 'integer', exclusiveMinimum: 43 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'integer', exclusiveMinimum: 43 })
|
||||
})
|
||||
36
node_modules/@fastify/merge-json-schemas/test/format.test.js
generated
vendored
Normal file
36
node_modules/@fastify/merge-json-schemas/test/format.test.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and string format keyword', () => {
|
||||
const schema1 = { type: 'string' }
|
||||
const schema2 = { type: 'string', format: 'date-time' }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', format: 'date-time' })
|
||||
})
|
||||
|
||||
test('should merge equal string format keywords', () => {
|
||||
const schema1 = { type: 'string', format: 'date-time' }
|
||||
const schema2 = { type: 'string', format: 'date-time' }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', format: 'date-time' })
|
||||
})
|
||||
|
||||
test('should throw an error if format keyword values are different', () => {
|
||||
const schema1 = { type: 'string', format: 'date-time' }
|
||||
const schema2 = { type: 'string', format: 'date' }
|
||||
|
||||
assert.throws(() => {
|
||||
mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
}, {
|
||||
name: 'JsonSchemaMergeError',
|
||||
code: 'JSON_SCHEMA_MERGE_ERROR',
|
||||
message: 'Failed to merge "format" keyword schemas.',
|
||||
schemas: ['date-time', 'date']
|
||||
})
|
||||
})
|
||||
22
node_modules/@fastify/merge-json-schemas/test/id.test.js
generated
vendored
Normal file
22
node_modules/@fastify/merge-json-schemas/test/id.test.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should skip $id keyword if they are equal', () => {
|
||||
const schema1 = { $id: 'foo', type: 'string' }
|
||||
const schema2 = { $id: 'foo', type: 'string' }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string' })
|
||||
})
|
||||
|
||||
test('should skip $id keyword if they are different', () => {
|
||||
const schema1 = { $id: 'foo', type: 'string' }
|
||||
const schema2 = { $id: 'bar', type: 'string' }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string' })
|
||||
})
|
||||
550
node_modules/@fastify/merge-json-schemas/test/if-then-else.test.js
generated
vendored
Normal file
550
node_modules/@fastify/merge-json-schemas/test/if-then-else.test.js
generated
vendored
Normal file
@@ -0,0 +1,550 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and if/then/else keywords', () => {
|
||||
const schema1 = {}
|
||||
const schema2 = {
|
||||
if: {
|
||||
type: 'string',
|
||||
const: 'foo'
|
||||
},
|
||||
then: {
|
||||
type: 'string',
|
||||
const: 'bar'
|
||||
},
|
||||
else: {
|
||||
type: 'string',
|
||||
const: 'baz'
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
if: {
|
||||
type: 'string',
|
||||
const: 'foo'
|
||||
},
|
||||
then: {
|
||||
type: 'string',
|
||||
const: 'bar'
|
||||
},
|
||||
else: {
|
||||
type: 'string',
|
||||
const: 'baz'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge if/then/else schema with an empty schema', () => {
|
||||
const schema1 = {
|
||||
if: {
|
||||
type: 'string',
|
||||
const: 'foo'
|
||||
},
|
||||
then: {
|
||||
type: 'string',
|
||||
const: 'bar'
|
||||
},
|
||||
else: {
|
||||
type: 'string',
|
||||
const: 'baz'
|
||||
}
|
||||
}
|
||||
const schema2 = {}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
if: {
|
||||
type: 'string',
|
||||
const: 'foo'
|
||||
},
|
||||
then: {
|
||||
type: 'string',
|
||||
const: 'bar'
|
||||
},
|
||||
else: {
|
||||
type: 'string',
|
||||
const: 'baz'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two if/then/else schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo1: { type: 'string', const: 'foo1' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar1: { type: 'string', const: 'bar1' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
baz1: { type: 'string', const: 'baz1' }
|
||||
}
|
||||
}
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo2: { type: 'string', const: 'foo2' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar2: { type: 'string', const: 'bar2' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
baz2: { type: 'string', const: 'baz2' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo1: { type: 'string', const: 'foo1' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar1: { type: 'string', const: 'bar1' }
|
||||
},
|
||||
if: {
|
||||
properties: {
|
||||
foo2: { type: 'string', const: 'foo2' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar2: { type: 'string', const: 'bar2' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
baz2: { type: 'string', const: 'baz2' }
|
||||
}
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
baz1: { type: 'string', const: 'baz1' }
|
||||
},
|
||||
if: {
|
||||
properties: {
|
||||
foo2: { type: 'string', const: 'foo2' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar2: { type: 'string', const: 'bar2' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
baz2: { type: 'string', const: 'baz2' }
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge three if/then/else schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo1: { type: 'string', const: 'foo1' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar1: { type: 'string', const: 'bar1' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
baz1: { type: 'string', const: 'baz1' }
|
||||
}
|
||||
}
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo2: { type: 'string', const: 'foo2' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar2: { type: 'string', const: 'bar2' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
baz2: { type: 'string', const: 'baz2' }
|
||||
}
|
||||
}
|
||||
}
|
||||
const schema3 = {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo3: { type: 'string', const: 'foo3' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar3: { type: 'string', const: 'bar3' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
baz3: { type: 'string', const: 'baz3' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2, schema3], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo1: { type: 'string', const: 'foo1' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar1: { type: 'string', const: 'bar1' }
|
||||
},
|
||||
if: {
|
||||
properties: {
|
||||
foo2: { type: 'string', const: 'foo2' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar2: { type: 'string', const: 'bar2' }
|
||||
},
|
||||
if: {
|
||||
properties: {
|
||||
foo3: { type: 'string', const: 'foo3' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar3: { type: 'string', const: 'bar3' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
baz3: { type: 'string', const: 'baz3' }
|
||||
}
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
baz2: { type: 'string', const: 'baz2' }
|
||||
},
|
||||
if: {
|
||||
properties: {
|
||||
foo3: { type: 'string', const: 'foo3' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar3: { type: 'string', const: 'bar3' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
baz3: { type: 'string', const: 'baz3' }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
baz1: { type: 'string', const: 'baz1' }
|
||||
},
|
||||
if: {
|
||||
properties: {
|
||||
foo2: { type: 'string', const: 'foo2' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar2: { type: 'string', const: 'bar2' }
|
||||
},
|
||||
if: {
|
||||
properties: {
|
||||
foo3: { type: 'string', const: 'foo3' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar3: { type: 'string', const: 'bar3' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
baz3: { type: 'string', const: 'baz3' }
|
||||
}
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
baz2: { type: 'string', const: 'baz2' }
|
||||
},
|
||||
if: {
|
||||
properties: {
|
||||
foo3: { type: 'string', const: 'foo3' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar3: { type: 'string', const: 'bar3' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
baz3: { type: 'string', const: 'baz3' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should two if/then keyword schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo1: { type: 'string', const: 'foo1' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar1: { type: 'string', const: 'bar1' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo2: { type: 'string', const: 'foo2' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar2: { type: 'string', const: 'bar2' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo1: { type: 'string', const: 'foo1' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar1: { type: 'string', const: 'bar1' }
|
||||
},
|
||||
if: {
|
||||
properties: {
|
||||
foo2: { type: 'string', const: 'foo2' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar2: { type: 'string', const: 'bar2' }
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should two if/else keyword schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo1: { type: 'string', const: 'foo1' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
bar1: { type: 'string', const: 'bar1' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo2: { type: 'string', const: 'foo2' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
bar2: { type: 'string', const: 'bar2' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo1: { type: 'string', const: 'foo1' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
bar1: { type: 'string', const: 'bar1' }
|
||||
},
|
||||
if: {
|
||||
properties: {
|
||||
foo2: { type: 'string', const: 'foo2' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
bar2: { type: 'string', const: 'bar2' }
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should two if/then and if/else keyword schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo1: { type: 'string', const: 'foo1' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar1: { type: 'string', const: 'bar1' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo2: { type: 'string', const: 'foo2' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
bar2: { type: 'string', const: 'bar2' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo1: { type: 'string', const: 'foo1' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar1: { type: 'string', const: 'bar1' }
|
||||
},
|
||||
if: {
|
||||
properties: {
|
||||
foo2: { type: 'string', const: 'foo2' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
bar2: { type: 'string', const: 'bar2' }
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should two if/else and if/then keyword schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo1: { type: 'string', const: 'foo1' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
bar1: { type: 'string', const: 'bar1' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo2: { type: 'string', const: 'foo2' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar2: { type: 'string', const: 'bar2' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
if: {
|
||||
properties: {
|
||||
foo1: { type: 'string', const: 'foo1' }
|
||||
}
|
||||
},
|
||||
else: {
|
||||
properties: {
|
||||
bar1: { type: 'string', const: 'bar1' }
|
||||
},
|
||||
if: {
|
||||
properties: {
|
||||
foo2: { type: 'string', const: 'foo2' }
|
||||
}
|
||||
},
|
||||
then: {
|
||||
properties: {
|
||||
bar2: { type: 'string', const: 'bar2' }
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
152
node_modules/@fastify/merge-json-schemas/test/items.test.js
generated
vendored
Normal file
152
node_modules/@fastify/merge-json-schemas/test/items.test.js
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and items keyword', () => {
|
||||
const schema1 = { type: 'array' }
|
||||
const schema2 = {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' }
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two equal item schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' }
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two different sets of item schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'number' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
baz: { type: 'boolean' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'number' },
|
||||
baz: { type: 'boolean' }
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two different sets of item schemas with additionalItems', () => {
|
||||
const schema1 = {
|
||||
type: 'array',
|
||||
items: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string', const: 'foo' }
|
||||
}
|
||||
}
|
||||
],
|
||||
additionalItems: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
baz: { type: 'string', const: 'baz' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
baz: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'array',
|
||||
items: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string', const: 'foo' },
|
||||
baz: { type: 'string' }
|
||||
}
|
||||
}
|
||||
],
|
||||
additionalItems: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
baz: { type: 'string', const: 'baz' }
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
30
node_modules/@fastify/merge-json-schemas/test/max-items.test.js
generated
vendored
Normal file
30
node_modules/@fastify/merge-json-schemas/test/max-items.test.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and maxItems keyword', () => {
|
||||
const schema1 = { type: 'array' }
|
||||
const schema2 = { type: 'array', maxItems: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'array', maxItems: 42 })
|
||||
})
|
||||
|
||||
test('should merge equal maxItems values', () => {
|
||||
const schema1 = { type: 'array', maxItems: 42 }
|
||||
const schema2 = { type: 'array', maxItems: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'array', maxItems: 42 })
|
||||
})
|
||||
|
||||
test('should merge different maxItems values', () => {
|
||||
const schema1 = { type: 'array', maxItems: 42 }
|
||||
const schema2 = { type: 'array', maxItems: 43 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'array', maxItems: 42 })
|
||||
})
|
||||
30
node_modules/@fastify/merge-json-schemas/test/max-length.test.js
generated
vendored
Normal file
30
node_modules/@fastify/merge-json-schemas/test/max-length.test.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and maxLength keyword', () => {
|
||||
const schema1 = { type: 'string' }
|
||||
const schema2 = { type: 'string', maxLength: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', maxLength: 42 })
|
||||
})
|
||||
|
||||
test('should merge equal maxLength values', () => {
|
||||
const schema1 = { type: 'string', maxLength: 42 }
|
||||
const schema2 = { type: 'string', maxLength: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', maxLength: 42 })
|
||||
})
|
||||
|
||||
test('should merge different maxLength values', () => {
|
||||
const schema1 = { type: 'string', maxLength: 42 }
|
||||
const schema2 = { type: 'string', maxLength: 43 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', maxLength: 42 })
|
||||
})
|
||||
30
node_modules/@fastify/merge-json-schemas/test/max-properties.test.js
generated
vendored
Normal file
30
node_modules/@fastify/merge-json-schemas/test/max-properties.test.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and maxProperties keyword', () => {
|
||||
const schema1 = { type: 'object' }
|
||||
const schema2 = { type: 'object', maxProperties: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'object', maxProperties: 42 })
|
||||
})
|
||||
|
||||
test('should merge equal maxProperties values', () => {
|
||||
const schema1 = { type: 'object', maxProperties: 42 }
|
||||
const schema2 = { type: 'object', maxProperties: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'object', maxProperties: 42 })
|
||||
})
|
||||
|
||||
test('should merge different maxProperties values', () => {
|
||||
const schema1 = { type: 'object', maxProperties: 42 }
|
||||
const schema2 = { type: 'object', maxProperties: 43 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'object', maxProperties: 42 })
|
||||
})
|
||||
30
node_modules/@fastify/merge-json-schemas/test/maximum.test.js
generated
vendored
Normal file
30
node_modules/@fastify/merge-json-schemas/test/maximum.test.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and maximum keyword', () => {
|
||||
const schema1 = { type: 'number' }
|
||||
const schema2 = { type: 'number', maximum: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'number', maximum: 42 })
|
||||
})
|
||||
|
||||
test('should merge equal maximum values', () => {
|
||||
const schema1 = { type: 'number', maximum: 42 }
|
||||
const schema2 = { type: 'number', maximum: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'number', maximum: 42 })
|
||||
})
|
||||
|
||||
test('should merge different maximum values', () => {
|
||||
const schema1 = { type: 'integer', maximum: 42 }
|
||||
const schema2 = { type: 'integer', maximum: 43 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'integer', maximum: 42 })
|
||||
})
|
||||
29
node_modules/@fastify/merge-json-schemas/test/merge-schema.test.js
generated
vendored
Normal file
29
node_modules/@fastify/merge-json-schemas/test/merge-schema.test.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should return an empty schema if passing an empty array', () => {
|
||||
const mergedSchema = mergeSchemas([], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {})
|
||||
})
|
||||
|
||||
test('should return true if passing all true values', () => {
|
||||
const mergedSchema = mergeSchemas([true, true, true], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, true)
|
||||
})
|
||||
|
||||
test('should return true if passing all false values', () => {
|
||||
const mergedSchema = mergeSchemas([false, false, false], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, false)
|
||||
})
|
||||
|
||||
test('should return true if passing at least one false schema', () => {
|
||||
const schema1 = { type: 'string' }
|
||||
const schema2 = { type: 'number' }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2, false], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, false)
|
||||
})
|
||||
30
node_modules/@fastify/merge-json-schemas/test/min-items.test.js
generated
vendored
Normal file
30
node_modules/@fastify/merge-json-schemas/test/min-items.test.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and minItems keyword', () => {
|
||||
const schema1 = { type: 'array' }
|
||||
const schema2 = { type: 'array', minItems: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'array', minItems: 42 })
|
||||
})
|
||||
|
||||
test('should merge equal minItems values', () => {
|
||||
const schema1 = { type: 'array', minItems: 42 }
|
||||
const schema2 = { type: 'array', minItems: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'array', minItems: 42 })
|
||||
})
|
||||
|
||||
test('should merge different minItems values', () => {
|
||||
const schema1 = { type: 'array', minItems: 42 }
|
||||
const schema2 = { type: 'array', minItems: 43 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'array', minItems: 43 })
|
||||
})
|
||||
30
node_modules/@fastify/merge-json-schemas/test/min-length.test.js
generated
vendored
Normal file
30
node_modules/@fastify/merge-json-schemas/test/min-length.test.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and minLength keyword', () => {
|
||||
const schema1 = { type: 'string' }
|
||||
const schema2 = { type: 'string', minLength: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', minLength: 42 })
|
||||
})
|
||||
|
||||
test('should merge equal minLength values', () => {
|
||||
const schema1 = { type: 'string', minLength: 42 }
|
||||
const schema2 = { type: 'string', minLength: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', minLength: 42 })
|
||||
})
|
||||
|
||||
test('should merge different minLength values', () => {
|
||||
const schema1 = { type: 'string', minLength: 42 }
|
||||
const schema2 = { type: 'string', minLength: 43 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', minLength: 43 })
|
||||
})
|
||||
30
node_modules/@fastify/merge-json-schemas/test/min-properties.test.js
generated
vendored
Normal file
30
node_modules/@fastify/merge-json-schemas/test/min-properties.test.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and minProperties keyword', () => {
|
||||
const schema1 = { type: 'object' }
|
||||
const schema2 = { type: 'object', minProperties: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'object', minProperties: 42 })
|
||||
})
|
||||
|
||||
test('should merge equal minItems values', () => {
|
||||
const schema1 = { type: 'object', minProperties: 42 }
|
||||
const schema2 = { type: 'object', minProperties: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'object', minProperties: 42 })
|
||||
})
|
||||
|
||||
test('should merge different minItems values', () => {
|
||||
const schema1 = { type: 'object', minProperties: 42 }
|
||||
const schema2 = { type: 'object', minProperties: 43 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'object', minProperties: 43 })
|
||||
})
|
||||
30
node_modules/@fastify/merge-json-schemas/test/minimum.test.js
generated
vendored
Normal file
30
node_modules/@fastify/merge-json-schemas/test/minimum.test.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and minimum keyword', () => {
|
||||
const schema1 = { type: 'number' }
|
||||
const schema2 = { type: 'number', minimum: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'number', minimum: 42 })
|
||||
})
|
||||
|
||||
test('should merge equal minimum values', () => {
|
||||
const schema1 = { type: 'number', minimum: 42 }
|
||||
const schema2 = { type: 'number', minimum: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'number', minimum: 42 })
|
||||
})
|
||||
|
||||
test('should merge different minimum values', () => {
|
||||
const schema1 = { type: 'integer', minimum: 42 }
|
||||
const schema2 = { type: 'integer', minimum: 43 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'integer', minimum: 43 })
|
||||
})
|
||||
36
node_modules/@fastify/merge-json-schemas/test/multiple-of.test.js
generated
vendored
Normal file
36
node_modules/@fastify/merge-json-schemas/test/multiple-of.test.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and multipleOf keyword', () => {
|
||||
const schema1 = { type: 'number' }
|
||||
const schema2 = { type: 'number', multipleOf: 42 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'number', multipleOf: 42 })
|
||||
})
|
||||
|
||||
test('should merge two schemas with multipleOf keywords', () => {
|
||||
const schema1 = { type: 'number', multipleOf: 2 }
|
||||
const schema2 = { type: 'number', multipleOf: 3 }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'number', multipleOf: 6 })
|
||||
})
|
||||
|
||||
test('should merge multiple schemas with float multipleOf keywords', () => {
|
||||
const schema1 = { type: 'number', multipleOf: 0.2 }
|
||||
const schema2 = { type: 'number', multipleOf: 2 }
|
||||
const schema3 = { type: 'number', multipleOf: 2 }
|
||||
const schema4 = { type: 'number', multipleOf: 0.5 }
|
||||
const schema5 = { type: 'number', multipleOf: 1.5 }
|
||||
|
||||
const mergedSchema = mergeSchemas(
|
||||
[schema1, schema2, schema3, schema4, schema5],
|
||||
{ defaultResolver }
|
||||
)
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'number', multipleOf: 6 })
|
||||
})
|
||||
29
node_modules/@fastify/merge-json-schemas/test/not.test.js
generated
vendored
Normal file
29
node_modules/@fastify/merge-json-schemas/test/not.test.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge two "not" keyword schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'array',
|
||||
not: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'array',
|
||||
not: {
|
||||
type: 'string', minLength: 1
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'array',
|
||||
not: {
|
||||
type: 'string', minLength: 1
|
||||
}
|
||||
})
|
||||
})
|
||||
30
node_modules/@fastify/merge-json-schemas/test/nullable.test.js
generated
vendored
Normal file
30
node_modules/@fastify/merge-json-schemas/test/nullable.test.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and nullable = true keyword', () => {
|
||||
const schema1 = { type: 'string' }
|
||||
const schema2 = { type: 'string', nullable: true }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', nullable: true })
|
||||
})
|
||||
|
||||
test('should merge empty schema and nullable = false keyword', () => {
|
||||
const schema1 = { type: 'string' }
|
||||
const schema2 = { type: 'string', nullable: false }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', nullable: false })
|
||||
})
|
||||
|
||||
test('should merge schemas with nullable true and false values', () => {
|
||||
const schema1 = { type: 'string', nullable: false }
|
||||
const schema2 = { type: 'string', nullable: true }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string', nullable: false })
|
||||
})
|
||||
144
node_modules/@fastify/merge-json-schemas/test/one-of.test.js
generated
vendored
Normal file
144
node_modules/@fastify/merge-json-schemas/test/one-of.test.js
generated
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas, MergeError } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and oneOf keyword', () => {
|
||||
const schema1 = {}
|
||||
const schema2 = {
|
||||
oneOf: [
|
||||
{ type: 'string', const: 'foo' }
|
||||
]
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
oneOf: [
|
||||
{ type: 'string', const: 'foo' }
|
||||
]
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two schemas with oneOfs schemas', () => {
|
||||
const schema1 = {
|
||||
oneOf: [
|
||||
{ type: 'string', enum: ['foo1', 'foo2', 'foo3'] },
|
||||
{ type: 'string', enum: ['foo3', 'foo4', 'foo5'] }
|
||||
]
|
||||
}
|
||||
const schema2 = {
|
||||
oneOf: [
|
||||
{ type: 'string', enum: ['foo2', 'foo3', 'foo4'] },
|
||||
{ type: 'string', enum: ['foo3', 'foo6', 'foo7'] }
|
||||
]
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
oneOf: [
|
||||
{ type: 'string', enum: ['foo2', 'foo3'] },
|
||||
{ type: 'string', enum: ['foo3'] },
|
||||
{ type: 'string', enum: ['foo3', 'foo4'] },
|
||||
{ type: 'string', enum: ['foo3'] }
|
||||
]
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge three schemas with oneOfs schemas', () => {
|
||||
const schema1 = {
|
||||
oneOf: [
|
||||
{ type: 'string', enum: ['foo1', 'foo2', 'foo3', 'foo4'] },
|
||||
{ type: 'string', enum: ['foo3', 'foo4', 'foo5', 'foo7'] }
|
||||
]
|
||||
}
|
||||
const schema2 = {
|
||||
oneOf: [
|
||||
{ type: 'string', enum: ['foo2', 'foo3', 'foo4', 'foo5'] },
|
||||
{ type: 'string', enum: ['foo3', 'foo6', 'foo7', 'foo8'] }
|
||||
]
|
||||
}
|
||||
|
||||
const schema3 = {
|
||||
oneOf: [
|
||||
{ type: 'string', enum: ['foo1', 'foo3', 'foo5', 'foo7'] },
|
||||
{ type: 'string', enum: ['foo2', 'foo4', 'foo6', 'foo8'] }
|
||||
]
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas(
|
||||
[schema1, schema2, schema3],
|
||||
{ defaultResolver }
|
||||
)
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
oneOf: [
|
||||
{ type: 'string', enum: ['foo3'] },
|
||||
{ type: 'string', enum: ['foo2', 'foo4'] },
|
||||
{ type: 'string', enum: ['foo3'] },
|
||||
{ type: 'string', enum: ['foo3', 'foo5'] },
|
||||
{ type: 'string', enum: ['foo4'] },
|
||||
{ type: 'string', enum: ['foo3', 'foo7'] }
|
||||
]
|
||||
})
|
||||
})
|
||||
|
||||
test('should throw a non MergeError error during oneOf merge', () => {
|
||||
const schema1 = {
|
||||
oneOf: [
|
||||
{ type: 'string', customKeyword: 42 },
|
||||
{ type: 'string', customKeyword: 43 }
|
||||
]
|
||||
}
|
||||
const schema2 = {
|
||||
oneOf: [
|
||||
{ type: 'string', customKeyword: 44 },
|
||||
{ type: 'string', customKeyword: 45 }
|
||||
]
|
||||
}
|
||||
|
||||
assert.throws(() => {
|
||||
mergeSchemas(
|
||||
[schema1, schema2],
|
||||
{
|
||||
resolvers: {
|
||||
customKeyword: () => {
|
||||
throw new Error('Custom error')
|
||||
}
|
||||
},
|
||||
defaultResolver
|
||||
}
|
||||
)
|
||||
}, {
|
||||
name: 'Error',
|
||||
message: 'Custom error'
|
||||
})
|
||||
})
|
||||
|
||||
test('should not throw a MergeError error during oneOf merge', () => {
|
||||
const schema1 = {
|
||||
oneOf: [
|
||||
{ type: 'string', customKeyword: 42 },
|
||||
{ type: 'string', customKeyword: 43 }
|
||||
]
|
||||
}
|
||||
const schema2 = {
|
||||
oneOf: [
|
||||
{ type: 'string', customKeyword: 44 },
|
||||
{ type: 'string', customKeyword: 45 }
|
||||
]
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas(
|
||||
[schema1, schema2],
|
||||
{
|
||||
resolvers: {
|
||||
customKeyword: (keyword, values) => {
|
||||
throw new MergeError(keyword, values)
|
||||
}
|
||||
},
|
||||
defaultResolver
|
||||
}
|
||||
)
|
||||
assert.deepStrictEqual(mergedSchema, { oneOf: [] })
|
||||
})
|
||||
312
node_modules/@fastify/merge-json-schemas/test/properties.test.js
generated
vendored
Normal file
312
node_modules/@fastify/merge-json-schemas/test/properties.test.js
generated
vendored
Normal file
@@ -0,0 +1,312 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and properties keyword', () => {
|
||||
const schema1 = { type: 'object' }
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' }
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' }
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two equal property schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' }
|
||||
}
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' }
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' }
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two different sets of property schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'number' }
|
||||
}
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
baz: { type: 'boolean' }
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'number' },
|
||||
baz: { type: 'boolean' }
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge property with different schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: {
|
||||
type: ['string', 'number'],
|
||||
enum: ['42', 2, 3]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: {
|
||||
type: ['number', 'null'],
|
||||
enum: [1, 2, 3, null]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'number', enum: [2, 3] }
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge properties if one schema has additionalProperties = false', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'number' }
|
||||
},
|
||||
additionalProperties: false
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string', enum: ['42'] },
|
||||
baz: { type: 'string' }
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string', enum: ['42'] },
|
||||
bar: { type: 'number' },
|
||||
baz: false
|
||||
},
|
||||
additionalProperties: false
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge properties if both schemas have additionalProperties = false', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'number' }
|
||||
},
|
||||
additionalProperties: false
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string', enum: ['42'] },
|
||||
baz: { type: 'string' }
|
||||
},
|
||||
additionalProperties: false
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string', enum: ['42'] },
|
||||
bar: false,
|
||||
baz: false
|
||||
},
|
||||
additionalProperties: false
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge properties if one schema has additionalProperties schema', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'number' }
|
||||
},
|
||||
additionalProperties: { type: 'string', enum: ['43'] }
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string', enum: ['42'] },
|
||||
baz: { type: 'string' }
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string', enum: ['42'] },
|
||||
bar: { type: 'number' },
|
||||
baz: { type: 'string', enum: ['43'] }
|
||||
},
|
||||
additionalProperties: { type: 'string', enum: ['43'] }
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge properties if both schemas have additionalProperties schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'number' }
|
||||
},
|
||||
additionalProperties: {
|
||||
type: ['string', 'number', 'null'],
|
||||
enum: ['45', '43', 41, null]
|
||||
}
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string', enum: ['42'] },
|
||||
baz: { type: 'string' }
|
||||
},
|
||||
additionalProperties: {
|
||||
type: ['string', 'boolean', 'number'],
|
||||
enum: ['44', '43', true, 41]
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string', enum: ['42'] },
|
||||
bar: { type: 'number', enum: ['44', '43', true, 41] },
|
||||
baz: { type: 'string', enum: ['45', '43', 41, null] }
|
||||
},
|
||||
additionalProperties: { type: ['string', 'number'], enum: ['43', 41] }
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge properties if one schema has patternProperties schema', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'number' }
|
||||
},
|
||||
patternProperties: {
|
||||
'^baz$': { type: 'string', enum: ['43'] }
|
||||
}
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string', enum: ['42'] },
|
||||
baz: { type: 'string' },
|
||||
qux: { type: 'string' }
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string', enum: ['42'] },
|
||||
bar: { type: 'number' },
|
||||
baz: { type: 'string', enum: ['43'] },
|
||||
qux: { type: 'string' }
|
||||
},
|
||||
patternProperties: {
|
||||
'^baz$': { type: 'string', enum: ['43'] }
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge properties if both schemas have patternProperties schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string' },
|
||||
bar: { type: 'number' },
|
||||
bak: { type: 'number' }
|
||||
},
|
||||
patternProperties: {
|
||||
'^baz$': { type: 'string', enum: ['43'] }
|
||||
}
|
||||
}
|
||||
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string', enum: ['42'] },
|
||||
baz: { type: 'string' },
|
||||
qux: { type: 'string' }
|
||||
},
|
||||
patternProperties: {
|
||||
'^bar$': { type: 'number', minimum: 2 }
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
properties: {
|
||||
foo: { type: 'string', enum: ['42'] },
|
||||
bar: { type: 'number', minimum: 2 },
|
||||
bak: { type: 'number' },
|
||||
baz: { type: 'string', enum: ['43'] },
|
||||
qux: { type: 'string' }
|
||||
},
|
||||
patternProperties: {
|
||||
'^bar$': { type: 'number', minimum: 2 },
|
||||
'^baz$': { type: 'string', enum: ['43'] }
|
||||
}
|
||||
})
|
||||
})
|
||||
49
node_modules/@fastify/merge-json-schemas/test/property-names.test.js
generated
vendored
Normal file
49
node_modules/@fastify/merge-json-schemas/test/property-names.test.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and propertyNames keyword', () => {
|
||||
const schema1 = {}
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
propertyNames: {
|
||||
pattern: '^[a-zA-Z]+$',
|
||||
minLength: 42
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
propertyNames: {
|
||||
pattern: '^[a-zA-Z]+$',
|
||||
minLength: 42
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('should merge two propertyNames keyword schemas', () => {
|
||||
const schema1 = {
|
||||
type: 'object',
|
||||
propertyNames: {
|
||||
minLength: 42
|
||||
}
|
||||
}
|
||||
const schema2 = {
|
||||
type: 'object',
|
||||
propertyNames: {
|
||||
minLength: 43
|
||||
}
|
||||
}
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, {
|
||||
type: 'object',
|
||||
propertyNames: {
|
||||
minLength: 43
|
||||
}
|
||||
})
|
||||
})
|
||||
30
node_modules/@fastify/merge-json-schemas/test/required.test.js
generated
vendored
Normal file
30
node_modules/@fastify/merge-json-schemas/test/required.test.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and required keyword', () => {
|
||||
const schema1 = { type: 'object' }
|
||||
const schema2 = { type: 'object', required: ['foo'] }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'object', required: ['foo'] })
|
||||
})
|
||||
|
||||
test('should merge two equal required keywords', () => {
|
||||
const schema1 = { type: 'object', required: ['foo'] }
|
||||
const schema2 = { type: 'object', required: ['foo'] }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'object', required: ['foo'] })
|
||||
})
|
||||
|
||||
test('should merge two different required keywords', () => {
|
||||
const schema1 = { type: 'object', required: ['foo', 'bar'] }
|
||||
const schema2 = { type: 'object', required: ['foo', 'baz'] }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'object', required: ['foo', 'bar', 'baz'] })
|
||||
})
|
||||
52
node_modules/@fastify/merge-json-schemas/test/type.test.js
generated
vendored
Normal file
52
node_modules/@fastify/merge-json-schemas/test/type.test.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge equal type values', () => {
|
||||
const schema1 = { type: 'string' }
|
||||
const schema2 = { type: 'string' }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string' })
|
||||
})
|
||||
|
||||
test('should merge array type values', () => {
|
||||
const schema1 = { type: ['string', 'number'] }
|
||||
const schema2 = { type: ['null', 'string'] }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string' })
|
||||
})
|
||||
|
||||
test('should merge array type values', () => {
|
||||
const schema1 = { type: ['string', 'number'] }
|
||||
const schema2 = { type: 'string' }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'string' })
|
||||
})
|
||||
|
||||
test('should merge array type values', () => {
|
||||
const schema1 = { type: ['number', 'string', 'boolean'] }
|
||||
const schema2 = { type: ['string', 'number', 'null'] }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: ['number', 'string'] })
|
||||
})
|
||||
|
||||
test('should throw an error if can not merge type values', () => {
|
||||
const schema1 = { type: 'string' }
|
||||
const schema2 = { type: 'number' }
|
||||
|
||||
assert.throws(() => {
|
||||
mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
}, {
|
||||
name: 'JsonSchemaMergeError',
|
||||
code: 'JSON_SCHEMA_MERGE_ERROR',
|
||||
message: 'Failed to merge "type" keyword schemas.',
|
||||
schemas: [['string'], ['number']]
|
||||
})
|
||||
})
|
||||
38
node_modules/@fastify/merge-json-schemas/test/unique-items.test.js
generated
vendored
Normal file
38
node_modules/@fastify/merge-json-schemas/test/unique-items.test.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert/strict')
|
||||
const { test } = require('node:test')
|
||||
const { mergeSchemas } = require('../index')
|
||||
const { defaultResolver } = require('./utils')
|
||||
|
||||
test('should merge empty schema and uniqueItems keyword', () => {
|
||||
const schema1 = { type: 'array' }
|
||||
const schema2 = { type: 'array', uniqueItems: true }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'array', uniqueItems: true })
|
||||
})
|
||||
|
||||
test('should merge two equal uniqueItems keyword schemas = true', () => {
|
||||
const schema1 = { type: 'array', uniqueItems: true }
|
||||
const schema2 = { type: 'array', uniqueItems: true }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'array', uniqueItems: true })
|
||||
})
|
||||
|
||||
test('should merge two equal uniqueItems keyword schemas = false', () => {
|
||||
const schema1 = { type: 'array', uniqueItems: false }
|
||||
const schema2 = { type: 'array', uniqueItems: false }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'array', uniqueItems: false })
|
||||
})
|
||||
|
||||
test('should merge two equal uniqueItems keyword schemas', () => {
|
||||
const schema1 = { type: 'array', uniqueItems: false }
|
||||
const schema2 = { type: 'array', uniqueItems: true }
|
||||
|
||||
const mergedSchema = mergeSchemas([schema1, schema2], { defaultResolver })
|
||||
assert.deepStrictEqual(mergedSchema, { type: 'array', uniqueItems: true })
|
||||
})
|
||||
9
node_modules/@fastify/merge-json-schemas/test/utils.js
generated
vendored
Normal file
9
node_modules/@fastify/merge-json-schemas/test/utils.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
'use strict'
|
||||
|
||||
function defaultResolver () {
|
||||
throw new Error('Default resolver should not be called.')
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
defaultResolver
|
||||
}
|
||||
Reference in New Issue
Block a user