diff --git a/search-service/src/main/kotlin/com/egm/stellio/search/web/EntityOperationHandler.kt b/search-service/src/main/kotlin/com/egm/stellio/search/web/EntityOperationHandler.kt index 4a145e974..1a92bb2c9 100644 --- a/search-service/src/main/kotlin/com/egm/stellio/search/web/EntityOperationHandler.kt +++ b/search-service/src/main/kotlin/com/egm/stellio/search/web/EntityOperationHandler.kt @@ -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 @@ -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 -> diff --git a/shared/src/main/kotlin/com/egm/stellio/shared/util/ApiUtils.kt b/shared/src/main/kotlin/com/egm/stellio/shared/util/ApiUtils.kt index e994080c9..fcbded585 100644 --- a/shared/src/main/kotlin/com/egm/stellio/shared/util/ApiUtils.kt +++ b/shared/src/main/kotlin/com/egm/stellio/shared/util/ApiUtils.kt @@ -155,7 +155,7 @@ fun Map.extractContexts(): List = private val coreContextRegex = ".*ngsi-ld-core-context-v\\d+.\\d+.jsonld$".toRegex() -internal fun addCoreContextIfMissing(contexts: List): List = +fun addCoreContextIfMissing(contexts: List): List = when { contexts.isEmpty() -> listOf(NGSILD_CORE_CONTEXT) // to ensure that core @context, if present, comes last