Skip to content

Commit 364dab5

Browse files
committed
[Gemini-cli] fix: Handle missing fields in Wikipedia API response
This commit fixes a crash that occurred when the Wikipedia API response was missing certain fields. The main changes are: - Made the `size`, `wordcount`, and `timestamp` fields in the `SearchResult` data class nullable to handle cases where they are not present in the API response. - Updated the unit test for the network module to check for null values.
1 parent 49e86f5 commit 364dab5

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

network/src/main/java/com/anysoftkeyboard/janus/network/SearchResponse.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ data class SearchResult(
3434
@Json(name = "ns") val ns: Int,
3535
@Json(name = "title") val title: String,
3636
@Json(name = "pageid") val pageid: Long,
37-
@Json(name = "size") val size: Int,
38-
@Json(name = "wordcount") val wordcount: Int,
37+
@Json(name = "size") val size: Int?,
38+
@Json(name = "wordcount") val wordcount: Int?,
3939
@Json(name = "snippet") val snippet: String,
40-
@Json(name = "timestamp") val timestamp: String
40+
@Json(name = "timestamp") val timestamp: String?
4141
)

network/src/test/java/com/anysoftkeyboard/janus/network/WikipediaClientTest.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import okhttp3.mockwebserver.MockResponse
77
import okhttp3.mockwebserver.MockWebServer
88
import org.junit.After
99
import org.junit.Assert.assertEquals
10+
import org.junit.Assert.assertNull
1011
import org.junit.Before
1112
import org.junit.Test
1213
import retrofit2.Retrofit
@@ -66,10 +67,7 @@ class WikipediaClientTest {
6667
"ns": 0,
6768
"title": "Monster Summer",
6869
"pageid": 71763900,
69-
"size": 10071,
70-
"wordcount": 773,
71-
"snippet": "Monster <span class=\"searchmatch\">Summer</span> is a 2024 American adventure horror film directed by David Henrie, written by Cornelius Uliano and Bryan Schulz, and starring Mason Thames",
72-
"timestamp": "2025-08-09T19:56:14Z"
70+
"snippet": "Monster <span class=\"searchmatch\">Summer</span> is a 2024 American adventure horror film directed by David Henrie, written by Cornelius Uliano and Bryan Schulz, and starring Mason Thames"
7371
}
7472
]
7573
}
@@ -93,5 +91,9 @@ class WikipediaClientTest {
9391
assertEquals(
9492
"<span class=\"searchmatch\">Summer</span> or summertime is the hottest and brightest of the four temperate seasons, occurring after spring and before autumn. At or centred on the summer",
9593
response.query.search[0].snippet)
94+
assertEquals("Monster Summer", response.query.search[1].title)
95+
assertNull(response.query.search[1].size)
96+
assertNull(response.query.search[1].wordcount)
97+
assertNull(response.query.search[1].timestamp)
9698
}
9799
}

0 commit comments

Comments
 (0)