File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
commonMain/kotlin/com/github/optimumcode/json/schema/internal
commonTest/kotlin/com/github/optimumcode/json/schema/base Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -33,8 +33,10 @@ internal object ReferenceValidator {
3333 return alwaysRunAssertions.any { path.contains(it) }
3434 }
3535 for ((location, refFragment) in locationToRef) {
36- val (otherLocation, otherRefFragment) = locationToRef.entries.find { it.key.startsWith(refFragment) }
37- ? : continue
36+ val (otherLocation, otherRefFragment) = locationToRef.entries.find { (refKey) ->
37+ val startsWith = refKey.startsWith(refFragment)
38+ startsWith && (refKey[refFragment.length] == JsonPointer .SEPARATOR || refKey == refFragment)
39+ } ? : continue
3840 if (! location.startsWith(otherRefFragment)) {
3941 continue
4042 }
Original file line number Diff line number Diff line change @@ -124,5 +124,29 @@ class JsonSchemaTest : FunSpec() {
124124 }.message shouldBe " circled references: /definitions/alice/allOf/0 ref to /definitions/bob" +
125125 " and /definitions/bob/allOf/0 ref to /definitions/alice"
126126 }
127+
128+ test(" does not report circled references if definitions have similar names" ) {
129+ shouldNotThrowAny {
130+ JsonSchema .fromDefinition(
131+ """
132+ {
133+ "${KEY } schema": "http://json-schema.org/draft-07/schema#",
134+ "definitions": {
135+ "nonNegativeInteger": {
136+ "type": "integer",
137+ "minimum": 0
138+ },
139+ "nonNegativeIntegerDefault0": {
140+ "allOf": [
141+ { "${KEY } ref": "#/definitions/nonNegativeInteger" },
142+ { "default": 0 }
143+ ]
144+ }
145+ }
146+ }
147+ """ .trimIndent(),
148+ )
149+ }
150+ }
127151 }
128152}
You can’t perform that action at this time.
0 commit comments