@@ -876,3 +876,202 @@ test('ref in definition with exact match', (t) => {
876
876
877
877
t . equal ( output , '{"foo":"foo"}' )
878
878
} )
879
+
880
+ test ( 'Bad key' , t => {
881
+ t . test ( 'Find match' , t => {
882
+ t . plan ( 1 )
883
+ try {
884
+ build ( {
885
+ definitions : {
886
+ projectId : {
887
+ type : 'object' ,
888
+ properties : {
889
+ id : { type : 'integer' }
890
+ }
891
+ }
892
+ } ,
893
+ type : 'object' ,
894
+ properties : {
895
+ data : {
896
+ $ref : '#/definitions/porjectId'
897
+ }
898
+ }
899
+ } )
900
+ t . fail ( 'Should throw' )
901
+ } catch ( err ) {
902
+ t . is ( err . message , "Cannot find reference 'porjectId', did you mean 'projectId'?" )
903
+ }
904
+ } )
905
+
906
+ t . test ( 'No match' , t => {
907
+ t . plan ( 1 )
908
+ try {
909
+ build ( {
910
+ definitions : {
911
+ projectId : {
912
+ type : 'object' ,
913
+ properties : {
914
+ id : { type : 'integer' }
915
+ }
916
+ }
917
+ } ,
918
+ type : 'object' ,
919
+ properties : {
920
+ data : {
921
+ $ref : '#/definitions/foobar'
922
+ }
923
+ }
924
+ } )
925
+ t . fail ( 'Should throw' )
926
+ } catch ( err ) {
927
+ t . is ( err . message , "Cannot find reference 'foobar'" )
928
+ }
929
+ } )
930
+
931
+ t . test ( 'Find match (external schema)' , t => {
932
+ t . plan ( 1 )
933
+ try {
934
+ build ( {
935
+ type : 'object' ,
936
+ properties : {
937
+ data : {
938
+ $ref : 'external#/definitions/porjectId'
939
+ }
940
+ }
941
+ } , {
942
+ schema : {
943
+ external : {
944
+ definitions : {
945
+ projectId : {
946
+ type : 'object' ,
947
+ properties : {
948
+ id : { type : 'integer' }
949
+ }
950
+ }
951
+ }
952
+ }
953
+ }
954
+ } )
955
+ t . fail ( 'Should throw' )
956
+ } catch ( err ) {
957
+ t . is ( err . message , "Cannot find reference 'porjectId', did you mean 'projectId'?" )
958
+ }
959
+ } )
960
+
961
+ t . test ( 'No match (external schema)' , t => {
962
+ t . plan ( 1 )
963
+ try {
964
+ build ( {
965
+ type : 'object' ,
966
+ properties : {
967
+ data : {
968
+ $ref : 'external#/definitions/foobar'
969
+ }
970
+ }
971
+ } , {
972
+ schema : {
973
+ external : {
974
+ definitions : {
975
+ projectId : {
976
+ type : 'object' ,
977
+ properties : {
978
+ id : { type : 'integer' }
979
+ }
980
+ }
981
+ }
982
+ }
983
+ }
984
+ } )
985
+ t . fail ( 'Should throw' )
986
+ } catch ( err ) {
987
+ t . is ( err . message , "Cannot find reference 'foobar'" )
988
+ }
989
+ } )
990
+
991
+ t . test ( 'Find match (external definitions typo)' , t => {
992
+ t . plan ( 1 )
993
+ try {
994
+ build ( {
995
+ type : 'object' ,
996
+ properties : {
997
+ data : {
998
+ $ref : 'external#/deifnitions/projectId'
999
+ }
1000
+ }
1001
+ } , {
1002
+ schema : {
1003
+ external : {
1004
+ definitions : {
1005
+ projectId : {
1006
+ type : 'object' ,
1007
+ properties : {
1008
+ id : { type : 'integer' }
1009
+ }
1010
+ }
1011
+ }
1012
+ }
1013
+ }
1014
+ } )
1015
+ t . fail ( 'Should throw' )
1016
+ } catch ( err ) {
1017
+ t . is ( err . message , "Cannot find reference 'deifnitions', did you mean 'definitions'?" )
1018
+ }
1019
+ } )
1020
+
1021
+ t . test ( 'Find match (definitions typo)' , t => {
1022
+ t . plan ( 1 )
1023
+ try {
1024
+ build ( {
1025
+ definitions : {
1026
+ projectId : {
1027
+ type : 'object' ,
1028
+ properties : {
1029
+ id : { type : 'integer' }
1030
+ }
1031
+ }
1032
+ } ,
1033
+ type : 'object' ,
1034
+ properties : {
1035
+ data : {
1036
+ $ref : '#/deifnitions/projectId'
1037
+ }
1038
+ }
1039
+ } )
1040
+ t . fail ( 'Should throw' )
1041
+ } catch ( err ) {
1042
+ t . is ( err . message , "Cannot find reference 'deifnitions', did you mean 'definitions'?" )
1043
+ }
1044
+ } )
1045
+
1046
+ t . test ( 'Find match (external schema typo)' , t => {
1047
+ t . plan ( 1 )
1048
+ try {
1049
+ build ( {
1050
+ type : 'object' ,
1051
+ properties : {
1052
+ data : {
1053
+ $ref : 'extrenal#/definitions/projectId'
1054
+ }
1055
+ }
1056
+ } , {
1057
+ schema : {
1058
+ external : {
1059
+ definitions : {
1060
+ projectId : {
1061
+ type : 'object' ,
1062
+ properties : {
1063
+ id : { type : 'integer' }
1064
+ }
1065
+ }
1066
+ }
1067
+ }
1068
+ }
1069
+ } )
1070
+ t . fail ( 'Should throw' )
1071
+ } catch ( err ) {
1072
+ t . is ( err . message , "Cannot find reference 'extrenal', did you mean 'external'?" )
1073
+ }
1074
+ } )
1075
+
1076
+ t . end ( )
1077
+ } )
0 commit comments