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 73c97e9..5e20d89 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 @@ -33,6 +33,8 @@ final class Formats { private static final Map> RFCS = Map.of( + "hostname", + Map.of(1123, "hostname"), "date-time", Map.of(3339, "date-time"), "date", 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 c0266d5..3e2d03a 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 @@ -36,6 +36,10 @@ public final class Rfcs { //create regex with: https://abnf.msweet.org/index.php private static final Map> RULES = Map.ofEntries( + Map.entry( + 1123, + Map.of("hostname", new RegExRule(Pattern.compile("(?=\\A[-a-z0-9]{1,63}\\Z)\\A[a-z0-9]+(-[a-z0-9]+)*\\Z"))) + ), Map.entry( 2673, Map.of("dotted-quad", new RegExRule(Pattern.compile("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$"))) 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 0f299e3..d87993d 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 @@ -96,4 +96,10 @@ void should_found_ipv6Format() { //ipv4 only -> invalid! assertThat(new Formats().findByName("ipv6").applyTo("125.158.4589.1"), is(false)); } + + @Test + void should_found_hostname() { + assertThat(new Formats().findByName("hostname").applyTo("www"), is(true)); + assertThat(new Formats().findByName("hostname").applyTo("bar_baz"), is(false)); + } }