fast-json-stringify 2.7.12 → 3.0.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/.github/dependabot.yml +4 -0
- package/.github/workflows/ci.yml +8 -4
- package/README.md +37 -63
- package/bench.js +44 -0
- package/build-schema-validator.js +14 -9
- package/index.js +49 -74
- package/package.json +3 -4
- package/schema-validator.js +1132 -1748
- package/test/allof.test.js +53 -1
- package/test/bigint.test.js +76 -0
- package/test/debug-mode.test.js +51 -14
- package/test/if-then-else.test.js +16 -1
- package/test/integer.test.js +1 -10
- package/test/nullable.test.js +9 -4
- package/test/side-effect.test.js +39 -0
- package/test/types/tsconfig.json +3 -1
- package/test/typesArray.test.js +2 -2
- package/test/bigint.js +0 -74
- package/test/long.test.js +0 -85
package/test/allof.test.js
CHANGED
|
@@ -108,7 +108,7 @@ test('object with allOf and no schema on the allOf', (t) => {
|
|
|
108
108
|
build(schema)
|
|
109
109
|
t.fail()
|
|
110
110
|
} catch (e) {
|
|
111
|
-
t.equal(e.message, 'schema is invalid: data
|
|
111
|
+
t.equal(e.message, 'schema is invalid: data/allOf must NOT have fewer than 1 items')
|
|
112
112
|
}
|
|
113
113
|
})
|
|
114
114
|
|
|
@@ -277,6 +277,58 @@ test('object with multiple $refs in allOf', (t) => {
|
|
|
277
277
|
t.equal(value, '{"id1":1,"id2":2}')
|
|
278
278
|
})
|
|
279
279
|
|
|
280
|
+
test('allOf with nested allOf in $ref', (t) => {
|
|
281
|
+
t.plan(1)
|
|
282
|
+
|
|
283
|
+
const schema = {
|
|
284
|
+
title: 'allOf with nested allOf in $ref',
|
|
285
|
+
type: 'object',
|
|
286
|
+
definitions: {
|
|
287
|
+
group: {
|
|
288
|
+
type: 'object',
|
|
289
|
+
allOf: [{
|
|
290
|
+
properties: {
|
|
291
|
+
id2: {
|
|
292
|
+
type: 'integer'
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}, {
|
|
296
|
+
properties: {
|
|
297
|
+
id3: {
|
|
298
|
+
type: 'integer'
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}]
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
allOf: [
|
|
305
|
+
{
|
|
306
|
+
type: 'object',
|
|
307
|
+
properties: {
|
|
308
|
+
id1: {
|
|
309
|
+
type: 'integer'
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
required: [
|
|
313
|
+
'id1'
|
|
314
|
+
]
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
$ref: '#/definitions/group'
|
|
318
|
+
}
|
|
319
|
+
]
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const stringify = build(schema)
|
|
323
|
+
const value = stringify({
|
|
324
|
+
id1: 1,
|
|
325
|
+
id2: 2,
|
|
326
|
+
id3: 3,
|
|
327
|
+
id4: 4 // extra prop shouldn't be in result
|
|
328
|
+
})
|
|
329
|
+
t.equal(value, '{"id1":1,"id2":2,"id3":3}')
|
|
330
|
+
})
|
|
331
|
+
|
|
280
332
|
test('object with external $refs in allOf', (t) => {
|
|
281
333
|
t.plan(1)
|
|
282
334
|
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const t = require('tap')
|
|
4
|
+
const test = t.test
|
|
5
|
+
const build = require('..')
|
|
6
|
+
|
|
7
|
+
test('render a bigint as JSON', (t) => {
|
|
8
|
+
t.plan(1)
|
|
9
|
+
|
|
10
|
+
const schema = {
|
|
11
|
+
title: 'bigint',
|
|
12
|
+
type: 'integer'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const stringify = build(schema)
|
|
16
|
+
const output = stringify(1615n)
|
|
17
|
+
|
|
18
|
+
t.equal(output, '1615')
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test('render an object with a bigint as JSON', (t) => {
|
|
22
|
+
t.plan(1)
|
|
23
|
+
|
|
24
|
+
const schema = {
|
|
25
|
+
title: 'object with bigint',
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
id: {
|
|
29
|
+
type: 'integer'
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const stringify = build(schema)
|
|
35
|
+
const output = stringify({
|
|
36
|
+
id: 1615n
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
t.equal(output, '{"id":1615}')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('render an array with a bigint as JSON', (t) => {
|
|
43
|
+
t.plan(1)
|
|
44
|
+
|
|
45
|
+
const schema = {
|
|
46
|
+
title: 'array with bigint',
|
|
47
|
+
type: 'array',
|
|
48
|
+
items: {
|
|
49
|
+
type: 'integer'
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const stringify = build(schema)
|
|
54
|
+
const output = stringify([1615n])
|
|
55
|
+
|
|
56
|
+
t.equal(output, '[1615]')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('render an object with an additionalProperty of type bigint as JSON', (t) => {
|
|
60
|
+
t.plan(1)
|
|
61
|
+
|
|
62
|
+
const schema = {
|
|
63
|
+
title: 'object with bigint',
|
|
64
|
+
type: 'object',
|
|
65
|
+
additionalProperties: {
|
|
66
|
+
type: 'integer'
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const stringify = build(schema)
|
|
71
|
+
const output = stringify({
|
|
72
|
+
num: 1615n
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
t.equal(output, '{"num":1615}')
|
|
76
|
+
})
|
package/test/debug-mode.test.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const test = require('tap').test
|
|
4
4
|
const fjs = require('..')
|
|
5
|
+
const Ajv = require('ajv').default
|
|
5
6
|
|
|
6
7
|
function build (opts) {
|
|
7
8
|
return fjs({
|
|
@@ -17,32 +18,40 @@ function build (opts) {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
test('activate debug mode', t => {
|
|
20
|
-
t.plan(
|
|
21
|
+
t.plan(3)
|
|
21
22
|
const debugMode = build({ debugMode: true })
|
|
22
|
-
|
|
23
|
-
t.
|
|
23
|
+
|
|
24
|
+
t.type(debugMode, 'object')
|
|
25
|
+
t.ok(debugMode.ajv instanceof Ajv)
|
|
26
|
+
t.type(debugMode.code, 'string')
|
|
24
27
|
})
|
|
25
28
|
|
|
26
29
|
test('activate debug mode truthy', t => {
|
|
27
|
-
t.plan(
|
|
30
|
+
t.plan(3)
|
|
31
|
+
|
|
28
32
|
const debugMode = build({ debugMode: 'yes' })
|
|
29
|
-
|
|
30
|
-
t.
|
|
33
|
+
|
|
34
|
+
t.type(debugMode, 'object')
|
|
35
|
+
t.type(debugMode.code, 'string')
|
|
36
|
+
t.ok(debugMode.ajv instanceof Ajv)
|
|
31
37
|
})
|
|
32
38
|
|
|
33
39
|
test('to string auto-consistent', t => {
|
|
34
|
-
t.plan(
|
|
40
|
+
t.plan(4)
|
|
35
41
|
const debugMode = build({ debugMode: 1 })
|
|
36
|
-
t.type(debugMode, Array)
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
t.type(debugMode, 'object')
|
|
44
|
+
t.type(debugMode.code, 'string')
|
|
45
|
+
t.ok(debugMode.ajv instanceof Ajv)
|
|
46
|
+
|
|
47
|
+
const compiled = fjs.restore(debugMode)
|
|
40
48
|
const tobe = JSON.stringify({ firstName: 'Foo' })
|
|
41
49
|
t.same(compiled({ firstName: 'Foo', surname: 'bar' }), tobe, 'surname evicted')
|
|
42
50
|
})
|
|
43
51
|
|
|
44
52
|
test('to string auto-consistent with ajv', t => {
|
|
45
|
-
t.plan(
|
|
53
|
+
t.plan(4)
|
|
54
|
+
|
|
46
55
|
const debugMode = fjs({
|
|
47
56
|
title: 'object with multiple types field',
|
|
48
57
|
type: 'object',
|
|
@@ -56,10 +65,38 @@ test('to string auto-consistent with ajv', t => {
|
|
|
56
65
|
}
|
|
57
66
|
}
|
|
58
67
|
}, { debugMode: 1 })
|
|
59
|
-
t.type(debugMode, Array)
|
|
60
68
|
|
|
61
|
-
|
|
62
|
-
|
|
69
|
+
t.type(debugMode, 'object')
|
|
70
|
+
t.type(debugMode.code, 'string')
|
|
71
|
+
t.ok(debugMode.ajv instanceof Ajv)
|
|
72
|
+
|
|
73
|
+
const compiled = fjs.restore(debugMode)
|
|
63
74
|
const tobe = JSON.stringify({ str: 'Foo' })
|
|
64
75
|
t.same(compiled({ str: 'Foo', void: 'me' }), tobe)
|
|
65
76
|
})
|
|
77
|
+
|
|
78
|
+
test('to string auto-consistent with ajv-formats', t => {
|
|
79
|
+
t.plan(3)
|
|
80
|
+
|
|
81
|
+
const debugMode = fjs({
|
|
82
|
+
title: 'object with multiple types field and format keyword',
|
|
83
|
+
type: 'object',
|
|
84
|
+
properties: {
|
|
85
|
+
str: {
|
|
86
|
+
anyOf: [{
|
|
87
|
+
type: 'string',
|
|
88
|
+
format: 'email'
|
|
89
|
+
}, {
|
|
90
|
+
type: 'boolean'
|
|
91
|
+
}]
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}, { debugMode: 1 })
|
|
95
|
+
|
|
96
|
+
t.type(debugMode, 'object')
|
|
97
|
+
|
|
98
|
+
const compiled = fjs.restore(debugMode)
|
|
99
|
+
const tobe = JSON.stringify({ str: 'foo@bar.com' })
|
|
100
|
+
t.same(compiled({ str: 'foo@bar.com' }), tobe)
|
|
101
|
+
t.same(compiled({ str: 'foo' }), JSON.stringify({ str: null }), 'invalid format is ignored')
|
|
102
|
+
})
|
|
@@ -8,11 +8,13 @@ const schema = {
|
|
|
8
8
|
properties: {
|
|
9
9
|
},
|
|
10
10
|
if: {
|
|
11
|
+
type: 'object',
|
|
11
12
|
properties: {
|
|
12
13
|
kind: { type: 'string', enum: ['foobar'] }
|
|
13
14
|
}
|
|
14
15
|
},
|
|
15
16
|
then: {
|
|
17
|
+
type: 'object',
|
|
16
18
|
properties: {
|
|
17
19
|
kind: { type: 'string', enum: ['foobar'] },
|
|
18
20
|
foo: { type: 'string' },
|
|
@@ -30,6 +32,7 @@ const schema = {
|
|
|
30
32
|
}
|
|
31
33
|
},
|
|
32
34
|
else: {
|
|
35
|
+
type: 'object',
|
|
33
36
|
properties: {
|
|
34
37
|
kind: { type: 'string', enum: ['greeting'] },
|
|
35
38
|
hi: { type: 'string' },
|
|
@@ -52,17 +55,20 @@ const nestedIfSchema = {
|
|
|
52
55
|
type: 'object',
|
|
53
56
|
properties: { },
|
|
54
57
|
if: {
|
|
58
|
+
type: 'object',
|
|
55
59
|
properties: {
|
|
56
60
|
kind: { type: 'string', enum: ['foobar', 'greeting'] }
|
|
57
61
|
}
|
|
58
62
|
},
|
|
59
63
|
then: {
|
|
60
64
|
if: {
|
|
65
|
+
type: 'object',
|
|
61
66
|
properties: {
|
|
62
67
|
kind: { type: 'string', enum: ['foobar'] }
|
|
63
68
|
}
|
|
64
69
|
},
|
|
65
70
|
then: {
|
|
71
|
+
type: 'object',
|
|
66
72
|
properties: {
|
|
67
73
|
kind: { type: 'string', enum: ['foobar'] },
|
|
68
74
|
foo: { type: 'string' },
|
|
@@ -80,6 +86,7 @@ const nestedIfSchema = {
|
|
|
80
86
|
}
|
|
81
87
|
},
|
|
82
88
|
else: {
|
|
89
|
+
type: 'object',
|
|
83
90
|
properties: {
|
|
84
91
|
kind: { type: 'string', enum: ['greeting'] },
|
|
85
92
|
hi: { type: 'string' },
|
|
@@ -88,6 +95,7 @@ const nestedIfSchema = {
|
|
|
88
95
|
}
|
|
89
96
|
},
|
|
90
97
|
else: {
|
|
98
|
+
type: 'object',
|
|
91
99
|
properties: {
|
|
92
100
|
kind: { type: 'string', enum: ['alphabet'] },
|
|
93
101
|
a: { type: 'string' },
|
|
@@ -100,11 +108,13 @@ const nestedElseSchema = {
|
|
|
100
108
|
type: 'object',
|
|
101
109
|
properties: { },
|
|
102
110
|
if: {
|
|
111
|
+
type: 'object',
|
|
103
112
|
properties: {
|
|
104
113
|
kind: { type: 'string', enum: ['foobar'] }
|
|
105
114
|
}
|
|
106
115
|
},
|
|
107
116
|
then: {
|
|
117
|
+
type: 'object',
|
|
108
118
|
properties: {
|
|
109
119
|
kind: { type: 'string', enum: ['foobar'] },
|
|
110
120
|
foo: { type: 'string' },
|
|
@@ -123,11 +133,13 @@ const nestedElseSchema = {
|
|
|
123
133
|
},
|
|
124
134
|
else: {
|
|
125
135
|
if: {
|
|
136
|
+
type: 'object',
|
|
126
137
|
properties: {
|
|
127
138
|
kind: { type: 'string', enum: ['greeting'] }
|
|
128
139
|
}
|
|
129
140
|
},
|
|
130
141
|
then: {
|
|
142
|
+
type: 'object',
|
|
131
143
|
properties: {
|
|
132
144
|
kind: { type: 'string', enum: ['greeting'] },
|
|
133
145
|
hi: { type: 'string' },
|
|
@@ -135,6 +147,7 @@ const nestedElseSchema = {
|
|
|
135
147
|
}
|
|
136
148
|
},
|
|
137
149
|
else: {
|
|
150
|
+
type: 'object',
|
|
138
151
|
properties: {
|
|
139
152
|
kind: { type: 'string', enum: ['alphabet'] },
|
|
140
153
|
a: { type: 'string' },
|
|
@@ -154,11 +167,13 @@ const noElseSchema = {
|
|
|
154
167
|
properties: {
|
|
155
168
|
},
|
|
156
169
|
if: {
|
|
170
|
+
type: 'object',
|
|
157
171
|
properties: {
|
|
158
172
|
kind: { type: 'string', enum: ['foobar'] }
|
|
159
173
|
}
|
|
160
174
|
},
|
|
161
175
|
then: {
|
|
176
|
+
type: 'object',
|
|
162
177
|
properties: {
|
|
163
178
|
kind: { type: 'string', enum: ['foobar'] },
|
|
164
179
|
foo: { type: 'string' },
|
|
@@ -310,7 +325,7 @@ t.test('if-then-else', t => {
|
|
|
310
325
|
t.test(test.name + ' - normal', t => {
|
|
311
326
|
t.plan(1)
|
|
312
327
|
|
|
313
|
-
const stringify = build(JSON.parse(JSON.stringify(test.schema)))
|
|
328
|
+
const stringify = build(JSON.parse(JSON.stringify(test.schema)), { ajv: { strictTypes: false } })
|
|
314
329
|
const serialized = stringify(test.input)
|
|
315
330
|
t.equal(serialized, test.expected)
|
|
316
331
|
})
|
package/test/integer.test.js
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const t = require('tap')
|
|
4
4
|
const test = t.test
|
|
5
|
-
const semver = require('semver')
|
|
6
5
|
const validator = require('is-my-json-valid')
|
|
7
|
-
const
|
|
8
|
-
const build = proxyquire('..', { long: null })
|
|
6
|
+
const build = require('..')
|
|
9
7
|
const ROUNDING_TYPES = ['ceil', 'floor', 'round']
|
|
10
8
|
|
|
11
9
|
test('render an integer as JSON', (t) => {
|
|
@@ -136,13 +134,6 @@ test('render an object with an additionalProperty of type integer as JSON', (t)
|
|
|
136
134
|
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
137
135
|
})
|
|
138
136
|
|
|
139
|
-
if (semver.gt(process.versions.node, '10.3.0')) {
|
|
140
|
-
require('./bigint')(t.test, build)
|
|
141
|
-
} else {
|
|
142
|
-
t.pass('Skip because Node version < 10.4')
|
|
143
|
-
t.end()
|
|
144
|
-
}
|
|
145
|
-
|
|
146
137
|
test('should round integer object parameter', t => {
|
|
147
138
|
t.plan(2)
|
|
148
139
|
|
package/test/nullable.test.js
CHANGED
|
@@ -97,16 +97,21 @@ const testSet = {
|
|
|
97
97
|
items: {}
|
|
98
98
|
}, null, null],
|
|
99
99
|
nullableObject: [{ type: 'object', nullable: true }, null, null],
|
|
100
|
-
complexObject: [complexObject, complexData, complexExpectedResult]
|
|
100
|
+
complexObject: [complexObject, complexData, complexExpectedResult, { ajv: { allowUnionTypes: true } }]
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
Object.keys(testSet).forEach(key => {
|
|
104
104
|
test(`handle nullable:true in ${key} correctly`, (t) => {
|
|
105
105
|
t.plan(1)
|
|
106
106
|
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
const [
|
|
108
|
+
schema,
|
|
109
|
+
data,
|
|
110
|
+
expected,
|
|
111
|
+
extraOptions
|
|
112
|
+
] = testSet[key]
|
|
113
|
+
|
|
114
|
+
const stringifier = build(schema, extraOptions)
|
|
110
115
|
const result = stringifier(data)
|
|
111
116
|
t.same(JSON.parse(result), expected)
|
|
112
117
|
})
|
package/test/side-effect.test.js
CHANGED
|
@@ -155,3 +155,42 @@ test('must not mutate items $ref', t => {
|
|
|
155
155
|
t.equal(value, '[{"name":"foo"}]')
|
|
156
156
|
t.same(schema, clonedSchema)
|
|
157
157
|
})
|
|
158
|
+
|
|
159
|
+
test('must not mutate items referred by $ref', t => {
|
|
160
|
+
t.plan(2)
|
|
161
|
+
|
|
162
|
+
const firstSchema = {
|
|
163
|
+
$id: 'example1',
|
|
164
|
+
type: 'object',
|
|
165
|
+
properties: {
|
|
166
|
+
name: {
|
|
167
|
+
type: 'string'
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const reusedSchema = {
|
|
173
|
+
$id: 'example2',
|
|
174
|
+
type: 'object',
|
|
175
|
+
properties: {
|
|
176
|
+
name: {
|
|
177
|
+
oneOf: [
|
|
178
|
+
{
|
|
179
|
+
$ref: 'example1'
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const clonedSchema = clone(firstSchema)
|
|
187
|
+
const stringify = build(reusedSchema, {
|
|
188
|
+
schema: {
|
|
189
|
+
[firstSchema.$id]: firstSchema
|
|
190
|
+
}
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
const value = stringify({ name: { name: 'foo' } })
|
|
194
|
+
t.equal(value, '{"name":{"name":"foo"}}')
|
|
195
|
+
t.same(firstSchema, clonedSchema)
|
|
196
|
+
})
|
package/test/types/tsconfig.json
CHANGED
package/test/typesArray.test.js
CHANGED
|
@@ -17,7 +17,7 @@ test('possibly nullable integer primitive alternative', (t) => {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const stringify = build(schema)
|
|
20
|
+
const stringify = build(schema, { ajv: { allowUnionTypes: true } })
|
|
21
21
|
|
|
22
22
|
const value = stringify({
|
|
23
23
|
data: 4
|
|
@@ -328,7 +328,7 @@ test('object with anyOf and multiple types', (t) => {
|
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
|
-
const stringify = build(schema)
|
|
331
|
+
const stringify = build(schema, { ajv: { allowUnionTypes: true } })
|
|
332
332
|
|
|
333
333
|
try {
|
|
334
334
|
const value = stringify({
|
package/test/bigint.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
module.exports = function (test, build) {
|
|
4
|
-
test('render a bigint as JSON', (t) => {
|
|
5
|
-
t.plan(1)
|
|
6
|
-
|
|
7
|
-
const schema = {
|
|
8
|
-
title: 'bigint',
|
|
9
|
-
type: 'integer'
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const stringify = build(schema)
|
|
13
|
-
const output = stringify(1615n)
|
|
14
|
-
|
|
15
|
-
t.equal(output, '1615')
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
test('render an object with a bigint as JSON', (t) => {
|
|
19
|
-
t.plan(1)
|
|
20
|
-
|
|
21
|
-
const schema = {
|
|
22
|
-
title: 'object with bigint',
|
|
23
|
-
type: 'object',
|
|
24
|
-
properties: {
|
|
25
|
-
id: {
|
|
26
|
-
type: 'integer'
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const stringify = build(schema)
|
|
32
|
-
const output = stringify({
|
|
33
|
-
id: 1615n
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
t.equal(output, '{"id":1615}')
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
test('render an array with a bigint as JSON', (t) => {
|
|
40
|
-
t.plan(1)
|
|
41
|
-
|
|
42
|
-
const schema = {
|
|
43
|
-
title: 'array with bigint',
|
|
44
|
-
type: 'array',
|
|
45
|
-
items: {
|
|
46
|
-
type: 'integer'
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const stringify = build(schema)
|
|
51
|
-
const output = stringify([1615n])
|
|
52
|
-
|
|
53
|
-
t.equal(output, '[1615]')
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
test('render an object with an additionalProperty of type bigint as JSON', (t) => {
|
|
57
|
-
t.plan(1)
|
|
58
|
-
|
|
59
|
-
const schema = {
|
|
60
|
-
title: 'object with bigint',
|
|
61
|
-
type: 'object',
|
|
62
|
-
additionalProperties: {
|
|
63
|
-
type: 'integer'
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const stringify = build(schema)
|
|
68
|
-
const output = stringify({
|
|
69
|
-
num: 1615n
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
t.equal(output, '{"num":1615}')
|
|
73
|
-
})
|
|
74
|
-
}
|
package/test/long.test.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const test = require('tap').test
|
|
4
|
-
const validator = require('is-my-json-valid')
|
|
5
|
-
const Long = require('long')
|
|
6
|
-
const build = require('..')
|
|
7
|
-
|
|
8
|
-
test('render a long as JSON', (t) => {
|
|
9
|
-
t.plan(2)
|
|
10
|
-
|
|
11
|
-
const schema = {
|
|
12
|
-
title: 'long',
|
|
13
|
-
type: 'integer'
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const validate = validator(schema)
|
|
17
|
-
const stringify = build(schema)
|
|
18
|
-
const output = stringify(Long.fromString('18446744073709551615', true))
|
|
19
|
-
|
|
20
|
-
t.equal(output, '18446744073709551615')
|
|
21
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
test('render an object with long as JSON', (t) => {
|
|
25
|
-
t.plan(2)
|
|
26
|
-
|
|
27
|
-
const schema = {
|
|
28
|
-
title: 'object with long',
|
|
29
|
-
type: 'object',
|
|
30
|
-
properties: {
|
|
31
|
-
id: {
|
|
32
|
-
type: 'integer'
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const validate = validator(schema)
|
|
38
|
-
const stringify = build(schema)
|
|
39
|
-
const output = stringify({
|
|
40
|
-
id: Long.fromString('18446744073709551615', true)
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
t.equal(output, '{"id":18446744073709551615}')
|
|
44
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
test('render an array with long as JSON', (t) => {
|
|
48
|
-
t.plan(2)
|
|
49
|
-
|
|
50
|
-
const schema = {
|
|
51
|
-
title: 'array with long',
|
|
52
|
-
type: 'array',
|
|
53
|
-
items: {
|
|
54
|
-
type: 'integer'
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const validate = validator(schema)
|
|
59
|
-
const stringify = build(schema)
|
|
60
|
-
const output = stringify([Long.fromString('18446744073709551615', true)])
|
|
61
|
-
|
|
62
|
-
t.equal(output, '[18446744073709551615]')
|
|
63
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
test('render an object with a long additionalProperty as JSON', (t) => {
|
|
67
|
-
t.plan(2)
|
|
68
|
-
|
|
69
|
-
const schema = {
|
|
70
|
-
title: 'object with long',
|
|
71
|
-
type: 'object',
|
|
72
|
-
additionalProperties: {
|
|
73
|
-
type: 'integer'
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const validate = validator(schema)
|
|
78
|
-
const stringify = build(schema)
|
|
79
|
-
const output = stringify({
|
|
80
|
-
num: Long.fromString('18446744073709551615', true)
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
t.equal(output, '{"num":18446744073709551615}')
|
|
84
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
85
|
-
})
|