File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -337,8 +337,8 @@ function buildCode (location) {
337
337
const propertiesLocation = mergeLocation ( location , 'properties' )
338
338
Object . keys ( schema . properties || { } ) . forEach ( ( key ) => {
339
339
let propertyLocation = mergeLocation ( propertiesLocation , key )
340
- if ( propertyLocation . $ref ) {
341
- propertyLocation = resolveRef ( location , propertyLocation . $ref )
340
+ if ( propertyLocation . schema . $ref ) {
341
+ propertyLocation = resolveRef ( location , propertyLocation . schema . $ref )
342
342
}
343
343
344
344
const sanitized = JSON . stringify ( key )
Original file line number Diff line number Diff line change @@ -1981,3 +1981,27 @@ test('nested schema should overwrite anchor scope', (t) => {
1981
1981
t . equal ( output , JSON . stringify ( data ) )
1982
1982
t . throws ( ( ) => build ( { $ref : 'root#anchor' } , { schema : externalSchema } ) )
1983
1983
} )
1984
+
1985
+ test ( 'object property reference with default value' , ( t ) => {
1986
+ t . plan ( 1 )
1987
+
1988
+ const schema = {
1989
+ definitions : {
1990
+ prop : {
1991
+ type : 'string' ,
1992
+ default : 'foo'
1993
+ }
1994
+ } ,
1995
+ type : 'object' ,
1996
+ properties : {
1997
+ prop : {
1998
+ $ref : '#/definitions/prop'
1999
+ }
2000
+ }
2001
+ }
2002
+
2003
+ const stringify = build ( schema )
2004
+ const output = stringify ( { } )
2005
+
2006
+ t . equal ( output , '{"prop":"foo"}' )
2007
+ } )
You can’t perform that action at this time.
0 commit comments