|
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 (!equals(consumerIntegerSchema.getAdditionalItems(), providerIntegerSchema.getAdditionalItems())) { |
|
18
|
|
|
errors.add(String.format(ERROR_FORMAT_SHORT, |
|
19
|
|
|
consumerIntegerSchema.getId(), |
|
20
|
|
|
"additionalItems")); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
if (!equals(consumerIntegerSchema.getItems(), providerIntegerSchema.getItems())) { |
|
24
|
|
|
errors.add(String.format(ERROR_FORMAT_SHORT, |
|
25
|
|
|
consumerIntegerSchema.getId(), |
|
26
|
|
|
"items")); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
if (!equals(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 (!equals(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 (!equals(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
|
|
|
|