diff --git a/vocabulary/format-assertion/src/main/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/Formats.java b/vocabulary/format-assertion/src/main/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/Formats.java index a1231ca..fe3982f 100644 --- a/vocabulary/format-assertion/src/main/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/Formats.java +++ b/vocabulary/format-assertion/src/main/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/Formats.java @@ -31,27 +31,18 @@ final class Formats { - private static final Map> RFCS = Map.of( - "hostname", - Map.entry(1123, "hostname"), - "date-time", - Map.entry(3339, "date-time"), - "date", - Map.entry(3339, "full-date"), - "time", - Map.entry(3339, "full-time"), - "duration", - Map.entry(3339, "duration"), - "uri", - Map.entry(3986, "URI"), - "uri-reference", - Map.entry(3986, "URI-reference"), - "email", - Map.entry(5321, "mailbox"), - "ipv4", - Map.entry(2673, "dotted-quad"), - "ipv6", - Map.entry(4291, "IPv6address") + private static final Map> RFCS = Map.ofEntries( + Map.entry("hostname", Map.entry(1123, "hostname")), + Map.entry("date-time", Map.entry(3339, "date-time")), + Map.entry("date", Map.entry(3339, "full-date")), + Map.entry("time", Map.entry(3339, "full-time")), + Map.entry("duration", Map.entry(3339, "duration")), + Map.entry("uri", Map.entry(3986, "URI")), + Map.entry("uri-reference", Map.entry(3986, "URI-reference")), + Map.entry("email", Map.entry(5321, "mailbox")), + Map.entry("ipv4", Map.entry(2673, "dotted-quad")), + Map.entry("uuid", Map.entry(4122, "UUID")), + Map.entry("ipv6", Map.entry(4291, "IPv6address")) ); Format findByName(final String name) { diff --git a/vocabulary/format-assertion/src/main/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/rfc/Rfcs.java b/vocabulary/format-assertion/src/main/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/rfc/Rfcs.java index 9fa0970..cce9c1e 100644 --- a/vocabulary/format-assertion/src/main/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/rfc/Rfcs.java +++ b/vocabulary/format-assertion/src/main/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/rfc/Rfcs.java @@ -193,6 +193,17 @@ public final class Rfcs { ) ) ), + Map.entry( + 4122, + Map.of( + "UUID", + new RegExRule( + Pattern.compile( + "^[0-9A-Fa-f]{8}\\-[0-9A-Fa-f]{4}\\-[0-9A-Fa-f]{4}\\-[0-9A-Fa-f]{4}\\-[0-9A-Fa-f]{12}$" + ) + ) + ) + ), Map.entry( 4291, Map.of( diff --git a/vocabulary/format-assertion/src/main/resources/rfc/rfc4122 b/vocabulary/format-assertion/src/main/resources/rfc/rfc4122 new file mode 100644 index 0000000..10053c4 --- /dev/null +++ b/vocabulary/format-assertion/src/main/resources/rfc/rfc4122 @@ -0,0 +1,15 @@ +UUID = time-low "-" time-mid "-" + time-high-and-version "-" + clock-seq-and-reserved + clock-seq-low "-" node +time-low = 4hexOctet +time-mid = 2hexOctet +time-high-and-version = 2hexOctet +clock-seq-and-reserved = hexOctet +clock-seq-low = hexOctet +node = 6hexOctet +hexOctet = hexDigit hexDigit +hexDigit = + "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9" / + "a" / "b" / "c" / "d" / "e" / "f" / + "A" / "B" / "C" / "D" / "E" / "F" \ No newline at end of file diff --git a/vocabulary/format-assertion/src/test/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/FormatsTest.java b/vocabulary/format-assertion/src/test/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/FormatsTest.java index c2f9553..53396a0 100644 --- a/vocabulary/format-assertion/src/test/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/FormatsTest.java +++ b/vocabulary/format-assertion/src/test/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/FormatsTest.java @@ -115,4 +115,10 @@ void should_found_urireferenceformat() { assertThat(new Formats().findByName("uri-reference").applyTo("/json-schema"), is(true)); assertThat(new Formats().findByName("uri-reference").applyTo("1://noUri"), is(false)); } + + @Test + void should_found_uuidformat() { + assertThat(new Formats().findByName("uuid").applyTo("b7128c5b-eafc-4b6b-9b35-1c9e3dbaabb1"), is(true)); + assertThat(new Formats().findByName("uuid").applyTo("b7128c5b-eafc-4b6b-9b35"), is(false)); + } }