Skip to content

Commit dd83cb3

Browse files
committed
simplify instance, remove context
1 parent 958df63 commit dd83cb3

13 files changed

Lines changed: 21 additions & 95 deletions

File tree

json-schema-validator/src/main/java/io/openapiprocessor/jsonschema/schema/JsonInstance.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,19 @@
1515
import java.util.Map;
1616

1717
public class JsonInstance {
18-
@Deprecated
19-
private final JsonInstanceContext context;
20-
2118
private final @Nullable Object value;
2219
private final JsonPointer location;
2320

24-
public JsonInstance (@Nullable Object value, JsonInstanceContext context) {
25-
this.context = context;
21+
public JsonInstance (@Nullable Object value) {
2622
this.value = value;
2723
this.location = JsonPointer.EMPTY;
2824
}
2925

30-
public JsonInstance (JsonPointer location, @Nullable Object value, JsonInstanceContext context) {
31-
this.context = context;
26+
public JsonInstance (JsonPointer location, @Nullable Object value) {
3227
this.value = value;
3328
this.location = location;
3429
}
3530

36-
public Scope getScope () {
37-
return context.getScope ();
38-
}
39-
4031
public JsonPointer getLocation () {
4132
return location;
4233
}
@@ -52,22 +43,19 @@ public String getPath () {
5243
public JsonInstance getPropertyName (String propertyName) {
5344
return new JsonInstance (
5445
location.append (propertyName),
55-
getPropertyKey (propertyName),
56-
context);
46+
getPropertyKey (propertyName));
5747
}
5848

5949
public JsonInstance getValue (String property) {
6050
return new JsonInstance (
6151
location.append (property),
62-
getPropertyValue (property),
63-
context);
52+
getPropertyValue (property));
6453
}
6554

6655
public JsonInstance getValue (int idx) {
6756
return new JsonInstance (
6857
location.append (idx),
69-
getArrayValue (idx),
70-
context);
58+
getArrayValue (idx));
7159
}
7260

7361
public int getArraySize () {
@@ -120,11 +108,7 @@ public boolean isEqual (JsonInstance other) {
120108

121109
@Override
122110
public String toString () {
123-
String location = this.location.toString ();
124-
if (location == null) {
125-
return String.format ("%s", context.getScope ());
126-
}
127-
return String.format ("%s", this.location);
111+
return String.format ("%s", this.location != null ? this.location : "/");
128112
}
129113

130114
private @Nullable String getPropertyKey (String property) {

json-schema-validator/src/main/java/io/openapiprocessor/jsonschema/schema/JsonSchemaObject.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,11 @@ public Collection<JsonInstance> getEnum () {
383383
else if (raw instanceof Collection) {
384384
List<JsonInstance> instances = new ArrayList<> ();
385385

386+
int index = 0;
386387
for (Object o : Types.asCol (raw)) {
387-
Scope scope = context.getScope ().move (o);
388-
JsonInstance instance = new JsonInstance (
389-
o, new JsonInstanceContext (scope, new ReferenceRegistry ())
390-
);
391-
388+
JsonInstance instance = new JsonInstance (getLocation ().append ("enum").append (index), o);
392389
instances.add (instance);
390+
index++;
393391
}
394392

395393
return Collections.unmodifiableCollection(instances);
@@ -406,8 +404,7 @@ o, new JsonInstanceContext (scope, new ReferenceRegistry ())
406404
}
407405

408406
Object raw = schemaObject.getRawValue ("const");
409-
Scope scope = raw != null ? context.getScope ().move (raw) : context.getScope ();
410-
return new JsonInstance (raw, new JsonInstanceContext (scope, new ReferenceRegistry ()));
407+
return new JsonInstance (getLocation ().append ("const"), raw);
411408
}
412409

413410
@Override

json-schema-validator/src/main/java/io/openapiprocessor/jsonschema/validator/ValidationMessage.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ public String getSchemaPath () {
7373
return schema.getLocation ().toString ();
7474
}
7575

76-
public String getInstanceScope () {
77-
return instance.getScope ().toString ();
78-
}
79-
8076
public String getInstancePath () {
8177
return instance.getPath ();
8278
}

json-schema-validator/src/main/java/io/openapiprocessor/jsonschema/validator/result/FullResultTextBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class FullResultTextBuilder implements ResultTextBuilder {
1111

1212
@Override
1313
public String getText (ValidationMessage message) {
14-
String location = trim(lastPartOfPath(message.getInstanceScope ()), 20);
14+
String location = trim(lastPartOfPath(message.getInstancePath ()), 20);
1515

1616
String instancePath = message.getInstancePath ().length () != 0
1717
? trim (message.getInstancePath (), 40)

json-schema-validator/src/main/java/io/openapiprocessor/jsonschema/validator/result/MessageCollector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public LinkedList<Message> collect () {
2626
private void collect (Collection<ValidationMessage> messages) {
2727
for (ValidationMessage message : messages) {
2828
Message msg = new Message (
29-
message.getInstanceScope (),
29+
"",
3030
message.getInstancePath (),
3131
message.getSchemaPath (),
3232
message.getText ()
3333
);
3434

3535
if (!msg.isEmpty ()) {
36-
MessageKey key = new MessageKey (message.getInstanceScope (), message.getInstancePath ());
36+
MessageKey key = new MessageKey ("", message.getInstancePath ());
3737
Collection<Message> scopeMessages = merged.computeIfAbsent (key, k -> new LinkedList<> ());
3838
scopeMessages.add (msg);
3939
}

json-schema-validator/src/test/kotlin/io/openapiprocessor/jsonschema/validator/ValidationMessagePrinterSpec.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ class ValidationMessagePrinterSpec : StringSpec({
2323
)
2424
val schema = JsonSchemaObject(mapOf(), sctx)
2525

26-
val ictx = JsonInstanceContext(
27-
scope,
28-
ReferenceRegistry()
29-
)
30-
val instance = JsonInstance("value", ictx)
31-
26+
val instance = JsonInstance("value")
3227

3328
val printer = ValidationMessagePrinter()
3429

json-schema-validator/src/test/kotlin/io/openapiprocessor/jsonschema/validator/any/AnyOfStepSpec.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,7 @@ class AnyOfStepSpec : StringSpec({
2626
)
2727
val schema = JsonSchemaObject(mapOf(), schemaContext)
2828

29-
val instanceContext = JsonInstanceContext(
30-
Scope(
31-
emptyUri(),
32-
null,
33-
SchemaVersion.getLatest()
34-
),
35-
ReferenceRegistry()
36-
)
37-
val instance = JsonInstance("value", instanceContext)
38-
29+
val instance = JsonInstance("value")
3930

4031
"step is valid without sub step error" {
4132
val step = AnyOfStep(schema, instance)

json-schema-validator/src/test/kotlin/io/openapiprocessor/jsonschema/validator/any/NotStepSpec.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,7 @@ class NotStepSpec : StringSpec({
2626
)
2727
val schema = JsonSchemaObject(mapOf(), schemaContext)
2828

29-
val instanceContext = JsonInstanceContext(
30-
Scope(
31-
emptyUri(),
32-
null,
33-
SchemaVersion.getLatest()
34-
), ReferenceRegistry()
35-
)
36-
val instance = JsonInstance("value", instanceContext)
29+
val instance = JsonInstance("value")
3730

3831
"step is valid if sub step is not" {
3932
val step = NotStep(schema, instance)

json-schema-validator/src/test/kotlin/io/openapiprocessor/jsonschema/validator/any/OneOfStepSpec.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,7 @@ class OneOfStepSpec : StringSpec({
2424
)
2525
val schema = JsonSchemaObject(mapOf(), schemaContext)
2626

27-
val instanceContext = JsonInstanceContext(
28-
Scope(
29-
UriSupport.emptyUri(),
30-
null,
31-
SchemaVersion.getLatest()
32-
), ReferenceRegistry()
33-
)
34-
val instance = JsonInstance("value", instanceContext)
27+
val instance = JsonInstance("value")
3528

3629
"step is valid without sub step error" {
3730
val step = OneOfStep(schema, instance)

json-schema-validator/src/test/kotlin/io/openapiprocessor/jsonschema/validator/support/Draft.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,7 @@ fun draftSpec(
8989
}
9090

9191
fun createInstance(instance: Any?): JsonInstance {
92-
val scope =
93-
Scope(emptyUri(), emptyUri(), settings.version)
94-
return JsonInstance(
95-
instance,
96-
JsonInstanceContext(
97-
scope,
98-
ReferenceRegistry()
99-
)
100-
)
92+
return JsonInstance(JsonPointer.empty(), instance)
10193
}
10294

10395
Files.walk(root)

0 commit comments

Comments
 (0)