| Total Complexity | 1 |
| Total Lines | 23 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | package com.hltech.vaunt.validator; |
||
| 10 | public class VauntSchemaValidator { |
||
| 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 |