@@ -1032,13 +1032,139 @@ describe("Error messages", async () => {
1032
1032
} ) ;
1033
1033
1034
1034
test ( "normalized output for a failing 'contains' keyword" , async ( ) => {
1035
+ registerSchema ( {
1036
+ $schema : "https://json-schema.org/draft/2020-12/schema" ,
1037
+ contains : {
1038
+ type : "number" ,
1039
+ multipleOf : 2
1040
+ }
1041
+ } , schemaUri ) ;
1042
+ const instance = [ "" , 3 , 5 ] ;
1043
+ const output = {
1044
+ valid : false ,
1045
+ errors : [
1046
+ {
1047
+ valid : false ,
1048
+ keywordLocation : "/contains" ,
1049
+ instanceLocation : "#" ,
1050
+ absoluteKeywordLocation : "https://example.com/main#/contains" ,
1051
+ errors : [
1052
+ {
1053
+ valid : false ,
1054
+ instanceLocation : "#/0" ,
1055
+ absoluteKeywordLocation : "https://example.com/main#/contains/type"
1056
+ } ,
1057
+ {
1058
+ valid : false ,
1059
+ instanceLocation : "#/1" ,
1060
+ absoluteKeywordLocation : "https://example.com/main#/contains/multipleOf"
1061
+ } ,
1062
+ {
1063
+ valid : false ,
1064
+ instanceLocation : "#/2" ,
1065
+ absoluteKeywordLocation : "https://example.com/main#/contains/multipleOf"
1066
+ }
1067
+ ]
1068
+ }
1069
+ ]
1070
+ } ;
1071
+ const result = await betterJsonSchemaErrors ( output , schemaUri , instance ) ;
1072
+ expect ( result . errors ) . to . eql ( [
1073
+ {
1074
+ instanceLocation : "#" ,
1075
+ message : localization . getContainsErrorMessage ( { minContains : 1 } ) ,
1076
+ schemaLocation : "https://example.com/main#/contains"
1077
+ } ,
1078
+ {
1079
+ instanceLocation : "#/0" ,
1080
+ message : localization . getTypeErrorMessage ( "number" , "string" ) ,
1081
+ schemaLocation : "https://example.com/main#/contains/type"
1082
+ } ,
1083
+ {
1084
+ instanceLocation : "#/1" ,
1085
+ message : localization . getMultipleOfErrorMessage ( 2 ) ,
1086
+ schemaLocation : "https://example.com/main#/contains/multipleOf"
1087
+ } ,
1088
+ {
1089
+ instanceLocation : "#/2" ,
1090
+ message : localization . getMultipleOfErrorMessage ( 2 ) ,
1091
+ schemaLocation : "https://example.com/main#/contains/multipleOf"
1092
+ }
1093
+ ] ) ;
1094
+ } ) ;
1095
+
1096
+ test ( "normalized output for a failing 'contains' keyword with only minContains" , async ( ) => {
1097
+ registerSchema ( {
1098
+ $schema : "https://json-schema.org/draft/2020-12/schema" ,
1099
+ contains : {
1100
+ type : "number" ,
1101
+ multipleOf : 2
1102
+ } ,
1103
+ minContains : 2
1104
+ } , schemaUri ) ;
1105
+ const instance = [ "" , 3 , 5 ] ;
1106
+ const output = {
1107
+ valid : false ,
1108
+ errors : [
1109
+ {
1110
+ valid : false ,
1111
+ keywordLocation : "/contains" ,
1112
+ instanceLocation : "#" ,
1113
+ absoluteKeywordLocation : "https://example.com/main#/contains" ,
1114
+ errors : [
1115
+ {
1116
+ valid : false ,
1117
+ instanceLocation : "#/0" ,
1118
+ absoluteKeywordLocation : "https://example.com/main#/contains/type"
1119
+ } ,
1120
+ {
1121
+ valid : false ,
1122
+ instanceLocation : "#/1" ,
1123
+ absoluteKeywordLocation : "https://example.com/main#/contains/multipleOf"
1124
+ } ,
1125
+ {
1126
+ valid : false ,
1127
+ instanceLocation : "#/2" ,
1128
+ absoluteKeywordLocation : "https://example.com/main#/contains/multipleOf"
1129
+ }
1130
+ ]
1131
+ }
1132
+ ]
1133
+ } ;
1134
+ const result = await betterJsonSchemaErrors ( output , schemaUri , instance ) ;
1135
+ expect ( result . errors ) . to . eql ( [
1136
+ {
1137
+ instanceLocation : "#" ,
1138
+ message : localization . getContainsErrorMessage ( { minContains : 2 } ) ,
1139
+ schemaLocation : "https://example.com/main#/contains"
1140
+ } ,
1141
+ {
1142
+ instanceLocation : "#/0" ,
1143
+ message : localization . getTypeErrorMessage ( "number" , "string" ) ,
1144
+ schemaLocation : "https://example.com/main#/contains/type"
1145
+ } ,
1146
+ {
1147
+ instanceLocation : "#/1" ,
1148
+ message : localization . getMultipleOfErrorMessage ( 2 ) ,
1149
+ schemaLocation : "https://example.com/main#/contains/multipleOf"
1150
+ } ,
1151
+ {
1152
+ instanceLocation : "#/2" ,
1153
+ message : localization . getMultipleOfErrorMessage ( 2 ) ,
1154
+ schemaLocation : "https://example.com/main#/contains/multipleOf"
1155
+ }
1156
+ ] ) ;
1157
+ } ) ;
1158
+
1159
+ test ( "`contains` with `minContains` and `maxContains` keyword" , async ( ) => {
1035
1160
registerSchema ( {
1036
1161
$schema : "https://json-schema.org/draft/2020-12/schema" ,
1037
1162
contains : {
1038
1163
type : "number" ,
1039
1164
multipleOf : 2
1040
1165
} ,
1041
- minContains : 1
1166
+ minContains : 2 ,
1167
+ maxContains : 4
1042
1168
} , schemaUri ) ;
1043
1169
const instance = [ "" , 3 , 5 ] ;
1044
1170
const output = {
@@ -1073,7 +1199,7 @@ describe("Error messages", async () => {
1073
1199
expect ( result . errors ) . to . eql ( [
1074
1200
{
1075
1201
instanceLocation : "#" ,
1076
- message : localization . getContainsErrorMessage ( ) ,
1202
+ message : localization . getContainsErrorMessage ( { minContains : 2 , maxContains : 4 } ) ,
1077
1203
schemaLocation : "https://example.com/main#/contains"
1078
1204
} ,
1079
1205
{
0 commit comments