Skip to content

Commit 7805892

Browse files
committed
Refactor packages for schema features
1 parent 654f11d commit 7805892

File tree

173 files changed

+3435
-9438
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+3435
-9438
lines changed

src/main/java/com/relogiclabs/json/schema/JsonAssert.java renamed to src/main/java/com/relogiclabs/jschema/JsonAssert.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
package com.relogiclabs.json.schema;
1+
package com.relogiclabs.jschema;
22

3-
import com.relogiclabs.json.schema.internal.util.DebugUtilities;
4-
import com.relogiclabs.json.schema.tree.DataTree;
5-
import com.relogiclabs.json.schema.tree.JsonTree;
6-
import com.relogiclabs.json.schema.tree.RuntimeContext;
7-
import com.relogiclabs.json.schema.tree.SchemaTree;
8-
import com.relogiclabs.json.schema.tree.TreeType;
3+
import com.relogiclabs.jschema.internal.util.LogHelper;
4+
import com.relogiclabs.jschema.tree.DataTree;
5+
import com.relogiclabs.jschema.tree.JsonTree;
6+
import com.relogiclabs.jschema.tree.RuntimeContext;
7+
import com.relogiclabs.jschema.tree.SchemaTree;
8+
import com.relogiclabs.jschema.tree.TreeType;
99
import lombok.Getter;
1010

11-
import static com.relogiclabs.json.schema.message.MessageFormatter.JSON_ASSERTION;
12-
import static com.relogiclabs.json.schema.message.MessageFormatter.SCHEMA_ASSERTION;
13-
import static com.relogiclabs.json.schema.tree.TreeType.JSON_TREE;
14-
import static com.relogiclabs.json.schema.tree.TreeType.SCHEMA_TREE;
11+
import static com.relogiclabs.jschema.message.MessageFormatter.JSON_ASSERTION;
12+
import static com.relogiclabs.jschema.message.MessageFormatter.SCHEMA_ASSERTION;
13+
import static com.relogiclabs.jschema.tree.TreeType.JSON_TREE;
14+
import static com.relogiclabs.jschema.tree.TreeType.SCHEMA_TREE;
1515

1616
/**
1717
* The class provides assertion functionalities to validate JSON documents against
18-
* a Schema or JSON.
18+
* a JSchema or JSON document.
1919
*/
2020
@Getter
2121
public class JsonAssert {
@@ -24,19 +24,19 @@ public class JsonAssert {
2424

2525
/**
2626
* Initializes a new instance of the {@link JsonAssert} class for the
27-
* specified Schema string.
28-
* @param schema A Schema string for validation or conformation
27+
* specified JSchema string.
28+
* @param schema A JSchema string for validation or conformation
2929
*/
3030
public JsonAssert(String schema) {
3131
this(schema, SCHEMA_TREE);
3232
}
3333

3434
/**
3535
* Initializes a new instance of the {@link JsonAssert} class for the specified
36-
* {@code expected} string, which can be either a Schema or a JSON representation.
37-
* @param expected An expected Schema or JSON string for validation or conformation
36+
* {@code expected} string, which can be either a JSchema or a JSON representation.
37+
* @param expected An expected JSchema or JSON string for validation or conformation
3838
* @param type The type of string provided by {@code expected}, indicating whether it represents
39-
* a Schema or JSON. Use {@link TreeType#SCHEMA_TREE} for Schema and {@link TreeType#JSON_TREE}
39+
* a JSchema or JSON. Use {@link TreeType#SCHEMA_TREE} for JSchema and {@link TreeType#JSON_TREE}
4040
* for JSON.
4141
*/
4242
public JsonAssert(String expected, TreeType type) {
@@ -50,22 +50,22 @@ public JsonAssert(String expected, TreeType type) {
5050
}
5151

5252
/**
53-
* Tests whether the input JSON string conforms to the expected Schema or JSON
53+
* Tests whether the input JSON string conforms to the expected JSchema or JSON
5454
* specified in the {@link JsonAssert} constructor.
5555
* @param json The actual input JSON to conform or validate
5656
*/
5757
public void isValid(String json) {
5858
runtime.clear();
5959
var jsonTree = new JsonTree(runtime, json);
60-
DebugUtilities.print(expectedTree, jsonTree);
60+
LogHelper.debug(expectedTree, jsonTree);
6161
if(!expectedTree.match(jsonTree))
6262
throw new IllegalStateException("Invalid runtime state");
6363
}
6464

6565
/**
66-
* Tests whether the specified JSON string conforms to the given Schema string
67-
* and throws an exception if the JSON string does not conform to the Schema.
68-
* @param schema The expected Schema to conform or validate
66+
* Tests whether the specified JSON string conforms to the given JSchema string
67+
* and throws an exception if the JSON string does not conform to the JSchema.
68+
* @param schema The expected JSchema to conform or validate
6969
* @param json The actual JSON to conform or validate
7070
*/
7171
public static void isValid(String schema, String json) {

src/main/java/com/relogiclabs/json/schema/JsonSchema.java renamed to src/main/java/com/relogiclabs/jschema/JsonSchema.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
package com.relogiclabs.json.schema;
1+
package com.relogiclabs.jschema;
22

3-
import com.relogiclabs.json.schema.internal.util.DebugUtilities;
4-
import com.relogiclabs.json.schema.tree.ExceptionRegistry;
5-
import com.relogiclabs.json.schema.tree.JsonTree;
6-
import com.relogiclabs.json.schema.tree.RuntimeContext;
7-
import com.relogiclabs.json.schema.tree.SchemaTree;
3+
import com.relogiclabs.jschema.internal.util.LogHelper;
4+
import com.relogiclabs.jschema.tree.ExceptionRegistry;
5+
import com.relogiclabs.jschema.tree.JsonTree;
6+
import com.relogiclabs.jschema.tree.RuntimeContext;
7+
import com.relogiclabs.jschema.tree.SchemaTree;
88
import lombok.Getter;
99

10-
import static com.relogiclabs.json.schema.message.MessageFormatter.SCHEMA_VALIDATION;
10+
import static com.relogiclabs.jschema.message.MessageFormatter.SCHEMA_VALIDATION;
1111

1212
/**
13-
* {@code JsonSchema} provides Schema validation functionalities for JSON document.
13+
* {@code JsonSchema} provides JSchema validation functionalities for JSON document.
1414
*/
1515
@Getter
1616
public class JsonSchema {
@@ -20,8 +20,8 @@ public class JsonSchema {
2020

2121
/**
2222
* Initializes a new instance of the {@link JsonSchema} class for the
23-
* specified Schema string.
24-
* @param schema A Schema string for validation
23+
* specified JSchema string.
24+
* @param schema A JSchema string for validation
2525
*/
2626
public JsonSchema(String schema) {
2727
runtime = new RuntimeContext(SCHEMA_VALIDATION, false);
@@ -30,32 +30,35 @@ public JsonSchema(String schema) {
3030
}
3131

3232
/**
33-
* Indicates whether the input JSON string conforms to the Schema specified
33+
* Indicates whether the input JSON string conforms to the JSchema specified
3434
* in the {@link JsonSchema} constructor.
35-
* @param json The JSON to validate with Schema
36-
* @return Returns {@code true} if the JSON string conforms to the Schema and {@code false} otherwise.
35+
* @param json The JSON to validate with JSchema
36+
* @return Returns {@code true} if the JSON string conforms to the JSchema and {@code false} otherwise.
3737
*/
3838
public boolean isValid(String json) {
3939
runtime.clear();
4040
var jsonTree = new JsonTree(runtime, json);
41-
DebugUtilities.print(schemaTree, jsonTree);
41+
LogHelper.debug(schemaTree, jsonTree);
4242
return schemaTree.match(jsonTree);
4343
}
4444

4545
/**
46-
* Writes error messages that occur during Schema validation process, to the
46+
* Writes error messages that occur during JSchema validation process, to the
4747
* standard error output stream.
4848
*/
4949
public void writeError() {
50-
for(var exception : exceptions)
51-
System.err.println(exception.getMessage());
50+
if(exceptions.getCount() == 0) {
51+
System.out.println("No error has occurred");
52+
return;
53+
}
54+
for(var exception : exceptions) System.err.println(exception.getMessage());
5255
}
5356

5457
/**
55-
* Indicates whether the input JSON string conforms to the given Schema string.
56-
* @param schema The Schema string to conform or validate
58+
* Indicates whether the input JSON string conforms to the given JSchema string.
59+
* @param schema The JSchema string to conform or validate
5760
* @param json The JSON string to conform or validate
58-
* @return Returns {@code true} if the JSON string conforms to the Schema and {@code false} otherwise.
61+
* @return Returns {@code true} if the JSON string conforms to the JSchema and {@code false} otherwise.
5962
*/
6063
public static boolean isValid(String schema, String json) {
6164
var jsonSchema = new JsonSchema(schema);

src/main/java/com/relogiclabs/json/schema/collection/IndexMap.java renamed to src/main/java/com/relogiclabs/jschema/collection/IndexMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.relogiclabs.json.schema.collection;
1+
package com.relogiclabs.jschema.collection;
22

33
import java.util.Collection;
44
import java.util.Set;

src/main/java/com/relogiclabs/json/schema/collection/Keyable.java renamed to src/main/java/com/relogiclabs/jschema/collection/Keyable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.relogiclabs.json.schema.collection;
1+
package com.relogiclabs.jschema.collection;
22

33
public interface Keyable<TK> {
44
TK getKey();

src/main/java/com/relogiclabs/jschema/function/CoreFunctions1.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public boolean length(JString target, JInteger length) {
3636
var rLength = target.length();
3737
if(rLength != length.getValue()) return fail(new JsonSchemaException(
3838
new ErrorDetail(SLEN01, "Invalid length of string ", target),
39-
new ExpectedDetail(function, "a string of length ", length),
39+
new ExpectedDetail(caller, "a string of length ", length),
4040
new ActualDetail(target, "found ", rLength, " which does not match")));
4141
return true;
4242
}
@@ -45,7 +45,7 @@ public boolean length(JArray target, JInteger length) {
4545
var rLength = target.getElements().size();
4646
if(rLength != length.getValue()) return fail(new JsonSchemaException(
4747
new ErrorDetail(ALEN01, "Invalid length of array ", target.getOutline()),
48-
new ExpectedDetail(function, "an array of length ", length),
48+
new ExpectedDetail(caller, "an array of length ", length),
4949
new ActualDetail(target, "found ", rLength, " which does not match")));
5050
return true;
5151
}
@@ -54,7 +54,7 @@ public boolean length(JObject target, JInteger length) {
5454
var rLength = target.getProperties().size();
5555
if(rLength != length.getValue()) return fail(new JsonSchemaException(
5656
new ErrorDetail(OLEN01, "Invalid size or length of object ", target.getOutline()),
57-
new ExpectedDetail(function, "an object of length ", length),
57+
new ExpectedDetail(caller, "an object of length ", length),
5858
new ActualDetail(target, "found ", rLength, " which does not match")));
5959
return true;
6060
}
@@ -64,12 +64,12 @@ public boolean length(JString target, JInteger minimum, JInteger maximum) {
6464
if(length < minimum.getValue())
6565
return fail(new JsonSchemaException(new ErrorDetail(SLEN02,
6666
"String ", target.getOutline(), " length is outside of range"),
67-
new ExpectedDetail(function, "length in range [", minimum, ", ", maximum, "]"),
67+
new ExpectedDetail(caller, "length in range [", minimum, ", ", maximum, "]"),
6868
new ActualDetail(target, "found ", length, " that is less than ", minimum)));
6969
if(length > maximum.getValue())
7070
return fail(new JsonSchemaException(new ErrorDetail(SLEN03,
7171
"String ", target.getOutline(), " length is outside of range"),
72-
new ExpectedDetail(function, "length in range [", minimum, ", ", maximum, "]"),
72+
new ExpectedDetail(caller, "length in range [", minimum, ", ", maximum, "]"),
7373
new ActualDetail(target, "found ", length, " that is greater than ", maximum)));
7474
return true;
7575
}
@@ -79,7 +79,7 @@ public boolean length(JString target, JInteger minimum, JUndefined undefined) {
7979
if(length < minimum.getValue())
8080
return fail(new JsonSchemaException(new ErrorDetail(SLEN04,
8181
"String ", target.getOutline(), " length is outside of range"),
82-
new ExpectedDetail(function, "length in range [", minimum, ", ", undefined, "]"),
82+
new ExpectedDetail(caller, "length in range [", minimum, ", ", undefined, "]"),
8383
new ActualDetail(target, "found ", length, " that is less than ", minimum)));
8484
return true;
8585
}
@@ -89,7 +89,7 @@ public boolean length(JString target, JUndefined undefined, JInteger maximum) {
8989
if(length > maximum.getValue())
9090
return fail(new JsonSchemaException(new ErrorDetail(SLEN05,
9191
"String ", target.getOutline(), " length is outside of range"),
92-
new ExpectedDetail(function, "length in range [", undefined, ", ", maximum, "]"),
92+
new ExpectedDetail(caller, "length in range [", undefined, ", ", maximum, "]"),
9393
new ActualDetail(target, "found ", length, " that is greater than ", maximum)));
9494
return true;
9595
}
@@ -99,12 +99,12 @@ public boolean length(JArray target, JInteger minimum, JInteger maximum) {
9999
if(length < minimum.getValue())
100100
return fail(new JsonSchemaException(new ErrorDetail(ALEN02,
101101
"Array ", target.getOutline(), " length is outside of range"),
102-
new ExpectedDetail(function, "length in range [", minimum, ", ", maximum, "]"),
102+
new ExpectedDetail(caller, "length in range [", minimum, ", ", maximum, "]"),
103103
new ActualDetail(target, "found ", length, " that is less than ", minimum)));
104104
if(length > maximum.getValue())
105105
return fail(new JsonSchemaException(new ErrorDetail(ALEN03,
106106
"Array ", target.getOutline(), " length is outside of range"),
107-
new ExpectedDetail(function, "length in range [", minimum, ", ", maximum, "]"),
107+
new ExpectedDetail(caller, "length in range [", minimum, ", ", maximum, "]"),
108108
new ActualDetail(target, "found ", length, " that is greater than ", maximum)));
109109
return true;
110110
}
@@ -114,7 +114,7 @@ public boolean length(JArray target, JInteger minimum, JUndefined undefined) {
114114
if(length < minimum.getValue())
115115
return fail(new JsonSchemaException(new ErrorDetail(ALEN04,
116116
"Array ", target.getOutline(), " length is outside of range"),
117-
new ExpectedDetail(function, "length in range [", minimum, ", ", undefined, "]"),
117+
new ExpectedDetail(caller, "length in range [", minimum, ", ", undefined, "]"),
118118
new ActualDetail(target, "found ", length, " that is less than ", minimum)));
119119
return true;
120120
}
@@ -124,7 +124,7 @@ public boolean length(JArray target, JUndefined undefined, JInteger maximum) {
124124
if(length > maximum.getValue())
125125
return fail(new JsonSchemaException(new ErrorDetail(ALEN05,
126126
"Array ", target.getOutline(), " length is outside of range"),
127-
new ExpectedDetail(function, "length in range [", undefined, ", ", maximum, "]"),
127+
new ExpectedDetail(caller, "length in range [", undefined, ", ", maximum, "]"),
128128
new ActualDetail(target, "found ", length, " that is greater than ", maximum)));
129129
return true;
130130
}
@@ -134,12 +134,12 @@ public boolean length(JObject target, JInteger minimum, JInteger maximum) {
134134
if(length < minimum.getValue())
135135
return fail(new JsonSchemaException(new ErrorDetail(OLEN02,
136136
"Object ", target.getOutline(), " size or length is outside of range"),
137-
new ExpectedDetail(function, "length in range [", minimum, ", ", maximum, "]"),
137+
new ExpectedDetail(caller, "length in range [", minimum, ", ", maximum, "]"),
138138
new ActualDetail(target, "found ", length, " that is less than ", minimum)));
139139
if(length > maximum.getValue())
140140
return fail(new JsonSchemaException(new ErrorDetail(OLEN03,
141141
"Object ", target.getOutline(), " size or length is outside of range"),
142-
new ExpectedDetail(function, "length in range [", minimum, ", ", maximum, "]"),
142+
new ExpectedDetail(caller, "length in range [", minimum, ", ", maximum, "]"),
143143
new ActualDetail(target, "found ", length, " that is greater than ", maximum)));
144144
return true;
145145
}
@@ -149,7 +149,7 @@ public boolean length(JObject target, JInteger minimum, JUndefined undefined) {
149149
if(length < minimum.getValue())
150150
return fail(new JsonSchemaException(new ErrorDetail(OLEN04,
151151
"Object ", target.getOutline(), " size or length is outside of range"),
152-
new ExpectedDetail(function, "length in range [", minimum, ", ", undefined, "]"),
152+
new ExpectedDetail(caller, "length in range [", minimum, ", ", undefined, "]"),
153153
new ActualDetail(target, "found ", length, " that is less than ", minimum)));
154154
return true;
155155
}
@@ -159,7 +159,7 @@ public boolean length(JObject target, JUndefined undefined, JInteger maximum) {
159159
if(length > maximum.getValue())
160160
return fail(new JsonSchemaException(new ErrorDetail(OLEN05,
161161
"Object ", target.getOutline(), " size or length is outside of range"),
162-
new ExpectedDetail(function, "length in range [", undefined, ", ", maximum, "]"),
162+
new ExpectedDetail(caller, "length in range [", undefined, ", ", maximum, "]"),
163163
new ActualDetail(target, "found ", length, " that is greater than ", maximum)));
164164
return true;
165165
}

0 commit comments

Comments
 (0)