fast-json-stringify
Advanced tools
Comparing version 2.6.0 to 2.7.0
14
index.js
@@ -983,5 +983,5 @@ 'use strict' | ||
let result = { code: '', laterCode: '' } | ||
const accessor = '[i]' | ||
if (Array.isArray(schema.items)) { | ||
result = schema.items.reduce((res, item, i) => { | ||
const accessor = '[i]' | ||
const tmpRes = nested(laterCode, name, accessor, mergeLocation(location, { schema: item }), i, true) | ||
@@ -998,2 +998,12 @@ const condition = `i === ${i} && ${buildArrayTypeCondition(item.type, accessor)}` | ||
}, result) | ||
if (schema.additionalItems) { | ||
const tmpRes = nested(laterCode, name, accessor, mergeLocation(location, { schema: schema.items }), undefined, true) | ||
result.code += ` | ||
else if (i >= ${schema.items.length}) { | ||
${tmpRes.code} | ||
} | ||
` | ||
} | ||
result.code += ` | ||
@@ -1005,3 +1015,3 @@ else { | ||
} else { | ||
result = nested(laterCode, name, '[i]', mergeLocation(location, { schema: schema.items }), undefined, true) | ||
result = nested(laterCode, name, accessor, mergeLocation(location, { schema: schema.items }), undefined, true) | ||
} | ||
@@ -1008,0 +1018,0 @@ |
{ | ||
"name": "fast-json-stringify", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"description": "Stringify your JSON at max speed", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -213,2 +213,65 @@ 'use strict' | ||
test('array items is a list of schema and additionalItems is true, just the described item is validated', (t) => { | ||
t.plan(1) | ||
const schema = { | ||
type: 'object', | ||
properties: { | ||
foo: { | ||
type: 'array', | ||
items: [ | ||
{ | ||
type: 'string' | ||
} | ||
], | ||
additionalItems: true | ||
} | ||
} | ||
} | ||
const stringify = build(schema) | ||
const result = stringify({ | ||
foo: [ | ||
'foo', | ||
'bar', | ||
1 | ||
] | ||
}) | ||
t.equal(result, '{"foo":["foo","bar",1]}') | ||
}) | ||
test('array items is a list of schema and additionalItems is false', (t) => { | ||
t.plan(1) | ||
const schema = { | ||
type: 'object', | ||
properties: { | ||
foo: { | ||
type: 'array', | ||
items: [ | ||
{ | ||
type: 'string' | ||
} | ||
], | ||
additionalItems: false | ||
} | ||
} | ||
} | ||
const stringify = build(schema) | ||
try { | ||
stringify({ | ||
foo: [ | ||
'foo', | ||
'bar' | ||
] | ||
}) | ||
t.fail() | ||
} catch (error) { | ||
t.ok(/does not match schema definition./.test(error.message)) | ||
} | ||
}) | ||
// https://github.com/fastify/fast-json-stringify/issues/279 | ||
@@ -215,0 +278,0 @@ test('object array with anyOf and symbol', (t) => { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
329064
9911