Skip to content

Commit b07aaf1

Browse files
committed
fixes #188 couldnot validate the email format in json schema
1 parent 22d29af commit b07aaf1

File tree

8 files changed

+2689
-8
lines changed

8 files changed

+2689
-8
lines changed

src/main/java/com/networknt/schema/FormatKeyword.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Map;
2222

2323
import com.fasterxml.jackson.databind.JsonNode;
24+
import com.networknt.schema.format.EmailValidator;
2425

2526
public class FormatKeyword implements Keyword {
2627
private final ValidatorTypeCode type;
@@ -29,6 +30,7 @@ public class FormatKeyword implements Keyword {
2930
private final String DATE = "date";
3031
private final String DATE_TIME = "date-time";
3132
private final String UUID = "uuid";
33+
private final String EMAIL = "email";
3234

3335
public FormatKeyword(ValidatorTypeCode type, Map<String, Format> formats) {
3436
this.type = type;
@@ -51,6 +53,8 @@ public JsonValidator newValidator(String schemaPath, JsonNode schemaNode, JsonSc
5153
return new DateTimeValidator(schemaPath, schemaNode, parentSchema, validationContext, formatName);
5254
} else if (formatName.equals(UUID)) {
5355
return new UUIDValidator(schemaPath, schemaNode, parentSchema, validationContext, formatName);
56+
} else if (formatName.equals(EMAIL)) {
57+
return new EmailValidator(schemaPath, schemaNode, parentSchema, validationContext, formatName);
5458
}
5559
}
5660
return new FormatValidator(schemaPath, schemaNode, parentSchema, validationContext, format);

src/main/java/com/networknt/schema/JsonMetaSchema.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,8 @@ private static class DraftV4 {
4545
private static final String DRAFT_4_ID = "id";
4646
public static final List<Format> BUILTIN_FORMATS = new ArrayList<Format>();
4747
static {
48-
BUILTIN_FORMATS.add(pattern("date-time",
49-
"^\\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(0?[1-9]|[12][0-9]|3[01])[tT ]\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?([zZ]?|[+-]\\d{2}:\\d{2})$"));
50-
BUILTIN_FORMATS.add(pattern("date", "^\\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(0?[1-9]|[12][0-9]|3[01])$"));
5148
BUILTIN_FORMATS.add(pattern("time", "^\\d{2}:\\d{2}:\\d{2}$"));
52-
BUILTIN_FORMATS.add(pattern("email", "^\\S+@\\S+$"));
53-
BUILTIN_FORMATS.add(pattern("ip-address",
49+
BUILTIN_FORMATS.add(pattern("ip-address",
5450
"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"));
5551
BUILTIN_FORMATS.add(pattern("ipv4",
5652
"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"));

src/main/java/com/networknt/schema/JsonSchemaFactory.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,7 @@ private JsonSchemaFactory(
185185

186186
/**
187187
* Builder without keywords or formats.
188-
*
189-
* Use {@link #getDraftV4()} instead, or if you need a builder based on Draft4, use
190-
*
188+
*
191189
* <code>
192190
* JsonSchemaFactory.builder(JsonSchemaFactory.getDraftV4()).build();
193191
* </code>

0 commit comments

Comments
 (0)