File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ function resolveRef (location, ref) {
5555 }
5656
5757 const schemaId = ref . slice ( 0 , hashIndex ) || location . schemaId
58- const jsonPointer = ref . slice ( hashIndex )
58+ const jsonPointer = ref . slice ( hashIndex ) || '#'
5959
6060 const schemaRef = schemaId + jsonPointer
6161
Original file line number Diff line number Diff line change @@ -1926,3 +1926,30 @@ test('anyOf inside allOf', (t) => {
19261926
19271927 t . equal ( output , JSON . stringify ( object ) )
19281928} )
1929+
1930+ test ( 'should resolve absolute $refs' , ( t ) => {
1931+ t . plan ( 1 )
1932+
1933+ const externalSchema = {
1934+ FooSchema : {
1935+ $id : 'FooSchema' ,
1936+ type : 'object' ,
1937+ properties : {
1938+ type : {
1939+ anyOf : [
1940+ { type : 'string' , const : 'bar' } ,
1941+ { type : 'string' , const : 'baz' }
1942+ ]
1943+ }
1944+ }
1945+ }
1946+ }
1947+
1948+ const schema = { $ref : 'FooSchema' }
1949+
1950+ const object = { type : 'bar' }
1951+ const stringify = build ( schema , { schema : externalSchema } )
1952+ const output = stringify ( object )
1953+
1954+ t . equal ( output , JSON . stringify ( object ) )
1955+ } )
You can’t perform that action at this time.
0 commit comments