Total Complexity | 1 |
Total Lines | 23 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package com.hltech.vaunt.validator.schema; |
||
10 | public class SchemaValidator { |
||
11 | |||
12 | private static final Set<JsonSchemaValidator> schemaValidators = new HashSet<>(); |
||
13 | |||
14 | static { |
||
15 | schemaValidators.addAll(Sets.newHashSet( |
||
16 | new StringSchemaValidator(), |
||
17 | new ObjectSchemaValidator(), |
||
18 | new BooleanSchemaValidator(), |
||
19 | new IntegerSchemaValidator(), |
||
20 | new NumberSchemaValidator() |
||
21 | )); |
||
22 | } |
||
23 | |||
24 | public static List<String> validate(JsonSchema consumerSchema, JsonSchema providerSchema) { |
||
25 | JsonSchemaValidator matchingValidator = schemaValidators.stream() |
||
26 | .filter(v -> v.supportsSchemaType().equals(consumerSchema.getClass())) |
||
27 | .filter(v -> v.supportsSchemaType().equals(providerSchema.getClass())) |
||
28 | .findAny() |
||
29 | .orElseThrow(() -> new RuntimeException( |
||
30 | "Exactly one validator should exist for consumer and provider")); |
||
31 | |||
32 | return matchingValidator.validate(consumerSchema, providerSchema); |
||
33 | } |
||
35 |