@@ -887,9 +887,52 @@ describe('DefinitionGenerator', () => {
887887 } )
888888
889889 expect ( definitionGenerator . openAPI . components . schemas ) . to . have . property ( 'main' )
890- expect ( definitionGenerator . openAPI . components . schemas . main . properties ) . to . have . property ( 'Error' )
891- expect ( definitionGenerator . openAPI . components . schemas . main . properties . Error ) . to . have . property ( 'type' )
892- expect ( definitionGenerator . openAPI . components . schemas . main . properties . Error . type ) . to . be . equal ( 'string' )
890+ expect ( definitionGenerator . openAPI . components . schemas . main ) . to . have . property ( 'type' )
891+ expect ( definitionGenerator . openAPI . components . schemas . main . type ) . to . be . equal ( 'string' )
892+ expect ( definitionGenerator . openAPI . components . schemas . main ) . to . not . have . property ( '$schema' )
893+ expect ( definitionGenerator . openAPI . components . schemas . main ) . to . not . have . property ( '$definitions' )
894+ expect ( expected ) . to . equal ( '#/components/schemas/main' )
895+
896+ expect ( spy . callCount ) . to . be . equal ( 2 )
897+
898+ spy . resetHistory ( )
899+ } ) ;
900+
901+ it ( 'should handle a complex schema that has been incorrectly dereferenced' , async function ( ) {
902+ const definitionGenerator = new DefinitionGenerator ( mockServerless )
903+
904+ const complexSchema = {
905+ $schema : 'http://json-schema.org/draft-04/schema#' ,
906+ title : 'JSON API Schema' ,
907+ $ref : '#/definitions/Person' ,
908+ definitions : {
909+ Person : {
910+ type : 'object' ,
911+ properties : {
912+ name : {
913+ type : 'string'
914+ } ,
915+ age : {
916+ type : 'number'
917+ }
918+ }
919+ }
920+ }
921+ }
922+
923+ const spy = sinon . spy ( definitionGenerator , 'dereferenceSchema' )
924+
925+ const expected = await definitionGenerator . schemaCreator ( complexSchema , 'main' )
926+ . catch ( ( err ) => {
927+ console . error ( err )
928+ } )
929+
930+ expect ( definitionGenerator . openAPI . components . schemas ) . to . have . property ( 'main' )
931+ expect ( definitionGenerator . openAPI . components . schemas . main ) . to . have . property ( 'type' )
932+ expect ( definitionGenerator . openAPI . components . schemas . main . type ) . to . be . equal ( 'object' )
933+ expect ( definitionGenerator . openAPI . components . schemas . main ) . to . have . property ( 'properties' )
934+ expect ( definitionGenerator . openAPI . components . schemas . main . properties ) . to . have . property ( 'name' )
935+ expect ( definitionGenerator . openAPI . components . schemas . main . properties ) . to . have . property ( 'age' )
893936 expect ( definitionGenerator . openAPI . components . schemas . main ) . to . not . have . property ( '$schema' )
894937 expect ( definitionGenerator . openAPI . components . schemas . main ) . to . not . have . property ( '$definitions' )
895938 expect ( expected ) . to . equal ( '#/components/schemas/main' )
@@ -1052,9 +1095,8 @@ describe('DefinitionGenerator', () => {
10521095 } )
10531096
10541097 expect ( definitionGenerator . openAPI . components . schemas ) . to . have . property ( 'LicensedMember' )
1055- expect ( definitionGenerator . openAPI . components . schemas . LicensedMember . properties ) . to . have . property ( 'Error' )
1056- expect ( definitionGenerator . openAPI . components . schemas . LicensedMember . properties . Error ) . to . have . property ( 'type' )
1057- expect ( definitionGenerator . openAPI . components . schemas . LicensedMember . properties . Error . type ) . to . be . equal ( 'string' )
1098+ expect ( definitionGenerator . openAPI . components . schemas . LicensedMember ) . to . have . property ( 'type' )
1099+ expect ( definitionGenerator . openAPI . components . schemas . LicensedMember . type ) . to . be . equal ( 'string' )
10581100 expect ( definitionGenerator . openAPI . components . schemas . LicensedMember ) . to . not . have . property ( '$schema' )
10591101 expect ( definitionGenerator . openAPI . components . schemas . LicensedMember ) . to . not . have . property ( '$definitions' )
10601102 expect ( expected ) . to . equal ( '#/components/schemas/LicensedMember' )
0 commit comments