Aktueller Stand

This commit is contained in:
2026-01-22 19:05:45 +01:00
parent 85dee61a4d
commit e280e4eadb
1967 changed files with 397327 additions and 74093 deletions

View File

@@ -1,6 +1,6 @@
'use strict'
const test = require('tap').test
const { test } = require('node:test')
const build = require('..')
process.env.TZ = 'UTC'
@@ -17,7 +17,7 @@ test('allOf: combine type and format ', (t) => {
const stringify = build(schema)
const date = new Date(1674263005800)
const value = stringify(date)
t.equal(value, '"01:03:25"')
t.assert.equal(value, '"01:03:25"')
})
test('allOf: combine additional properties ', (t) => {
@@ -35,7 +35,7 @@ test('allOf: combine additional properties ', (t) => {
const stringify = build(schema)
const data = { property: true }
const value = stringify(data)
t.equal(value, JSON.stringify(data))
t.assert.equal(value, JSON.stringify(data))
})
test('allOf: combine pattern properties', (t) => {
@@ -57,7 +57,7 @@ test('allOf: combine pattern properties', (t) => {
const stringify = build(schema)
const data = { foo: 42 }
const value = stringify(data)
t.equal(value, JSON.stringify(data))
t.assert.equal(value, JSON.stringify(data))
})
test('object with allOf and multiple schema on the allOf', (t) => {
@@ -101,7 +101,7 @@ test('object with allOf and multiple schema on the allOf', (t) => {
id: 1
})
} catch (e) {
t.equal(e.message, '"name" is required!')
t.assert.equal(e.message, '"name" is required!')
}
try {
@@ -109,15 +109,15 @@ test('object with allOf and multiple schema on the allOf', (t) => {
name: 'string'
})
} catch (e) {
t.equal(e.message, '"id" is required!')
t.assert.equal(e.message, '"id" is required!')
}
t.equal(stringify({
t.assert.equal(stringify({
id: 1,
name: 'string'
}), '{"name":"string","id":1}')
t.equal(stringify({
t.assert.equal(stringify({
id: 1,
name: 'string',
tag: 'otherString'
@@ -149,7 +149,7 @@ test('object with allOf and one schema on the allOf', (t) => {
const value = stringify({
id: 1
})
t.equal(value, '{"id":1}')
t.assert.equal(value, '{"id":1}')
})
test('object with allOf and no schema on the allOf', (t) => {
@@ -165,7 +165,7 @@ test('object with allOf and no schema on the allOf', (t) => {
build(schema)
t.fail()
} catch (e) {
t.equal(e.message, 'schema is invalid: data/allOf must NOT have fewer than 1 items')
t.assert.equal(e.message, 'schema is invalid: data/allOf must NOT have fewer than 1 items')
}
})
@@ -217,7 +217,7 @@ test('object with nested allOfs', (t) => {
id3: 3,
id4: 4 // extra prop shouldn't be in result
})
t.equal(value, '{"id1":1,"id2":2,"id3":3}')
t.assert.equal(value, '{"id1":1,"id2":2,"id3":3}')
})
test('object with anyOf nested inside allOf', (t) => {
@@ -286,7 +286,7 @@ test('object with anyOf nested inside allOf', (t) => {
obj: { nested: 'yes' },
nestedObj: { nested: 'yes' }
})
t.equal(value, '{"id1":1,"obj":{"nested":"yes"},"id3":3,"nestedObj":{"nested":"yes"}}')
t.assert.equal(value, '{"id1":1,"obj":{"nested":"yes"},"id3":3,"nestedObj":{"nested":"yes"}}')
})
test('object with $ref in allOf', (t) => {
@@ -317,7 +317,7 @@ test('object with $ref in allOf', (t) => {
id1: 1,
id2: 2 // extra prop shouldn't be in result
})
t.equal(value, '{"id1":1}')
t.assert.equal(value, '{"id1":1}')
})
test('object with $ref and other object in allOf', (t) => {
@@ -357,7 +357,7 @@ test('object with $ref and other object in allOf', (t) => {
id2: 2,
id3: 3 // extra prop shouldn't be in result
})
t.equal(value, '{"id1":1,"id2":2}')
t.assert.equal(value, '{"id1":1,"id2":2}')
})
test('object with multiple $refs in allOf', (t) => {
@@ -400,7 +400,7 @@ test('object with multiple $refs in allOf', (t) => {
id2: 2,
id3: 3 // extra prop shouldn't be in result
})
t.equal(value, '{"id1":1,"id2":2}')
t.assert.equal(value, '{"id1":1,"id2":2}')
})
test('allOf with nested allOf in $ref', (t) => {
@@ -452,7 +452,7 @@ test('allOf with nested allOf in $ref', (t) => {
id3: 3,
id4: 4 // extra prop shouldn't be in result
})
t.equal(value, '{"id1":1,"id2":2,"id3":3}')
t.assert.equal(value, '{"id1":1,"id2":2,"id3":3}')
})
test('object with external $refs in allOf', (t) => {
@@ -505,7 +505,7 @@ test('object with external $refs in allOf', (t) => {
id2: 2,
id3: 3 // extra prop shouldn't be in result
})
t.equal(value, '{"id1":1,"id2":2}')
t.assert.equal(value, '{"id1":1,"id2":2}')
})
test('allof with local anchor reference', (t) => {
@@ -550,7 +550,7 @@ test('allof with local anchor reference', (t) => {
const stringify = build(schema, { schema: externalSchemas })
const data = { type: 'foo', validation: 'bar' }
t.equal(stringify(data), JSON.stringify(data))
t.assert.equal(stringify(data), JSON.stringify(data))
})
test('allOf: multiple nested $ref properties', (t) => {
@@ -601,12 +601,12 @@ test('allOf: multiple nested $ref properties', (t) => {
const stringify = build(schema, { schema: [externalSchema1, externalSchema2] })
t.equal(stringify({ id1: 1 }), JSON.stringify({ id1: 1 }))
t.equal(stringify({ id2: 2 }), JSON.stringify({ id2: 2 }))
t.assert.equal(stringify({ id1: 1 }), JSON.stringify({ id1: 1 }))
t.assert.equal(stringify({ id2: 2 }), JSON.stringify({ id2: 2 }))
})
test('allOf: throw Error if types mismatch ', (t) => {
t.plan(3)
t.plan(1)
const schema = {
allOf: [
@@ -614,18 +614,16 @@ test('allOf: throw Error if types mismatch ', (t) => {
{ type: 'number' }
]
}
try {
t.assert.throws(() => {
build(schema)
t.fail('should throw the MergeError')
} catch (error) {
t.ok(error instanceof Error)
t.equal(error.message, 'Failed to merge "type" keyword schemas.')
t.same(error.schemas, [['string'], ['number']])
}
}, {
message: 'Failed to merge "type" keyword schemas.',
schemas: [['string'], ['number']]
})
})
test('allOf: throw Error if format mismatch ', (t) => {
t.plan(3)
t.plan(1)
const schema = {
allOf: [
@@ -633,14 +631,12 @@ test('allOf: throw Error if format mismatch ', (t) => {
{ format: 'time' }
]
}
try {
t.assert.throws(() => {
build(schema)
t.fail('should throw the MergeError')
} catch (error) {
t.ok(error instanceof Error)
t.equal(error.message, 'Failed to merge "format" keyword schemas.')
t.same(error.schemas, ['date', 'time'])
}
}, {
message: 'Failed to merge "format" keyword schemas.'
// schemas: ['date', 'time']
})
})
test('recursive nested allOfs', (t) => {
@@ -658,7 +654,7 @@ test('recursive nested allOfs', (t) => {
const data = { foo: {} }
const stringify = build(schema)
t.equal(stringify(data), JSON.stringify(data))
t.assert.equal(stringify(data), JSON.stringify(data))
})
test('recursive nested allOfs', (t) => {
@@ -676,7 +672,7 @@ test('recursive nested allOfs', (t) => {
const data = { foo: {} }
const stringify = build(schema)
t.equal(stringify(data), JSON.stringify(data))
t.assert.equal(stringify(data), JSON.stringify(data))
})
test('external recursive allOfs', (t) => {
@@ -715,7 +711,7 @@ test('external recursive allOfs', (t) => {
}
}
const stringify = build(schema, { schema: { externalSchema } })
t.equal(stringify(data), '{"a":{"bar":"42","foo":{}},"b":{"bar":"42","foo":{}}}')
t.assert.equal(stringify(data), '{"a":{"bar":"42","foo":{}},"b":{"bar":"42","foo":{}}}')
})
test('do not crash with $ref prop', (t) => {
@@ -751,5 +747,5 @@ test('do not crash with $ref prop', (t) => {
$ref: 'true'
}
})
t.equal(value, '{"outside":{"$ref":"true"}}')
t.assert.equal(value, '{"outside":{"$ref":"true"}}')
})