-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from harrel56/feature/disallow-non-empty-fragm…
…ents2 Add id validation to subschemas too
- Loading branch information
Showing
3 changed files
with
90 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package dev.harrel.jsonschema; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
final class JsonNodeUtil { | ||
private JsonNodeUtil() {} | ||
|
||
static Optional<Map<String, JsonNode>> getAsObject(JsonNode node) { | ||
return node.isObject() ? Optional.of(node.asObject()) : Optional.empty(); | ||
} | ||
|
||
static Optional<String> getStringField(Map<String, JsonNode> objectMap, String fieldName) { | ||
return Optional.ofNullable(objectMap.get(fieldName)) | ||
.filter(JsonNode::isString) | ||
.map(JsonNode::asString); | ||
} | ||
|
||
static void validateIdField(String id) { | ||
if (UriUtil.hasNonEmptyFragment(URI.create(id))) { | ||
throw new IllegalArgumentException(String.format("$id [%s] cannot contain non-empty fragments", id)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters