Skip to content

Commit

Permalink
Fix: JSON schemata now all behind httpS
Browse files Browse the repository at this point in the history
As the online location of the draft 3-7 JSON schema definitions now
redirects to HTTPS, this breaks determining the JSON schema version.

This fix allows both http & https for these JSON schema definitions.
  • Loading branch information
opwvhk committed Oct 23, 2023
1 parent 03ba4d6 commit 04626e4
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/main/java/opwvhk/avro/json/SchemaAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -472,27 +472,23 @@ private static <T> void add(List<T> list, T newItem) {
}

private enum SchemaVersion {
DRAFT_3("http://json-schema.org/draft-03/schema#"),
DRAFT_4("http://json-schema.org/draft-04/schema#"),
DRAFT_6("http://json-schema.org/draft-06/schema#"),
DRAFT_7("http://json-schema.org/draft-07/schema#"),
DRAFT_2019_09("https://json-schema.org/draft/2019-09/schema"),
DRAFT_2020_12("https://json-schema.org/draft/2020-12/schema");
DRAFT_3, DRAFT_4, DRAFT_6, DRAFT_7, DRAFT_2019_09, DRAFT_2020_12;
private static final Map<URI, SchemaVersion> VERSIONS_BY_IDENTIFIERS = Map.of(
URI.create("http://json-schema.org/draft-03/schema#"), DRAFT_3,
URI.create("https://json-schema.org/draft-03/schema#"), DRAFT_3,
URI.create("http://json-schema.org/draft-04/schema#"), DRAFT_4,
URI.create("https://json-schema.org/draft-04/schema#"), DRAFT_4,
URI.create("http://json-schema.org/draft-06/schema#"), DRAFT_6,
URI.create("https://json-schema.org/draft-06/schema#"), DRAFT_6,
URI.create("http://json-schema.org/draft-07/schema#"), DRAFT_7,
URI.create("https://json-schema.org/draft-07/schema#"), DRAFT_7,
URI.create("https://json-schema.org/draft/2019-09/schema"), DRAFT_2019_09,
URI.create("https://json-schema.org/draft/2020-12/schema"), DRAFT_2020_12
);

private static SchemaVersion valueOf(URI identifier) {
for (SchemaVersion schemaVersion : values()) {
if (schemaVersion.identifier.equals(identifier)) {
return schemaVersion;
}
}
// Unknown schema: use a default
return DRAFT_7;
}

private final URI identifier;

SchemaVersion(String identifier) {
this.identifier = URI.create(identifier);
// Return the identified schema, or draft 7 by default.
return VERSIONS_BY_IDENTIFIERS.getOrDefault(identifier, DRAFT_7);
}

private boolean isAtLeast(SchemaVersion schemaVersion) {
Expand Down

0 comments on commit 04626e4

Please sign in to comment.