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) {
55
55
}
56
56
57
57
const schemaId = ref . slice ( 0 , hashIndex ) || location . schemaId
58
- const jsonPointer = ref . slice ( hashIndex )
58
+ const jsonPointer = ref . slice ( hashIndex ) || '#'
59
59
60
60
const schemaRef = schemaId + jsonPointer
61
61
Original file line number Diff line number Diff line change @@ -1926,3 +1926,30 @@ test('anyOf inside allOf', (t) => {
1926
1926
1927
1927
t . equal ( output , JSON . stringify ( object ) )
1928
1928
} )
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