@@ -887,9 +887,52 @@ describe('DefinitionGenerator', () => {
887
887
} )
888
888
889
889
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' )
893
936
expect ( definitionGenerator . openAPI . components . schemas . main ) . to . not . have . property ( '$schema' )
894
937
expect ( definitionGenerator . openAPI . components . schemas . main ) . to . not . have . property ( '$definitions' )
895
938
expect ( expected ) . to . equal ( '#/components/schemas/main' )
@@ -1052,9 +1095,8 @@ describe('DefinitionGenerator', () => {
1052
1095
} )
1053
1096
1054
1097
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' )
1058
1100
expect ( definitionGenerator . openAPI . components . schemas . LicensedMember ) . to . not . have . property ( '$schema' )
1059
1101
expect ( definitionGenerator . openAPI . components . schemas . LicensedMember ) . to . not . have . property ( '$definitions' )
1060
1102
expect ( expected ) . to . equal ( '#/components/schemas/LicensedMember' )
0 commit comments