fast-json-stringify 1.16.3 → 1.16.4
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 +2 -1
- package/package.json +1 -1
- package/test/ref.test.js +35 -0
package/index.js
CHANGED
|
@@ -75,6 +75,7 @@ function build (schema, options) {
|
|
|
75
75
|
`
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
const fullSchema = schema
|
|
78
79
|
if (schema.$ref) {
|
|
79
80
|
schema = refFinder(schema.$ref, schema, options.schema)
|
|
80
81
|
}
|
|
@@ -90,7 +91,7 @@ function build (schema, options) {
|
|
|
90
91
|
switch (schema.type) {
|
|
91
92
|
case 'object':
|
|
92
93
|
main = '$main'
|
|
93
|
-
code = buildObject(schema, code, main, options.schema,
|
|
94
|
+
code = buildObject(schema, code, main, options.schema, fullSchema)
|
|
94
95
|
break
|
|
95
96
|
case 'string':
|
|
96
97
|
main = schema.nullable ? $asStringNullable.name : $asString.name
|
package/package.json
CHANGED
package/test/ref.test.js
CHANGED
|
@@ -685,6 +685,41 @@ test('ref internal - multiple $ref format', (t) => {
|
|
|
685
685
|
t.equal(output, '{"zero":"test","a":"test","b":"test","c":"test","d":"test","e":"test"}')
|
|
686
686
|
})
|
|
687
687
|
|
|
688
|
+
test('ref in root internal', (t) => {
|
|
689
|
+
t.plan(2)
|
|
690
|
+
|
|
691
|
+
const schema = {
|
|
692
|
+
title: 'object with $ref in root schema',
|
|
693
|
+
$ref: '#/definitions/num',
|
|
694
|
+
definitions: {
|
|
695
|
+
num: {
|
|
696
|
+
type: 'object',
|
|
697
|
+
properties: {
|
|
698
|
+
int: {
|
|
699
|
+
$ref: '#/definitions/int'
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
},
|
|
703
|
+
int: {
|
|
704
|
+
type: 'integer'
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
const object = { int: 42 }
|
|
710
|
+
const stringify = build(schema)
|
|
711
|
+
const output = stringify(object)
|
|
712
|
+
|
|
713
|
+
try {
|
|
714
|
+
JSON.parse(output)
|
|
715
|
+
t.pass()
|
|
716
|
+
} catch (e) {
|
|
717
|
+
t.fail()
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
t.equal(output, '{"int":42}')
|
|
721
|
+
})
|
|
722
|
+
|
|
688
723
|
test('ref in root external', (t) => {
|
|
689
724
|
t.plan(2)
|
|
690
725
|
|