|
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,46 @@ public boolean validInstanceUnchecked(final JsonNode instance) |
196 | 195 | { |
197 | 196 | return doValidateUnchecked(instance, false).isSuccess(); |
198 | 197 | } |
| 198 | + |
| 199 | + /** |
| 200 | + * Method to retrieve all JSON Schema attributes. |
| 201 | + * |
| 202 | + * @return Node of the attributes |
| 203 | + */ |
| 204 | + public JsonNode getProperties() { |
| 205 | + return schema.getNode().findValue("properties"); |
| 206 | + } |
| 207 | + |
| 208 | + /** |
| 209 | + * Method to finding a JSON Schema attribute with specified name and returning the node. |
| 210 | + * If no matching attribute is found, returns null. |
| 211 | + * |
| 212 | + * @param name Name of attribute to look for |
| 213 | + * |
| 214 | + * @return Node of the attribute, if any; null if none |
| 215 | + */ |
| 216 | + public JsonNode getProperty(final String name) { |
| 217 | + return getProperties().get(name); |
| 218 | + } |
| 219 | + |
| 220 | + /** |
| 221 | + * Method for checking if a JSON Schema attribute with specified name is required. |
| 222 | + * If no matching attribute is found, returns null. |
| 223 | + * |
| 224 | + * @param name Name of attribute to look for |
| 225 | + * |
| 226 | + * @return true if it is required, false if not |
| 227 | + */ |
| 228 | + public boolean isRequired(final String name) { |
| 229 | + final JsonNode requiredNode = schema.getNode().findValue("required"); |
| 230 | + if (requiredNode != null) { |
| 231 | + final Iterator<JsonNode> requiredElements = requiredNode.elements(); |
| 232 | + while (requiredElements.hasNext()) { |
| 233 | + if (name.equals(requiredElements.next().asText())) { |
| 234 | + return true; |
| 235 | + } |
| 236 | + } |
| 237 | + } |
| 238 | + return false; |
| 239 | + } |
199 | 240 | } |
0 commit comments