Passed
Push — master ( e81f81...d91c1f )
by Filip
02:20
created

validate(JsonSchema,JsonSchema)   A

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
package com.hltech.vaunt.validator;
2
3
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
4
import com.google.common.collect.Sets;
5
6
import java.util.HashSet;
7
import java.util.List;
8
import java.util.Set;
9
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
    }
34
}
35