fix(client) add encodeDefault for field with non spec default value (#99)
* fix(client) add encodeDefault for field with non spec default value * add test
This commit is contained in:
parent
9341f1e42f
commit
fb568bbcab
2 changed files with 10 additions and 0 deletions
|
|
@ -1054,6 +1054,8 @@ public data class Tool(
|
||||||
val properties: JsonObject = EmptyJsonObject,
|
val properties: JsonObject = EmptyJsonObject,
|
||||||
val required: List<String>? = null,
|
val required: List<String>? = null,
|
||||||
) {
|
) {
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
|
@EncodeDefault
|
||||||
val type: String = "object"
|
val type: String = "object"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package io.modelcontextprotocol.kotlin.sdk
|
||||||
import io.kotest.assertions.json.shouldEqualJson
|
import io.kotest.assertions.json.shouldEqualJson
|
||||||
import io.modelcontextprotocol.kotlin.sdk.shared.McpJson
|
import io.modelcontextprotocol.kotlin.sdk.shared.McpJson
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
import kotlinx.serialization.json.JsonPrimitive
|
import kotlinx.serialization.json.JsonPrimitive
|
||||||
import kotlinx.serialization.json.buildJsonObject
|
import kotlinx.serialization.json.buildJsonObject
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
|
|
@ -54,4 +55,11 @@ class ToolSerializationTest {
|
||||||
assertEquals(expected = getWeatherTool, actual = tool)
|
assertEquals(expected = getWeatherTool, actual = tool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should always serialize default value`() {
|
||||||
|
val json = Json(from = McpJson) {
|
||||||
|
encodeDefaults = false
|
||||||
|
}
|
||||||
|
json.encodeToString(getWeatherTool) shouldEqualJson getWeatherToolJson
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue