Skip to content

Commit ae3f0c8

Browse files
committed
Create reference resolver per validation invocation
1 parent a8ed436 commit ae3f0c8

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/JsonSchema.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package io.github.optimumcode.json.schema
33
import io.github.optimumcode.json.pointer.JsonPointer
44
import io.github.optimumcode.json.schema.OutputCollector.DelegateOutputCollector
55
import io.github.optimumcode.json.schema.internal.DefaultAssertionContext
6-
import io.github.optimumcode.json.schema.internal.DefaultReferenceResolver
6+
import io.github.optimumcode.json.schema.internal.DefaultReferenceResolverProvider
77
import io.github.optimumcode.json.schema.internal.IsolatedLoader
88
import io.github.optimumcode.json.schema.internal.JsonSchemaAssertion
99
import io.github.optimumcode.json.schema.internal.wrapper.wrap
@@ -18,7 +18,7 @@ import kotlin.jvm.JvmStatic
1818
*/
1919
public class JsonSchema internal constructor(
2020
private val assertion: JsonSchemaAssertion,
21-
private val referenceResolver: DefaultReferenceResolver,
21+
private val referenceResolverProvider: DefaultReferenceResolverProvider,
2222
) {
2323
/**
2424
* Validates [value] against this [JsonSchema].
@@ -56,7 +56,7 @@ public class JsonSchema internal constructor(
5656
value: AbstractElement,
5757
errorCollector: ErrorCollector,
5858
): Boolean {
59-
val context = DefaultAssertionContext(JsonPointer.ROOT, referenceResolver)
59+
val context = DefaultAssertionContext(JsonPointer.ROOT, referenceResolverProvider.createResolver())
6060
return DelegateOutputCollector(errorCollector).use {
6161
assertion.validate(value, context, this)
6262
}
@@ -74,7 +74,7 @@ public class JsonSchema internal constructor(
7474
value: AbstractElement,
7575
outputCollectorProvider: OutputCollector.Provider<T>,
7676
): T {
77-
val context = DefaultAssertionContext(JsonPointer.ROOT, referenceResolver)
77+
val context = DefaultAssertionContext(JsonPointer.ROOT, referenceResolverProvider.createResolver())
7878
val collector = outputCollectorProvider.get()
7979
collector.use {
8080
assertion.validate(value, context, this)

json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/ReferenceResolver.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ internal class ReferenceHolder(
2222
operator fun component3(): Uri = scopeId
2323
}
2424

25+
internal class DefaultReferenceResolverProvider(
26+
private val references: Map<RefId, AssertionWithPath>,
27+
) {
28+
fun createResolver(): DefaultReferenceResolver = DefaultReferenceResolver(references)
29+
}
30+
2531
internal class DefaultReferenceResolver(
2632
private val references: Map<RefId, AssertionWithPath>,
2733
private val schemaPathsStack: ArrayDeque<Pair<JsonPointer, Uri>> = ArrayDeque(),

json-schema-validator/src/commonMain/kotlin/io/github/optimumcode/json/schema/internal/SchemaLoader.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ private fun createSchema(result: LoadResult): JsonSchema {
289289
.asSequence()
290290
.filter { it.key in result.usedRefs || it.key in dynamicRefs }
291291
.associate { it.key to it.value }
292-
return JsonSchema(result.assertion, DefaultReferenceResolver(usedReferencesWithPath))
292+
return JsonSchema(result.assertion, DefaultReferenceResolverProvider(usedReferencesWithPath))
293293
}
294294

295295
private class LoadResult(

0 commit comments

Comments
 (0)