Skip to content

Commit

Permalink
Adds schema properties getter methods to JsonSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
David Belmez committed Jun 6, 2016
1 parent fd781ef commit 8525531
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ apply(plugin: "idea");
apply(plugin: "eclipse");

group = "com.github.fge";
version = "2.2.6";
version = "2.2.7";
sourceCompatibility = "1.6";
targetCompatibility = "1.6"; // defaults to sourceCompatibility

Expand Down
40 changes: 36 additions & 4 deletions src/main/java/com/github/fge/jsonschema/main/JsonSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
import com.github.fge.jsonschema.core.processing.ProcessingResult;
import com.github.fge.jsonschema.core.processing.Processor;
import com.github.fge.jsonschema.core.report.ListProcessingReport;
import com.github.fge.jsonschema.core.report.MessageProvider;
import com.github.fge.jsonschema.core.report.ProcessingReport;
import com.github.fge.jsonschema.core.report.ReportProvider;
import com.github.fge.jsonschema.core.tree.SchemaTree;
import com.github.fge.jsonschema.core.tree.SimpleJsonTree;
import com.github.fge.jsonschema.processors.data.FullData;
import com.github.fge.jsonschema.processors.validation.ValidationProcessor;

import java.util.Iterator;
import javax.annotation.concurrent.Immutable;

/**
Expand Down Expand Up @@ -142,8 +141,8 @@ public ProcessingReport validate(final JsonNode instance)
* thrown during processing)
*
*
* @see ProcessingResult#uncheckedResult(Processor, ProcessingReport,
* MessageProvider)
* @see ProcessingResult#uncheckedResult(com.github.fge.jsonschema.core.processing.Processor, ProcessingReport,
* com.github.fge.jsonschema.core.report.MessageProvider)
* @see JsonValidator#validate(JsonNode, JsonNode, boolean)
*
* @since 2.1.8
Expand Down Expand Up @@ -196,4 +195,37 @@ public boolean validInstanceUnchecked(final JsonNode instance)
{
return doValidateUnchecked(instance, false).isSuccess();
}

/**
* Method to finding a JSON Schema attribute with specified name and returning the node.
* If no matching attribute is found, returns null.
*
* @param name Name of attribute to look for
*
* @return Node of the attribute, if any; null if none
*/
public JsonNode getProperty(final String name) {
return schema.getNode().findValue("properties").get(name);
}

/**
* Method for checking if a JSON Schema attribute with specified name is required.
* If no matching attribute is found, returns null.
*
* @param name Name of attribute to look for
*
* @return true if it is required, false if not
*/
public boolean isRequired(final String name) {
final JsonNode requiredNode = schema.getNode().findValue("required");
if (requiredNode != null) {
final Iterator<JsonNode> requiredElements = requiredNode.elements();
while (requiredElements.hasNext()) {
if (name.equals(requiredElements.next().asText())) {
return true;
}
}
}
return false;
}
}

0 comments on commit 8525531

Please sign in to comment.