validate(JsonSchema,JsonSchema)   B
last analyzed

Complexity

Conditions 6

Size

Total Lines 44
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 6
eloc 32
c 1
b 0
f 1
dl 0
loc 44
rs 8.1786
1
package com.hltech.vaunt.validator.schema;
2
3
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
4
import com.fasterxml.jackson.module.jsonSchema.types.ArraySchema;
5
6
import java.util.List;
7
8
public class ArraySchemaValidator extends ContainerTypeSchemaValidator {
9
10
    @Override
11
    public List<String> validate(JsonSchema consumerSchema, JsonSchema providerSchema) {
12
        List<String> errors = super.validate(consumerSchema, providerSchema);
13
14
        ArraySchema consumerIntegerSchema = consumerSchema.asArraySchema();
15
        ArraySchema providerIntegerSchema = providerSchema.asArraySchema();
16
17
        if (!isValid(consumerIntegerSchema.getAdditionalItems(), providerIntegerSchema.getAdditionalItems())) {
18
            errors.add(String.format(ERROR_FORMAT_SHORT,
19
                    consumerIntegerSchema.getId(),
20
                    "additionalItems"));
21
        }
22
23
        if (!isValid(consumerIntegerSchema.getItems(), providerIntegerSchema.getItems())) {
24
            errors.add(String.format(ERROR_FORMAT_SHORT,
25
                    consumerIntegerSchema.getId(),
26
                    "items"));
27
        }
28
29
        if (!isValid(consumerIntegerSchema.getMaxItems(), providerIntegerSchema.getMaxItems())) {
30
            errors.add(String.format(ERROR_FORMAT,
31
                    consumerIntegerSchema.getId(),
32
                    "maxItems",
33
                    consumerIntegerSchema.getMaxItems(),
34
                    providerIntegerSchema.getMaxItems()));
35
        }
36
37
        if (!isValid(consumerIntegerSchema.getMinItems(), providerIntegerSchema.getMinItems())) {
38
            errors.add(String.format(ERROR_FORMAT,
39
                    consumerIntegerSchema.getId(),
40
                    "minItems",
41
                    consumerIntegerSchema.getMinItems(),
42
                    providerIntegerSchema.getMinItems()));
43
        }
44
45
        if (!isValid(consumerIntegerSchema.getUniqueItems(), providerIntegerSchema.getUniqueItems())) {
46
            errors.add(String.format(ERROR_FORMAT,
47
                    consumerIntegerSchema.getId(),
48
                    "uniqueItems",
49
                    consumerIntegerSchema.getUniqueItems(),
50
                    providerIntegerSchema.getUniqueItems()));
51
        }
52
53
        return errors;
54
    }
55
56
    @Override
57
    public Class<?> supportsSchemaType() {
58
        return ArraySchema.class;
59
    }
60
}
61