Skip to content

Commit 17277e2

Browse files
authored
Correct id resolution when absolute uri-reference is used (#105)
Resolves #104
1 parent cdfe7dc commit 17277e2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,12 @@ private data class DefaultLoadingContext(
608608
) {
609609
when {
610610
id.isAbsolute -> register(id.buildRefId(), assertion, dynamic) // register JSON schema by absolute URI
611+
id.encodedPath.let { it != null && it.startsWith('/') } ->
612+
register(
613+
additionalIDs.resolvePath(id.encodedPath).buildRefId(),
614+
assertion,
615+
dynamic,
616+
)
611617
id.isRelative ->
612618
when {
613619
// For root schema we should not apply any transformations to ID
@@ -650,6 +656,11 @@ private fun Set<IdWithLocation>.resolvePath(path: String?): Uri {
650656
}
651657

652658
private fun Uri.appendPathToParent(path: String): Uri {
659+
if (path.startsWith('/')) {
660+
return buildUpon()
661+
.encodedPath(path)
662+
.build()
663+
}
653664
val hasLastEmptySegment = toString().endsWith('/')
654665
return if (hasLastEmptySegment) {
655666
buildUpon() // don't need to drop anything. just add the path because / in the end means empty segment

0 commit comments

Comments
 (0)