Skip to content

Commit 9700ebc

Browse files
committed
Updated test
1 parent 311e1a5 commit 9700ebc

File tree

1 file changed

+79
-12
lines changed

1 file changed

+79
-12
lines changed

test/ref.test.js

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,33 +48,45 @@ test('ref internal - properties', (t) => {
4848
test('ref external - properties', (t) => {
4949
t.plan(2)
5050

51-
const schema = {
52-
title: 'object with $ref',
53-
definitions: {
54-
def: {
55-
type: 'object',
56-
properties: {
57-
str: {
58-
type: 'string'
51+
const externalSchema = {
52+
first: require('./ref.json'),
53+
second: {
54+
definitions: {
55+
num: {
56+
type: 'object',
57+
properties: {
58+
int: {
59+
type: 'integer'
60+
}
5961
}
6062
}
6163
}
62-
},
64+
}
65+
}
66+
67+
const schema = {
68+
title: 'object with $ref',
6369
type: 'object',
6470
properties: {
6571
obj: {
66-
$ref: __dirname + '/ref.json#/definitions/def' // eslint-disable-line
72+
$ref: 'first#/definitions/def'
73+
},
74+
num: {
75+
$ref: 'second#/definitions/num'
6776
}
6877
}
6978
}
7079

7180
const object = {
7281
obj: {
7382
str: 'test'
83+
},
84+
num: {
85+
int: 42
7486
}
7587
}
7688

77-
const stringify = build(schema)
89+
const stringify = build(schema, { schema: externalSchema })
7890
const output = stringify(object)
7991

8092
try {
@@ -84,7 +96,7 @@ test('ref external - properties', (t) => {
8496
t.fail()
8597
}
8698

87-
t.equal('{"obj":{"str":"test"}}', output)
99+
t.equal('{"obj":{"str":"test"},"num":{"int":42}}', output)
88100
})
89101

90102
test('ref internal - patternProperties', (t) => {
@@ -219,3 +231,58 @@ test('ref internal - pattern-additional Properties', (t) => {
219231

220232
t.equal('{"reg":{"str":"test"},"obj":{"str":"test"}}', output)
221233
})
234+
235+
test('ref external - pattern-additional Properties', (t) => {
236+
t.plan(2)
237+
238+
const externalSchema = {
239+
first: require('./ref.json'),
240+
second: {
241+
definitions: {
242+
num: {
243+
type: 'object',
244+
properties: {
245+
int: {
246+
type: 'integer'
247+
}
248+
}
249+
}
250+
}
251+
}
252+
}
253+
254+
const schema = {
255+
title: 'object with $ref',
256+
type: 'object',
257+
properties: {},
258+
patternProperties: {
259+
reg: {
260+
$ref: 'first#/definitions/def'
261+
}
262+
},
263+
additionalProperties: {
264+
$ref: 'second#/definitions/num'
265+
}
266+
}
267+
268+
const object = {
269+
reg: {
270+
str: 'test'
271+
},
272+
obj: {
273+
int: 42
274+
}
275+
}
276+
277+
const stringify = build(schema, { schema: externalSchema })
278+
const output = stringify(object)
279+
280+
try {
281+
JSON.parse(output)
282+
t.pass()
283+
} catch (e) {
284+
t.fail()
285+
}
286+
287+
t.equal('{"reg":{"str":"test"},"obj":{"int":42}}', output)
288+
})

0 commit comments

Comments
 (0)