Skip to content

Commit

Permalink
Merge pull request #193 from sebastian-toepfer/format_assertion_uuid
Browse files Browse the repository at this point in the history
add support for uuid format
  • Loading branch information
sebastian-toepfer authored Dec 8, 2024
2 parents 625ba56 + 269296c commit 5140221
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,18 @@

final class Formats {

private static final Map<String, Map.Entry<Integer, String>> 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<String, Map.Entry<Integer, String>> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 15 additions & 0 deletions vocabulary/format-assertion/src/main/resources/rfc/rfc4122
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 5140221

Please sign in to comment.