@Override public int hashCode() { return locator.hashCode() ^ pointer.hashCode(); }
public Iterable<JsonPointer> selectSchemas(final int index) { if (!hasItems) return hasAdditional ? ImmutableList.of(ADDITIONAL_ITEMS) : Collections.<JsonPointer>emptyList(); if (!itemsIsArray) return ImmutableList.of(ITEMS); if (index < itemsSize) return ImmutableList.of(ITEMS.append(index)); return hasAdditional ? ImmutableList.of(ADDITIONAL_ITEMS) : Collections.<JsonPointer>emptyList(); } }
/** * Build an instance validator tied to a subschema from a main schema * * <p>Note that the validity of the schema is <b>not</b> checked. Use {@link * #getSyntaxValidator()} if you are not sure.</p> * * @param schema the schema * @param ptr a JSON Pointer as a string * @return a {@link JsonSchema} * @throws ProcessingException {@code ptr} is not a valid JSON Pointer, or * resolving the pointer against the schema leads to a {@link MissingNode} * @throws NullPointerException schema is null, or pointer is null */ public JsonSchema getJsonSchema(final JsonNode schema, final String ptr) throws ProcessingException { BUNDLE.checkNotNull(schema, "nullSchema"); CORE_BUNDLE.checkNotNull(ptr, "nullPointer"); final JsonPointer pointer; try { pointer = new JsonPointer(ptr); return validator.buildJsonSchema(schema, pointer); } catch (JsonPointerException ignored) { // Cannot happen } throw new IllegalStateException("How did I get there??"); }
@Override public String toString() { final URI tmp; try { tmp = new URI(null, null, pointer.toString()); } catch (URISyntaxException e) { throw new RuntimeException("How did I get there??", e); } return locator.toURI().resolve(tmp).toString(); } }
/** * Build an instance validator tied to a schema * * <p>Note that the validity of the schema is <b>not</b> checked. Use {@link * #getSyntaxValidator()} if you are not sure.</p> * * @param schema the schema * @return a {@link JsonSchema} * @throws ProcessingException schema is a {@link MissingNode} * @throws NullPointerException schema is null */ public JsonSchema getJsonSchema(final JsonNode schema) throws ProcessingException { BUNDLE.checkNotNull(schema, "nullSchema"); return validator.buildJsonSchema(schema, JsonPointer.empty()); }
@Override public boolean equals(@Nullable final Object obj) { if (obj == null) return false; if (this == obj) return true; if (getClass() != obj.getClass()) return false; final SchemaURI other = (SchemaURI) obj; return locator.equals(other.locator) && pointer.equals(other.pointer); }
@DataProvider public Iterator<Object[]> testData() throws ProcessingException, JsonPointerException { final List<Object[]> list = Lists.newArrayList(); JsonNode digest; String memberName; List<JsonPointer> ret; for (final JsonNode node: testNode) { digest = node.get("digest"); memberName = node.get("memberName").textValue(); ret = Lists.newArrayList(); for (final JsonNode element: node.get("ret")) ret.add(new JsonPointer(element.textValue())); list.add(new Object[]{ digest, memberName, ret }); } return list.iterator(); }
@Override protected void checkOkOk(final ProcessingReport report) throws ProcessingException { final ArgumentCaptor<ProcessingMessage> captor = ArgumentCaptor.forClass(ProcessingMessage.class); verify(report).error(captor.capture()); final ProcessingMessage message = captor.getValue(); final ObjectNode reports = FACTORY.objectNode(); final ArrayNode oneReport = FACTORY.arrayNode(); reports.put(ptr1.toString(), oneReport); reports.put(ptr2.toString(), oneReport); assertMessage(message) .isValidationError(keyword, BUNDLE.printf("err.draftv3.disallow.schema", 2, 2)) .hasField("matched", 2).hasField("nrSchemas", 2) .hasField("reports", reports); }
public Iterable<JsonPointer> selectSchemas(final String memberName) { final List<JsonPointer> list = Lists.newArrayList(); if (properties.contains(memberName)) list.add(PROPERTIES.append(memberName)); for (final String regex: patternProperties) if (RhinoHelper.regMatch(regex, memberName)) list.add(PATTERNPROPERTIES.append(regex)); if (!list.isEmpty()) return ImmutableList.copyOf(list); return hasAdditional ? ImmutableList.of(ADDITIONALPROPERTIES) : Collections.<JsonPointer>emptyList(); } }
@DataProvider public Iterator<Object[]> testData() throws ProcessingException, JsonPointerException { final List<Object[]> list = Lists.newArrayList(); JsonNode digest; int elementIndex; List<JsonPointer> ret; for (final JsonNode node: testNode) { digest = node.get("digest"); elementIndex = node.get("elementIndex").intValue(); ret = Lists.newArrayList(); for (final JsonNode element: node.get("ret")) ret.add(new JsonPointer(element.textValue())); list.add(new Object[]{ digest, elementIndex, ret }); } return list.iterator(); }
private ProcessingMessage validationLoopMessage(final FullData input) { final ArrayNode node = JacksonUtils.nodeFactory().arrayNode(); for (final SchemaURI uri: schemaURIs) node.add(uri.toString()); return input.newMessage() .put("domain", "validation") .setMessage(errmsg) .putArgument("alreadyVisited", new SchemaURI(input.getSchema())) .putArgument("instancePointer", pointer.toString()) .put("validationPath", node); } }
@Override public void validate(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final String value = data.getInstance().getNode().textValue(); try { new JsonPointer(value); } catch (JsonPointerException ignored) { report.error(newMsg(data, bundle, "err.format.jsonpointer.invalid") .putArgument("value", value)); } } }
@Override public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final SchemaTree tree = data.getSchema(); final JsonNode node = tree.getNode().get(keyword); FullData newData; if (node.isObject()) { newData = data.withSchema(tree.append(JsonPointer.of(keyword))); processor.process(report, newData); return; } /* * Not an object? An array */ final int size = node.size(); JsonPointer pointer; for (int index = 0; index < size; index++) { pointer = JsonPointer.of(keyword, index); newData = data.withSchema(tree.append(pointer)); processor.process(report, newData); } }