private void checkRequestBody(Overlay<Object> rbField) { if (rbField != null && rbField.isPresent() && rbField.get() instanceof String) { // TODO if this looks like it's meant to be an expression, check that it's a // valid one, and warn if not } } }
public <T extends JsonOverlay<?>> T asNullIfMissing(final T el) { boolean _isPresent = Overlay.of(((IJsonOverlay<?>) el)).isPresent(); boolean _not = (!_isPresent); if (_not) { return null; } return el; }
private void checkRequestBody(Overlay<Object> rbField) { if (rbField != null && rbField.isPresent() && rbField.get() instanceof String) { // TODO if this looks like it's meant to be an expression, check that it's a // valid one, and warn if not } } }
void checkExampleExclusion(Overlay<Map<String, Example>> examples, Overlay<Object> example) { boolean examplesPresent = examples != null && examples.isPresent() && Overlay.getMapOverlay(examples).size() > 0; boolean examplePresent = example != null && example.isPresent(); if (examplesPresent && examplePresent) { results.addError("ExmplExclusion|The 'example' and 'exmaples' properties may not both appear", value); } } }
void checkExampleExclusion(Overlay<Map<String, Example>> examples, Overlay<Object> example) { boolean examplesPresent = examples != null && examples.isPresent() && Overlay.getMapOverlay(examples).size() > 0; boolean examplePresent = example != null && example.isPresent(); if (examplesPresent && examplePresent) { results.addError("ExmplExclusion|The 'example' and 'exmaples' properties may not both appear", value); } } }
void checkExampleExclusion(Overlay<Map<String, Example>> examples, Overlay<Object> example) { boolean examplesPresent = examples != null && examples.isPresent() && Overlay.getMapOverlay(examples).size() > 0; boolean examplePresent = example != null && example.isPresent(); if (examplesPresent && examplePresent) { results.addError("ExmplExclusion|The 'example' and 'exmaples' properties may not both appear", value); } } }
void checkExampleExclusion(Overlay<Map<String, Example>> examples, Overlay<Object> example) { boolean examplesPresent = examples != null && examples.isPresent() && Overlay.getMapOverlay(examples).size() > 0; boolean examplePresent = example != null && example.isPresent(); if (examplesPresent && examplePresent) { results.addError("ExmplExclusion|The 'example' and 'exmaples' properties may not both appear", value); } } }
private void checkExactlyOneValue(Overlay<Object> valueField, Overlay<String> externalField) { boolean valuePresent = valueField != null & valueField.isPresent(); boolean externalPresent = externalField != null && externalField.isPresent(); if (valuePresent && externalPresent) { results.addError(msg(ExmplTwoValues), value); } else if (!valuePresent && !externalPresent) { // the specification doesn't actually state that a value is required, but the // object seems pointless without one, so we'll go with a warning results.addWarning(msg(ExampleNoValue), value); } } }
private void checkExactlyOneValue(Overlay<Object> valueField, Overlay<String> externalField) { boolean valuePresent = valueField != null & valueField.isPresent(); boolean externalPresent = externalField != null && externalField.isPresent(); if (valuePresent && externalPresent) { results.addError(msg(ExmplTwoValues), value); } else if (!valuePresent && !externalPresent) { // the specification doesn't actually state that a value is required, but the // object seems pointless without one, so we'll go with a warning results.addWarning(msg(ExampleNoValue), value); } } }
@SafeVarargs public final Overlay<String> validateStringField(String name, boolean required, Pattern pattern, Consumer<Overlay<String>>... otherChecks) { Overlay<String> field = validateField(name, required, String.class, null); checkMissing(field, required); if (field != null && field.isPresent()) { if (pattern != null) { checkPattern(field, pattern); } for (Consumer<Overlay<String>> otherCheck : otherChecks) { otherCheck.accept(field); } } return field; }
@SafeVarargs public final Overlay<String> validateStringField(String name, boolean required, Pattern pattern, Consumer<Overlay<String>>... otherChecks) { Overlay<String> field = validateField(name, required, String.class, null); checkMissing(field, required); if (field != null && field.isPresent()) { if (pattern != null) { checkPattern(field, pattern); } for (Consumer<Overlay<String>> otherCheck : otherChecks) { otherCheck.accept(field); } } return field; }
void checkMissing(Overlay<?> field, boolean required) { if (required && (field == null || !field.isPresent())) { results.addError(msg(MissingField, field.getPathInParent()), value); } }
void checkMissing(Overlay<?> field, boolean required) { if (required && (field == null || !field.isPresent())) { results.addError(msg(MissingField, field.getPathInParent()), value); } }
public Overlay<Number> validateNumericField(String name, boolean required, Function<Number, Boolean> test, String desc) { Overlay<Number> field = validateField(name, required, Number.class, null); checkMissing(field, required); if (field != null && field.isPresent() && test != null) { Number n = field.get(); if (!test.apply(n)) { results.addError(msg(NumberConstraint, desc, n), field); } } return field; }
private <X> void checkListNotEmpty(Overlay<List<X>> list, boolean nonEmpty) { if (nonEmpty) { ListOverlay<X> listOverlay = Overlay.getListOverlay(list); if (list != null && !list.isPresent()) { if (nonEmpty && listOverlay.size() == 0) { results.addError(msg(EmptyList), list); } } } }
public Overlay<Number> validateNumericField(String name, boolean required, Function<Number, Boolean> test, String desc) { Overlay<Number> field = validateField(name, required, Number.class, null); checkMissing(field, required); if (field != null && field.isPresent() && test != null) { Number n = field.get(); if (!test.apply(n)) { results.addError(msg(NumberConstraint, desc, n), field); } } return field; }
private <X> void checkListNotEmpty(Overlay<List<X>> list, boolean nonEmpty) { if (nonEmpty) { ListOverlay<X> listOverlay = Overlay.getListOverlay(list); if (list != null && !list.isPresent()) { if (nonEmpty && listOverlay.size() == 0) { results.addError(msg(EmptyList), list); } } } }
private <X> void checkMapNotEmpty(Overlay<Map<String, X>> list, boolean nonEmpty) { if (nonEmpty) { MapOverlay<X> mapOverlay = Overlay.getMapOverlay(list); if (list != null && !list.isPresent()) { if (nonEmpty && mapOverlay.size() == 0) { results.addError(msg(EmptyList), list); } } } }
@SafeVarargs public final <F> Overlay<F> validateField(String name, boolean required, Class<F> fieldClass, Validator<F> validator, Consumer<Overlay<F>>... otherChecks) { @SuppressWarnings("unchecked") PropertiesOverlay<V> propValue = (PropertiesOverlay<V>) value.get(); Overlay<F> field = Overlay.of(propValue, name, fieldClass); checkJsonType(field, getAllowedJsonTypes(field), results); checkMissing(field, required); if (field != null && field.isPresent() && validator != null) { validator.validate(field); for (Consumer<Overlay<F>> otherCheck : otherChecks) { otherCheck.accept(field); } } return field; }
private <X> void checkMapNotEmpty(Overlay<Map<String, X>> list, boolean nonEmpty) { if (nonEmpty) { MapOverlay<X> mapOverlay = Overlay.getMapOverlay(list); if (list != null && !list.isPresent()) { if (nonEmpty && mapOverlay.size() == 0) { results.addError(msg(EmptyList), list); } } } }