|
1
|
|
|
package com.hltech.vaunt.validator.schema; |
|
2
|
|
|
|
|
3
|
|
|
import com.fasterxml.jackson.module.jsonSchema.JsonSchema; |
|
4
|
|
|
import com.fasterxml.jackson.module.jsonSchema.types.StringSchema; |
|
5
|
|
|
|
|
6
|
|
|
import java.util.List; |
|
7
|
|
|
|
|
8
|
|
|
public class StringSchemaValidator extends ValueTypeSchemaValidator { |
|
9
|
|
|
|
|
10
|
|
|
@Override |
|
11
|
|
|
public List<String> validate(JsonSchema consumerSchema, JsonSchema providerSchema) { |
|
12
|
|
|
List<String> errors = super.validate(consumerSchema, providerSchema); |
|
13
|
|
|
|
|
14
|
|
|
StringSchema consumerStringSchema = consumerSchema.asStringSchema(); |
|
15
|
|
|
StringSchema providerStringSchema = providerSchema.asStringSchema(); |
|
16
|
|
|
|
|
17
|
|
|
if (!equals(consumerStringSchema.getMinLength(), providerStringSchema.getMinLength())) { |
|
18
|
|
|
errors.add(String.format(ERROR_FORMAT, |
|
19
|
|
|
consumerStringSchema.getId(), |
|
20
|
|
|
"minLength", |
|
21
|
|
|
consumerStringSchema.getMinLength(), |
|
22
|
|
|
providerStringSchema.getMinLength())); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
if (!equals(consumerStringSchema.getMaxLength(), providerStringSchema.getMaxLength())) { |
|
26
|
|
|
errors.add(String.format(ERROR_FORMAT, |
|
27
|
|
|
consumerStringSchema.getId(), |
|
28
|
|
|
"maxLength", |
|
29
|
|
|
consumerStringSchema.getMaxLength(), |
|
30
|
|
|
providerStringSchema.getMaxLength())); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if (!equals(consumerStringSchema.getPattern(), providerStringSchema.getPattern())) { |
|
34
|
|
|
errors.add(String.format(ERROR_FORMAT, |
|
35
|
|
|
consumerStringSchema.getId(), |
|
36
|
|
|
"pattern", |
|
37
|
|
|
consumerStringSchema.getPattern(), |
|
38
|
|
|
providerStringSchema.getPattern())); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return errors; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
@Override |
|
45
|
|
|
public Class<?> supportsSchemaType() { |
|
46
|
|
|
return StringSchema.class; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|