File tree Expand file tree Collapse file tree 2 files changed +61
-1
lines changed Expand file tree Collapse file tree 2 files changed +61
-1
lines changed Original file line number Diff line number Diff line change @@ -225,7 +225,19 @@ function inferTypeByKeyword (schema) {
225
225
226
226
function dependsOnAjv ( schema ) {
227
227
const str = JSON . stringify ( schema )
228
- return ( / " i f " : { .* " t h e n " : { | " ( a n y O f | o n e O f ) " : \[ | " c o n s t " : / . test ( str ) )
228
+ switch ( true ) {
229
+ case / " i f " : { .* " t h e n " : { / . test ( str ) :
230
+ case / " ( a n y O f | o n e O f ) " : \[ / . test ( str ) :
231
+ case / " c o n s t " / . test ( str ) :
232
+ case / " \$ r e f " / . test ( str ) :
233
+ {
234
+ return true
235
+ }
236
+
237
+ default : {
238
+ return false
239
+ }
240
+ }
229
241
}
230
242
231
243
const stringSerializerMap = {
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const t = require ( 'tap' )
4
+ const build = require ( '..' )
5
+
6
+ t . test ( 'nested ref requires ajv' , async t => {
7
+ const schemaA = {
8
+ $id : 'urn:schema:a' ,
9
+ definitions : {
10
+ foo : { anyOf : [ { type : 'string' } , { type : 'null' } ] }
11
+ }
12
+ }
13
+
14
+ const schemaB = {
15
+ $id : 'urn:schema:b' ,
16
+ type : 'object' ,
17
+ properties : {
18
+ results : {
19
+ type : 'object' ,
20
+ properties : {
21
+ items : {
22
+ type : 'object' ,
23
+ properties : {
24
+ bar : {
25
+ type : 'array' ,
26
+ items : { $ref : 'urn:schema:a#/definitions/foo' }
27
+ }
28
+ }
29
+ }
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ const stringify = build ( schemaB , {
36
+ schema : {
37
+ [ schemaA . $id ] : schemaA
38
+ }
39
+ } )
40
+ const result = stringify ( {
41
+ results : {
42
+ items : {
43
+ bar : [ 'baz' ]
44
+ }
45
+ }
46
+ } )
47
+ t . same ( result , '{"results":{"items":{"bar":["baz"]}}}' )
48
+ } )
You can’t perform that action at this time.
0 commit comments