Skip to content

Commit

Permalink
Correct id resolution when absolute uri-reference is used (#105)
Browse files Browse the repository at this point in the history
Resolves #104
  • Loading branch information
OptimumCode authored May 3, 2024
1 parent cdfe7dc commit 17277e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,12 @@ private data class DefaultLoadingContext(
) {
when {
id.isAbsolute -> register(id.buildRefId(), assertion, dynamic) // register JSON schema by absolute URI
id.encodedPath.let { it != null && it.startsWith('/') } ->
register(
additionalIDs.resolvePath(id.encodedPath).buildRefId(),
assertion,
dynamic,
)
id.isRelative ->
when {
// For root schema we should not apply any transformations to ID
Expand Down Expand Up @@ -650,6 +656,11 @@ private fun Set<IdWithLocation>.resolvePath(path: String?): Uri {
}

private fun Uri.appendPathToParent(path: String): Uri {
if (path.startsWith('/')) {
return buildUpon()
.encodedPath(path)
.build()
}
val hasLastEmptySegment = toString().endsWith('/')
return if (hasLastEmptySegment) {
buildUpon() // don't need to drop anything. just add the path because / in the end means empty segment
Expand Down
2 changes: 1 addition & 1 deletion test-suites/schema-test-suite

0 comments on commit 17277e2

Please sign in to comment.