Skip to content

Commit

Permalink
0.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
redmitry committed Aug 22, 2024
1 parent 9588194 commit aaadc5d
Show file tree
Hide file tree
Showing 29 changed files with 153 additions and 168 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>es.elixir.bsc.json.schema</groupId>
<artifactId>jaronuinga</artifactId>
<version>0.5.3</version>
<version>0.5.4</version>
<packaging>jar</packaging>

<organization>
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/es/elixir/bsc/json/schema/ValidationError.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* *****************************************************************************
* Copyright (C) 2022 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* Copyright (C) 2024 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* and Barcelona Supercomputing Center (BSC)
*
* Modifications to the initial code base are copyright of their respective
Expand Down Expand Up @@ -39,16 +39,15 @@ public class ValidationError {
public final String path;
public final String message;

public ValidationError(final String message) {
public ValidationError(String message) {
this(null, null, null, message);
}

public ValidationError(final URI id, final String pointer, final String message) {
public ValidationError(URI id, String pointer, String message) {
this(id, pointer, null, message);
}

public ValidationError(final URI id, final String pointer,
final String path, final String message) {
public ValidationError(URI id, String pointer, String path, String message) {

this.code = -1;
this.id = id;
Expand All @@ -57,8 +56,8 @@ public ValidationError(final URI id, final String pointer,
this.message = message;
}

public ValidationError(final URI id, final String pointer,
final String path, final ValidationMessage message, Object... args) {
public ValidationError(URI id, String pointer, String path,
ValidationMessage message, Object... args) {

this.code = message.CODE;
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* *****************************************************************************
* Copyright (C) 2023 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* Copyright (C) 2024 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* and Barcelona Supercomputing Center (BSC)
*
* Modifications to the initial code base are copyright of their respective
Expand Down Expand Up @@ -97,7 +97,7 @@ public enum ValidationMessage {
public final int CODE;
public final String VALUE;

private ValidationMessage(final int code, final String value) {
private ValidationMessage(int code, String value) {
CODE = code;
VALUE = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import es.elixir.bsc.json.schema.model.impl.JsonReferenceImpl;
import es.elixir.bsc.json.schema.model.impl.AbstractJsonSchemaElement;
import es.elixir.bsc.json.schema.model.impl.JsonMultitypeSchemaWrapper;
import java.io.IOException;
import java.util.Map;
import javax.json.JsonArray;
import javax.json.JsonObject;
Expand Down Expand Up @@ -83,7 +84,7 @@ public AbstractJsonSchema parse(JsonSchemaLocator locator, AbstractJsonSchemaEle

if (value.getValueType() == ValueType.TRUE ||
value.getValueType() == ValueType.FALSE) {
return new BooleanJsonSchemaImpl(parent, locator, jsonPointer).read(this, value, type);
return new BooleanJsonSchemaImpl(parent, locator, jsonPointer).read(this, value);
}

if (value.getValueType() != ValueType.OBJECT) {
Expand All @@ -101,21 +102,21 @@ public AbstractJsonSchema parse(JsonSchemaLocator locator, AbstractJsonSchemaEle
}

// before draft 2019-09 $ref ignored any other properties
if (JsonSchemaVersion.SCHEMA_DRAFT_2019_09.compareTo(getJsonSchemaVersion(object)) > 0) {
return new JsonReferenceImpl(parent, locator, jsonPointer).read(this, object, null);
if (JsonSchemaVersion.SCHEMA_DRAFT_2019_09.compareTo(getJsonSchemaVersion(locator)) > 0) {
return new JsonReferenceImpl(parent, locator, jsonPointer).read(this, object);
}
}

final JsonValue type_value = object.get(TYPE);
final ValueType vtype;
if (type_value == null) {
vtype = null;
} else {
} else {
vtype = type_value.getValueType();
switch(vtype) {
case STRING:
try {
type = JsonType.fromValue(((JsonString)type_value).getString());
type = JsonType.fromValue(((JsonString)type_value).getString());
} catch(IllegalArgumentException ex) {
throw new JsonSchemaException(new ParsingError(
ParsingMessage.UNKNOWN_OBJECT_TYPE, ((JsonString)type_value).getString()));
Expand All @@ -134,43 +135,49 @@ public AbstractJsonSchema parse(JsonSchemaLocator locator, AbstractJsonSchemaEle
if (jenum.isEmpty()) {
throw new JsonSchemaException(new ParsingError(ParsingMessage.EMPTY_ENUM));
}
return new JsonEnumImpl(parent, locator, jsonPointer).read(this, object, type);
return new JsonEnumImpl(parent, locator, jsonPointer).read(this, object);
}

final JsonValue jconst = object.get(CONST);
if (jconst != null) {
return new JsonConstImpl(parent, locator, jsonPointer).read(this, object, type);
return new JsonConstImpl(parent, locator, jsonPointer).read(this, object);
}

if (type == null) {
return new JsonMultitypeSchemaWrapper(parent, locator, jsonPointer,
vtype == ValueType.ARRAY ? type_value.asJsonArray() : null)
.read(this, object, null);
.read(this, object);
}

final AbstractJsonSchema schema;
switch(type) {
case OBJECT: schema = new JsonObjectSchemaImpl(parent, locator, jsonPointer).read(this, object, type); break;
case ARRAY: schema = new JsonArraySchemaImpl(parent, locator, jsonPointer).read(this, object, type); break;
case STRING: schema = new JsonStringSchemaImpl(parent, locator, jsonPointer).read(this, object, type); break;
case NUMBER: schema = new JsonNumberSchemaImpl(parent, locator, jsonPointer).read(this, object, type); break;
case INTEGER: schema = new JsonIntegerSchemaImpl(parent, locator, jsonPointer).read(this, object, type); break;
case BOOLEAN: schema = new JsonBooleanSchemaImpl(parent, locator, jsonPointer).read(this, object, type); break;
case NULL: schema = new JsonNullSchemaImpl(parent, locator, jsonPointer).read(this, object, type); break;
case OBJECT: schema = new JsonObjectSchemaImpl(parent, locator, jsonPointer).read(this, object); break;
case ARRAY: schema = new JsonArraySchemaImpl(parent, locator, jsonPointer).read(this, object); break;
case STRING: schema = new JsonStringSchemaImpl(parent, locator, jsonPointer).read(this, object); break;
case NUMBER: schema = new JsonNumberSchemaImpl(parent, locator, jsonPointer).read(this, object); break;
case INTEGER: schema = new JsonIntegerSchemaImpl(parent, locator, jsonPointer).read(this, object); break;
case BOOLEAN: schema = new JsonBooleanSchemaImpl(parent, locator, jsonPointer).read(this, object); break;
case NULL: schema = new JsonNullSchemaImpl(parent, locator, jsonPointer).read(this, object); break;
default: return null;
}

return schema;
}

@Override
public JsonSchemaVersion getJsonSchemaVersion(JsonObject object) {
final JsonValue jversion = object.get(JsonSchema.SCHEMA);
if (jversion != null && jversion.getValueType() == JsonValue.ValueType.STRING) {
try {
return JsonSchemaVersion.fromValue(((JsonString)jversion).getString());
} catch(IllegalArgumentException ex) {}
}
public JsonSchemaVersion getJsonSchemaVersion(JsonSchemaLocator locator) {
final JsonValue schema;
try {
schema = locator.getSchema("/");
if (JsonValue.ValueType.OBJECT == schema.getValueType()) {
final JsonValue jversion = schema.asJsonObject().get(JsonSchema.SCHEMA);
if (jversion != null && jversion.getValueType() == JsonValue.ValueType.STRING) {
try {
return JsonSchemaVersion.fromValue(((JsonString)jversion).getString());
} catch(IllegalArgumentException ex) {}
}
}
} catch (IOException ex) {}

final Object version = properties.get(JsonSchemaParserConfig.JSON_SCHEMA_VERSION);
if (version instanceof JsonSchemaVersion) {
Expand All @@ -179,4 +186,5 @@ public JsonSchemaVersion getJsonSchemaVersion(JsonObject object) {

return JsonSchemaVersion.SCHEMA_DRAFT_07; // default
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* *****************************************************************************
* Copyright (C) 2022 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* Copyright (C) 2024 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* and Barcelona Supercomputing Center (BSC)
*
* Modifications to the initial code base are copyright of their respective
Expand Down Expand Up @@ -45,9 +45,8 @@ public class DefaultJsonStringFormatValidator implements JsonStringFormatValidat
private final static Pattern IP4_PATTERN = Pattern.compile("^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$");
private final static Pattern IP6_PATTERN = Pattern.compile("^((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4}))*::((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4}))*|((?:[0-9A-Fa-f]{1,4}))((?::[0-9A-Fa-f]{1,4})){7}$");

public static void validate(final String jsonPointer,
final JsonStringSchema schema,
final String value) throws ValidationException {
public static void validate(String jsonPointer, JsonStringSchema schema,
String value) throws ValidationException {

final String format = schema.getFormat();
switch(format) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* *****************************************************************************
* Copyright (C) 2023 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* Copyright (C) 2024 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* and Barcelona Supercomputing Center (BSC)
*
* Modifications to the initial code base are copyright of their respective
Expand Down Expand Up @@ -33,7 +33,6 @@
import es.elixir.bsc.json.schema.model.impl.AbstractJsonSchema;
import es.elixir.bsc.json.schema.model.impl.AbstractJsonSchemaElement;
import java.util.Map;
import javax.json.JsonObject;
import javax.json.JsonValue;

/**
Expand All @@ -56,7 +55,7 @@ public interface JsonSubschemaParser extends JsonSchemaParser {
*/
Map<String, Object> getJsonSchemaParserProperties();

JsonSchemaVersion getJsonSchemaVersion(JsonObject object);
JsonSchemaVersion getJsonSchemaVersion(JsonSchemaLocator locator);

@Override
default AbstractJsonSchema parse(JsonSchemaLocator locator, JsonValue schema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import es.elixir.bsc.json.schema.impl.JsonSubschemaParser;
import es.elixir.bsc.json.schema.model.JsonReference;
import es.elixir.bsc.json.schema.model.JsonSchemaElement;
import es.elixir.bsc.json.schema.model.JsonType;
import javax.json.JsonException;
import java.util.List;
import javax.json.JsonObject;
Expand All @@ -62,8 +61,8 @@ public AbstractJsonReferenceImpl(AbstractJsonSchemaElement parent, JsonSchemaLoc
super(parent, locator, jsonPointer);
}

protected void read(JsonSubschemaParser parser, JsonObject object,
JsonType type, String tag) throws JsonSchemaException {
protected void read(JsonSubschemaParser parser, JsonObject object, String tag)
throws JsonSchemaException {

this.parser = parser;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* *****************************************************************************
* Copyright (C) 2023 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* Copyright (C) 2024 ELIXIR ES, Spanish National Bioinformatics Institute (INB)
* and Barcelona Supercomputing Center (BSC)
*
* Modifications to the initial code base are copyright of their respective
Expand Down Expand Up @@ -32,7 +32,6 @@
import es.elixir.bsc.json.schema.ValidationException;
import es.elixir.bsc.json.schema.impl.JsonSubschemaParser;
import es.elixir.bsc.json.schema.model.JsonSchema;
import es.elixir.bsc.json.schema.model.JsonType;
import java.util.ArrayList;
import java.util.List;
import javax.json.JsonValue;
Expand All @@ -54,8 +53,8 @@ public AbstractJsonSchema(AbstractJsonSchemaElement parent, JsonSchemaLocator lo
super(parent, locator, jsonPointer);
}

public AbstractJsonSchema<T> read(JsonSubschemaParser parser, T value,
JsonType type) throws JsonSchemaException {
public AbstractJsonSchema<T> read(JsonSubschemaParser parser, T value)
throws JsonSchemaException {
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import es.elixir.bsc.json.schema.impl.JsonSubschemaParser;
import es.elixir.bsc.json.schema.model.BooleanJsonSchema;
import es.elixir.bsc.json.schema.model.JsonSchemaElement;
import es.elixir.bsc.json.schema.model.JsonType;
import javax.json.JsonValue;
import javax.json.JsonValue.ValueType;
import java.util.List;
Expand All @@ -62,9 +61,8 @@ public Stream<JsonSchemaElement> getChildren() {
}

@Override
public BooleanJsonSchemaImpl read(final JsonSubschemaParser parser,
final JsonValue schema,
final JsonType type) throws JsonSchemaException {
public BooleanJsonSchemaImpl read(JsonSubschemaParser parser, JsonValue schema)
throws JsonSchemaException {

if (schema.getValueType() != ValueType.TRUE &&
schema.getValueType() != ValueType.FALSE) {
Expand All @@ -78,7 +76,10 @@ public BooleanJsonSchemaImpl read(final JsonSubschemaParser parser,
}

@Override
public boolean validate(String jsonPointer, JsonValue value, JsonValue parent, List evaluated, List<ValidationError> errors, JsonSchemaValidationCallback<JsonValue> callback) throws ValidationException {
public boolean validate(String jsonPointer, JsonValue value, JsonValue parent,
List evaluated, List<ValidationError> errors, JsonSchemaValidationCallback<JsonValue> callback)
throws ValidationException {

if (!evaluation) {
errors.add(new ValidationError(getId(), getJsonPointer(), jsonPointer,
ValidationMessage.UNEVALUATED_BOOLEAN_SCHEMA_MSG));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.List;
import es.elixir.bsc.json.schema.JsonSchemaValidationCallback;
import es.elixir.bsc.json.schema.impl.JsonSubschemaParser;
import es.elixir.bsc.json.schema.model.JsonType;
import javax.json.JsonValue;
import java.util.ArrayList;
import javax.json.JsonArray;
Expand All @@ -51,11 +50,10 @@ public JsonAllOfImpl(AbstractJsonSchema parent, JsonSchemaLocator locator,
}

@Override
public JsonAllOfImpl read(final JsonSubschemaParser parser,
final JsonArray schema,
final JsonType type) throws JsonSchemaException {
public JsonAllOfImpl read(JsonSubschemaParser parser, JsonArray schema)
throws JsonSchemaException {

super.read(parser, schema, type);
super.read(parser, schema);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import es.elixir.bsc.json.schema.JsonSchemaValidationCallback;
import es.elixir.bsc.json.schema.ValidationException;
import es.elixir.bsc.json.schema.impl.JsonSubschemaParser;
import es.elixir.bsc.json.schema.model.JsonType;
import javax.json.JsonValue;

/**
Expand All @@ -53,10 +52,10 @@ public JsonAnyOfImpl(AbstractJsonSchemaElement parent, JsonSchemaLocator locator
}

@Override
public JsonAnyOfImpl read(final JsonSubschemaParser parser,
final T value,
final JsonType type) throws JsonSchemaException {
super.read(parser, value, type);
public JsonAnyOfImpl read(JsonSubschemaParser parser, T value)
throws JsonSchemaException {

super.read(parser, value);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import es.elixir.bsc.json.schema.JsonSchemaValidationCallback;
import es.elixir.bsc.json.schema.ParsingError;
import es.elixir.bsc.json.schema.ParsingMessage;
import es.elixir.bsc.json.schema.model.JsonType;
import java.util.ArrayList;
import java.util.List;
import es.elixir.bsc.json.schema.impl.JsonSubschemaParser;
Expand Down Expand Up @@ -148,11 +147,10 @@ public Long getMaxContains() {
}

@Override
public JsonArraySchemaImpl read(final JsonSubschemaParser parser,
final JsonObject object,
final JsonType type) throws JsonSchemaException {
public JsonArraySchemaImpl read(JsonSubschemaParser parser, JsonObject object)
throws JsonSchemaException {

super.read(parser, object, type);
super.read(parser, object);

final JsonNumber min = JsonSchemaUtil.check(object.getJsonNumber(MIN_ITEMS), JsonValue.ValueType.NUMBER);
if (min != null) {
Expand Down
Loading

0 comments on commit aaadc5d

Please sign in to comment.