1
+ // File generated from our OpenAPI spec by Stainless.
2
+
1
3
package com.openai.core.http
2
4
5
+ import com.openai.core.JsonArray
6
+ import com.openai.core.JsonBoolean
7
+ import com.openai.core.JsonMissing
8
+ import com.openai.core.JsonNull
9
+ import com.openai.core.JsonNumber
10
+ import com.openai.core.JsonObject
11
+ import com.openai.core.JsonString
12
+ import com.openai.core.JsonValue
3
13
import com.openai.core.toImmutable
4
14
import java.util.TreeMap
5
15
@@ -28,6 +38,19 @@ private constructor(
28
38
TreeMap (String .CASE_INSENSITIVE_ORDER )
29
39
private var size: Int = 0
30
40
41
+ fun put (name : String , value : JsonValue ): Builder = apply {
42
+ when (value) {
43
+ is JsonMissing ,
44
+ is JsonNull -> {}
45
+ is JsonBoolean -> put(name, value.value.toString())
46
+ is JsonNumber -> put(name, value.value.toString())
47
+ is JsonString -> put(name, value.value)
48
+ is JsonArray -> value.values.forEach { put(name, it) }
49
+ is JsonObject ->
50
+ value.values.forEach { (nestedName, value) -> put(" $name .$nestedName " , value) }
51
+ }
52
+ }
53
+
31
54
fun put (name : String , value : String ) = apply {
32
55
map.getOrPut(name) { mutableListOf () }.add(value)
33
56
size++
@@ -41,15 +64,6 @@ private constructor(
41
64
headers.names().forEach { put(it, headers.values(it)) }
42
65
}
43
66
44
- fun remove (name : String ) = apply { size - = map.remove(name).orEmpty().size }
45
-
46
- fun removeAll (names : Set <String >) = apply { names.forEach(::remove) }
47
-
48
- fun clear () = apply {
49
- map.clear()
50
- size = 0
51
- }
52
-
53
67
fun replace (name : String , value : String ) = apply {
54
68
remove(name)
55
69
put(name, value)
@@ -68,6 +82,15 @@ private constructor(
68
82
headers.names().forEach { replace(it, headers.values(it)) }
69
83
}
70
84
85
+ fun remove (name : String ) = apply { size - = map.remove(name).orEmpty().size }
86
+
87
+ fun removeAll (names : Set <String >) = apply { names.forEach(::remove) }
88
+
89
+ fun clear () = apply {
90
+ map.clear()
91
+ size = 0
92
+ }
93
+
71
94
fun build () =
72
95
Headers (
73
96
map.mapValuesTo(TreeMap (String .CASE_INSENSITIVE_ORDER )) { (_, values) ->
0 commit comments