(context, location, input)
| 1168 | } |
| 1169 | |
| 1170 | function buildIfThenElse (context, location, input) { |
| 1171 | context.validatorSchemasIds.add(location.schemaId) |
| 1172 | |
| 1173 | const { |
| 1174 | if: ifSchema, |
| 1175 | then: thenSchema, |
| 1176 | else: elseSchema, |
| 1177 | ...schemaWithoutIfThenElse |
| 1178 | } = location.schema |
| 1179 | |
| 1180 | const rootLocation = new Location( |
| 1181 | schemaWithoutIfThenElse, |
| 1182 | location.schemaId, |
| 1183 | location.jsonPointer |
| 1184 | ) |
| 1185 | |
| 1186 | const ifLocation = location.getPropertyLocation('if') |
| 1187 | const ifSchemaRef = ifLocation.getSchemaRef() |
| 1188 | |
| 1189 | const thenLocation = location.getPropertyLocation('then') |
| 1190 | let thenMergedSchemaId = context.mergedSchemasIds.get(thenSchema) |
| 1191 | let thenMergedLocation = null |
| 1192 | if (thenMergedSchemaId) { |
| 1193 | thenMergedLocation = getMergedLocation(context, thenMergedSchemaId) |
| 1194 | } else { |
| 1195 | thenMergedSchemaId = `__fjs_merged_${schemaIdCounter++}` |
| 1196 | context.mergedSchemasIds.set(thenSchema, thenMergedSchemaId) |
| 1197 | |
| 1198 | thenMergedLocation = mergeLocations(context, thenMergedSchemaId, [ |
| 1199 | rootLocation, |
| 1200 | thenLocation |
| 1201 | ]) |
| 1202 | } |
| 1203 | |
| 1204 | if (!elseSchema) { |
| 1205 | return ` |
| 1206 | if (validator.validate("${ifSchemaRef}", ${input})) { |
| 1207 | ${buildValue(context, thenMergedLocation, input)} |
| 1208 | } else { |
| 1209 | ${buildValue(context, rootLocation, input)} |
| 1210 | } |
| 1211 | ` |
| 1212 | } |
| 1213 | |
| 1214 | const elseLocation = location.getPropertyLocation('else') |
| 1215 | let elseMergedSchemaId = context.mergedSchemasIds.get(elseSchema) |
| 1216 | let elseMergedLocation = null |
| 1217 | if (elseMergedSchemaId) { |
| 1218 | elseMergedLocation = getMergedLocation(context, elseMergedSchemaId) |
| 1219 | } else { |
| 1220 | elseMergedSchemaId = `__fjs_merged_${schemaIdCounter++}` |
| 1221 | context.mergedSchemasIds.set(elseSchema, elseMergedSchemaId) |
| 1222 | |
| 1223 | elseMergedLocation = mergeLocations(context, elseMergedSchemaId, [ |
| 1224 | rootLocation, |
| 1225 | elseLocation |
| 1226 | ]) |
| 1227 | } |
no test coverage detected
searching dependent graphs…