You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@johnzon.apache.org by GitBox <gi...@apache.org> on 2020/12/02 16:41:55 UTC

[GitHub] [johnzon] manuelrazola commented on a change in pull request #72: Json Schema Validation: added integer type validation.

manuelrazola commented on a change in pull request #72:
URL: https://github.com/apache/johnzon/pull/72#discussion_r534315786



##########
File path: johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/spi/builtin/IntegerValidation.java
##########
@@ -0,0 +1,50 @@
+package org.apache.johnzon.jsonschema.spi.builtin;
+
+import java.util.Optional;
+import java.util.function.Function;
+import java.util.stream.Stream;
+
+import javax.json.JsonNumber;
+import javax.json.JsonString;
+import javax.json.JsonValue;
+
+import org.apache.johnzon.jsonschema.ValidationResult;
+import org.apache.johnzon.jsonschema.ValidationResult.ValidationError;
+import org.apache.johnzon.jsonschema.spi.ValidationContext;
+import org.apache.johnzon.jsonschema.spi.ValidationExtension;
+
+public class IntegerValidation implements ValidationExtension {
+
+	@Override
+	public Optional<Function<JsonValue, Stream<ValidationError>>> create(ValidationContext model) {
+		final JsonValue type = model.getSchema().get("type");
+		if (JsonString.class.isInstance(type) && "integer".equals(JsonString.class.cast(type).getString())) {
+			return Optional.of(new Impl(model.toPointer(), model.getValueProvider()));
+		}
+		return Optional.empty();
+	}
+
+	private static class Impl extends BaseValidation {
+
+		private Impl(final String pointer, final Function<JsonValue, JsonValue> valueProvider) {
+			super(pointer, valueProvider, JsonValue.ValueType.NUMBER);
+		}
+
+		@Override
+		protected Stream<ValidationError> onNumber(JsonNumber number) {
+			final double value = number.doubleValue();

Review comment:
       Possibly, will test how it would look like and come back tomorrow ;)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org