| 
22 | 22 | import com.fasterxml.jackson.databind.JsonNode;  | 
23 | 23 | import com.github.fge.jsonschema.core.exceptions.ProcessingException;  | 
24 | 24 | import com.github.fge.jsonschema.core.processing.ProcessingResult;  | 
25 |  | -import com.github.fge.jsonschema.core.processing.Processor;  | 
26 | 25 | import com.github.fge.jsonschema.core.report.ListProcessingReport;  | 
27 |  | -import com.github.fge.jsonschema.core.report.MessageProvider;  | 
28 | 26 | import com.github.fge.jsonschema.core.report.ProcessingReport;  | 
29 | 27 | import com.github.fge.jsonschema.core.report.ReportProvider;  | 
30 | 28 | import com.github.fge.jsonschema.core.tree.SchemaTree;  | 
31 | 29 | import com.github.fge.jsonschema.core.tree.SimpleJsonTree;  | 
32 | 30 | import com.github.fge.jsonschema.processors.data.FullData;  | 
33 | 31 | import com.github.fge.jsonschema.processors.validation.ValidationProcessor;  | 
34 | 32 | 
 
  | 
 | 33 | +import java.util.Iterator;  | 
35 | 34 | import javax.annotation.concurrent.Immutable;  | 
36 | 35 | 
 
  | 
37 | 36 | /**  | 
@@ -142,8 +141,8 @@ public ProcessingReport validate(final JsonNode instance)  | 
142 | 141 |      * thrown during processing)  | 
143 | 142 |      *  | 
144 | 143 |      *  | 
145 |  | -     * @see ProcessingResult#uncheckedResult(Processor, ProcessingReport,  | 
146 |  | -     * MessageProvider)  | 
 | 144 | +     * @see ProcessingResult#uncheckedResult(com.github.fge.jsonschema.core.processing.Processor, ProcessingReport,  | 
 | 145 | +     * com.github.fge.jsonschema.core.report.MessageProvider)  | 
147 | 146 |      * @see JsonValidator#validate(JsonNode, JsonNode, boolean)  | 
148 | 147 |      *  | 
149 | 148 |      * @since 2.1.8  | 
@@ -196,4 +195,37 @@ public boolean validInstanceUnchecked(final JsonNode instance)  | 
196 | 195 |     {  | 
197 | 196 |         return doValidateUnchecked(instance, false).isSuccess();  | 
198 | 197 |     }  | 
 | 198 | + | 
 | 199 | +    /**  | 
 | 200 | +     * Method to finding a JSON Schema attribute with specified name and returning the node.  | 
 | 201 | +     * If no matching attribute is found, returns null.  | 
 | 202 | +     *  | 
 | 203 | +     * @param name Name of attribute to look for  | 
 | 204 | +     *  | 
 | 205 | +     * @return Node of the attribute, if any; null if none  | 
 | 206 | +     */  | 
 | 207 | +    public JsonNode getProperty(final String name) {  | 
 | 208 | +        return schema.getNode().findValue("properties").get(name);  | 
 | 209 | +    }  | 
 | 210 | + | 
 | 211 | +    /**  | 
 | 212 | +     * Method for checking if a JSON Schema attribute with specified name is required.  | 
 | 213 | +     * If no matching attribute is found, returns null.  | 
 | 214 | +     *  | 
 | 215 | +     * @param name Name of attribute to look for  | 
 | 216 | +     *  | 
 | 217 | +     * @return true if it is required, false if not  | 
 | 218 | +     */  | 
 | 219 | +    public boolean isRequired(final String name) {  | 
 | 220 | +        final JsonNode requiredNode = schema.getNode().findValue("required");  | 
 | 221 | +        if (requiredNode != null) {  | 
 | 222 | +            final Iterator<JsonNode> requiredElements = requiredNode.elements();  | 
 | 223 | +            while (requiredElements.hasNext()) {  | 
 | 224 | +                if (name.equals(requiredElements.next().asText())) {  | 
 | 225 | +                    return true;  | 
 | 226 | +                }  | 
 | 227 | +            }  | 
 | 228 | +        }  | 
 | 229 | +        return false;  | 
 | 230 | +    }  | 
199 | 231 | }  | 
0 commit comments