fast-json-stringify
Advanced tools
Comparing version 5.0.0 to 5.0.1
@@ -105,6 +105,6 @@ 'use strict' | ||
if (options.schema) { | ||
options.schema = clone(options.schema) | ||
const externalSchemas = clone(options.schema) | ||
for (const key of Object.keys(options.schema)) { | ||
const externalSchema = options.schema[key] | ||
for (const key of Object.keys(externalSchemas)) { | ||
const externalSchema = externalSchemas[key] | ||
isValidSchema(externalSchema, key) | ||
@@ -111,0 +111,0 @@ extendDateTimeType(externalSchema) |
{ | ||
"name": "fast-json-stringify", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "Stringify your JSON at max speed", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
'use strict' | ||
const clone = require('rfdc')({ proto: true }) | ||
const test = require('tap').test | ||
@@ -1825,1 +1827,68 @@ const build = require('..') | ||
}) | ||
test('Should not modify external schemas', (t) => { | ||
t.plan(2) | ||
const externalSchema = { | ||
uuid: { | ||
format: 'uuid', | ||
$id: 'UUID', | ||
type: 'string' | ||
}, | ||
Entity: { | ||
$id: 'Entity', | ||
type: 'object', | ||
properties: { | ||
id: { $ref: 'UUID' }, | ||
id2: { $ref: 'UUID' } | ||
} | ||
} | ||
} | ||
const options = { schema: externalSchema } | ||
const optionsClone = clone(options) | ||
const stringify = build({ $ref: 'Entity' }, options) | ||
const data = { id: 'a4e4c954-9f5f-443a-aa65-74d95732249a' } | ||
const output = stringify(data) | ||
t.equal(output, JSON.stringify(data)) | ||
t.same(options, optionsClone) | ||
}) | ||
test('input schema is not mutated', (t) => { | ||
t.plan(3) | ||
const schema = { | ||
title: 'object with $ref', | ||
type: 'object', | ||
definitions: { | ||
def: { type: 'string' } | ||
}, | ||
properties: { | ||
obj: { | ||
$ref: '#/definitions/def' | ||
} | ||
} | ||
} | ||
const clonedSchema = JSON.parse(JSON.stringify(schema)) | ||
const object = { | ||
obj: 'test' | ||
} | ||
const stringify = build(schema) | ||
const output = stringify(object) | ||
try { | ||
JSON.parse(output) | ||
t.pass() | ||
} catch (e) { | ||
t.fail() | ||
} | ||
t.equal(output, '{"obj":"test"}') | ||
t.same(schema, clonedSchema) | ||
}) |
310139
11523