|
1
|
|
|
package com.hltech.vaunt.validator.schema; |
|
2
|
|
|
|
|
3
|
|
|
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; |
|
4
|
|
|
import com.fasterxml.jackson.module.jsonSchema.types.NumberSchema; |
|
5
|
|
|
|
|
6
|
|
|
import java.util.List; |
|
7
|
|
|
|
|
8
|
|
|
public class NumberSchemaValidator extends ValueTypeSchemaValidator { |
|
9
|
|
|
|
|
10
|
|
|
@Override |
|
11
|
|
|
public List<String> validate(JsonSchema consumerSchema, JsonSchema providerSchema) { |
|
12
|
|
|
List<String> errors = super.validate(consumerSchema, providerSchema); |
|
13
|
|
|
|
|
14
|
|
|
NumberSchema consumerNumberSchema = consumerSchema.asNumberSchema(); |
|
15
|
|
|
NumberSchema providerNumberSchema = providerSchema.asNumberSchema(); |
|
16
|
|
|
|
|
17
|
|
|
if (!equals(consumerNumberSchema.getExclusiveMaximum(), providerNumberSchema.getExclusiveMaximum())) { |
|
18
|
|
|
errors.add(String.format(ERROR_FORMAT, |
|
19
|
|
|
consumerNumberSchema.getId(), |
|
20
|
|
|
"exclusiveMaximum", |
|
21
|
|
|
consumerNumberSchema.getExclusiveMaximum(), |
|
22
|
|
|
providerNumberSchema.getExclusiveMaximum())); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
if (!equals(consumerNumberSchema.getExclusiveMinimum(), providerNumberSchema.getExclusiveMinimum())) { |
|
26
|
|
|
errors.add(String.format(ERROR_FORMAT, |
|
27
|
|
|
consumerNumberSchema.getId(), |
|
28
|
|
|
"exclusiveMinimum", |
|
29
|
|
|
consumerNumberSchema.getExclusiveMinimum(), |
|
30
|
|
|
providerNumberSchema.getExclusiveMinimum())); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if (!equals(consumerNumberSchema.getMaximum(), providerNumberSchema.getMaximum())) { |
|
34
|
|
|
errors.add(String.format(ERROR_FORMAT, |
|
35
|
|
|
consumerNumberSchema.getId(), |
|
36
|
|
|
"maximum", |
|
37
|
|
|
consumerNumberSchema.getMaximum(), |
|
38
|
|
|
providerNumberSchema.getMaximum())); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if (!equals(consumerNumberSchema.getMinimum(), providerNumberSchema.getMinimum())) { |
|
42
|
|
|
errors.add(String.format(ERROR_FORMAT, |
|
43
|
|
|
consumerNumberSchema.getId(), |
|
44
|
|
|
"minimum", |
|
45
|
|
|
consumerNumberSchema.getMinimum(), |
|
46
|
|
|
providerNumberSchema.getMinimum())); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if (!equals(consumerNumberSchema.getMultipleOf(), providerNumberSchema.getMultipleOf())) { |
|
50
|
|
|
errors.add(String.format(ERROR_FORMAT, |
|
51
|
|
|
consumerNumberSchema.getId(), |
|
52
|
|
|
"multipleOf", |
|
53
|
|
|
consumerNumberSchema.getMultipleOf(), |
|
54
|
|
|
providerNumberSchema.getMultipleOf())); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return errors; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
@Override |
|
61
|
|
|
public Class<?> supportsSchemaType() { |
|
62
|
|
|
return NumberSchema.class; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|