Skip to content

Commit

Permalink
fix: add core context if missing in batch operations (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobeal authored Apr 19, 2024
1 parent bac26e4 commit 474ce52
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.egm.stellio.shared.model.*
import com.egm.stellio.shared.util.*
import com.egm.stellio.shared.util.JsonLdUtils.JSONLD_CONTEXT
import com.egm.stellio.shared.util.JsonLdUtils.JSONLD_ID_TERM
import com.egm.stellio.shared.util.JsonLdUtils.NGSILD_CORE_CONTEXT
import com.egm.stellio.shared.util.JsonLdUtils.compactEntities
import com.egm.stellio.shared.util.JsonLdUtils.expandJsonLdEntityF
import com.egm.stellio.shared.util.JsonUtils.deserializeAsList
Expand Down Expand Up @@ -319,7 +318,7 @@ class EntityOperationHandler(
if (contentType == JSON_LD_MEDIA_TYPE)
expandJsonLdEntityF(it.minus(JSONLD_CONTEXT), it.extractContexts())
else
expandJsonLdEntityF(it, listOf(context ?: NGSILD_CORE_CONTEXT))
expandJsonLdEntityF(it, addCoreContextIfMissing(listOfNotNull(context)))
jsonLdExpansionResult
.mapLeft { apiException -> Pair(it[JSONLD_ID_TERM] as String, apiException) }
.flatMap { jsonLdEntity ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fun Map<String, Any>.extractContexts(): List<String> =

private val coreContextRegex = ".*ngsi-ld-core-context-v\\d+.\\d+.jsonld$".toRegex()

internal fun addCoreContextIfMissing(contexts: List<String>): List<String> =
fun addCoreContextIfMissing(contexts: List<String>): List<String> =
when {
contexts.isEmpty() -> listOf(NGSILD_CORE_CONTEXT)
// to ensure that core @context, if present, comes last
Expand Down

0 comments on commit 474ce52

Please sign in to comment.