fast-json-stringify 7.3.1 → 7.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -1
- package/package.json +1 -1
- package/test/side-effect.test.js +57 -0
package/index.js
CHANGED
|
@@ -1392,7 +1392,7 @@ function generateFuncName (context) {
|
|
|
1392
1392
|
|
|
1393
1393
|
function buildMultiTypeSerializer (context, location, input) {
|
|
1394
1394
|
const schema = location.schema
|
|
1395
|
-
const types = schema.type.sort(t1 => t1 === 'null' ? -1 : 1)
|
|
1395
|
+
const types = [...schema.type].sort(t1 => t1 === 'null' ? -1 : 1)
|
|
1396
1396
|
|
|
1397
1397
|
let code = ''
|
|
1398
1398
|
|
package/package.json
CHANGED
package/test/side-effect.test.js
CHANGED
|
@@ -4,6 +4,63 @@ const { test } = require('node:test')
|
|
|
4
4
|
const clone = require('rfdc/default')
|
|
5
5
|
const build = require('..')
|
|
6
6
|
|
|
7
|
+
test('multi-type schemas should not change the input schema', t => {
|
|
8
|
+
t.plan(5)
|
|
9
|
+
|
|
10
|
+
const schema = {
|
|
11
|
+
type: ['object', 'null'],
|
|
12
|
+
properties: {
|
|
13
|
+
name: { type: ['string', 'null'] },
|
|
14
|
+
values: { type: 'array', items: { type: ['number', 'null'] } }
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const clonedSchema = clone(schema)
|
|
18
|
+
const stringify = build(schema)
|
|
19
|
+
|
|
20
|
+
t.assert.deepStrictEqual(schema, clonedSchema)
|
|
21
|
+
t.assert.equal(stringify({ name: 'hello', values: [42, null] }), '{"name":"hello","values":[42,null]}')
|
|
22
|
+
t.assert.equal(stringify(null), 'null')
|
|
23
|
+
|
|
24
|
+
const stringifyAgain = build(schema)
|
|
25
|
+
t.assert.equal(stringifyAgain({ name: null, values: [] }), '{"name":null,"values":[]}')
|
|
26
|
+
t.assert.deepStrictEqual(schema, clonedSchema)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('multi-type schemas should not change an external reference schema', t => {
|
|
30
|
+
t.plan(3)
|
|
31
|
+
|
|
32
|
+
const referenceSchema = {
|
|
33
|
+
$id: 'externalSchema',
|
|
34
|
+
type: ['string', 'null']
|
|
35
|
+
}
|
|
36
|
+
const clonedSchema = clone(referenceSchema)
|
|
37
|
+
const stringify = build({
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: { name: { $ref: 'externalSchema' } }
|
|
40
|
+
}, {
|
|
41
|
+
schema: { externalSchema: referenceSchema }
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
t.assert.equal(stringify({ name: 'hello' }), '{"name":"hello"}')
|
|
45
|
+
t.assert.equal(stringify({ name: null }), '{"name":null}')
|
|
46
|
+
t.assert.deepStrictEqual(referenceSchema, clonedSchema)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test('multi-type schemas should support frozen type arrays', t => {
|
|
50
|
+
t.plan(3)
|
|
51
|
+
|
|
52
|
+
const stringify = build({
|
|
53
|
+
type: Object.freeze(['object', 'null']),
|
|
54
|
+
properties: {
|
|
55
|
+
name: { type: Object.freeze(['string', 'null']) }
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
t.assert.equal(stringify({ name: 'hello' }), '{"name":"hello"}')
|
|
60
|
+
t.assert.equal(stringify({ name: null }), '{"name":null}')
|
|
61
|
+
t.assert.equal(stringify(null), 'null')
|
|
62
|
+
})
|
|
63
|
+
|
|
7
64
|
test('oneOf with $ref should not change the input schema', t => {
|
|
8
65
|
t.plan(2)
|
|
9
66
|
|