Skip to content

Commit

Permalink
Ignore unknown response fields (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabi755 authored Apr 16, 2024
1 parent 1f9b431 commit 76a91e8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import io.ktor.client.statement.HttpResponse
import io.ktor.http.ContentType
import io.ktor.http.contentType
import io.ktor.serialization.kotlinx.json.json
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonNull
Expand Down Expand Up @@ -99,7 +100,7 @@ internal fun Lokalise(
): Lokalise {
val clientConfig: HttpClientConfig<*>.() -> Unit = {
install(ContentNegotiation) {
json()
json(Json{ ignoreUnknownKeys = true })
}
install(Logging) {
level = if (fullLoggingEnabled) LogLevel.ALL else LogLevel.HEADERS
Expand Down
12 changes: 12 additions & 0 deletions src/commonTest/kotlin/com/ioki/lokalise/api/LokaliseClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ioki.lokalise.api

import com.ioki.lokalise.api.stubs.errorJson
import com.ioki.lokalise.api.stubs.fileDownloadJson
import com.ioki.lokalise.api.stubs.fileDownloadWithUnknownFieldJson
import com.ioki.lokalise.api.stubs.fileUploadJson
import com.ioki.lokalise.api.stubs.projectsJson
import com.ioki.lokalise.api.stubs.retrieveProcessJson
Expand Down Expand Up @@ -243,6 +244,17 @@ class LokaliseClientTest {
)
}

@Test
fun `test ignore unknown fields`() = runLokaliseTest(fileDownloadWithUnknownFieldJson) { lokalise, mockEngine ->
lokalise.downloadFiles(
projectId = "projectId",
format = "someFormat"
)

val requestData = mockEngine.requestHistory.first()
assertHeaders(requestData.headers)
}

private fun assertHeaders(headers: Headers) = assertTrue {
headers.contains("Accept", "application/json") &&
headers.contains("X-Api-Token", "sec3tT0k3n")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.ioki.lokalise.api.stubs

val fileDownloadWithUnknownFieldJson = """
{
"project_id": "3002780358964f9bab5a92.87762498",
"bundle_url": "https://s3-eu-west-1.amazonaws.com/lokalise-assets/export/MyApp-locale.zip",
"unknown_field": 42
}
""".trimIndent()

0 comments on commit 76a91e8

Please sign in to comment.