Skip to content

Commit ca3f877

Browse files
fix(types): change type field to constant in ResponseInputMessageItem
1 parent 6e95c74 commit ca3f877

5 files changed

Lines changed: 44 additions & 167 deletions

File tree

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 151
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-55ef7034334e938c30656a404ce5e21466103be87542a796425346299f450404.yml
3-
openapi_spec_hash: 4a5bfd2ee4ad47f5b7cf6f1ad08d5d7f
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-0fea07225431c8d0cf5fc1a70c9363a91d259f7a169f410717e162de1b24e489.yml
3+
openapi_spec_hash: 41b34c1678ec0e95daf62ca4cd52c8f8
44
config_hash: 96fbf82cf74a44ccd513f5acf0956ffd

openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseInputMessageItem.kt

Lines changed: 42 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ private constructor(
2626
private val id: JsonField<String>,
2727
private val content: JsonField<List<ResponseInputContent>>,
2828
private val role: JsonField<Role>,
29+
private val type: JsonValue,
2930
private val status: JsonField<Status>,
30-
private val type: JsonField<Type>,
3131
private val additionalProperties: MutableMap<String, JsonValue>,
3232
) {
3333

@@ -38,9 +38,9 @@ private constructor(
3838
@ExcludeMissing
3939
content: JsonField<List<ResponseInputContent>> = JsonMissing.of(),
4040
@JsonProperty("role") @ExcludeMissing role: JsonField<Role> = JsonMissing.of(),
41+
@JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(),
4142
@JsonProperty("status") @ExcludeMissing status: JsonField<Status> = JsonMissing.of(),
42-
@JsonProperty("type") @ExcludeMissing type: JsonField<Type> = JsonMissing.of(),
43-
) : this(id, content, role, status, type, mutableMapOf())
43+
) : this(id, content, role, type, status, mutableMapOf())
4444

4545
/**
4646
* The unique ID of the message input.
@@ -67,21 +67,26 @@ private constructor(
6767
fun role(): Role = role.getRequired("role")
6868

6969
/**
70-
* The status of item. One of `in_progress`, `completed`, or `incomplete`. Populated when items
71-
* are returned via API.
70+
* The type of the message input. Always set to `message`.
7271
*
73-
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
74-
* server responded with an unexpected value).
72+
* Expected to always return the following:
73+
* ```java
74+
* JsonValue.from("message")
75+
* ```
76+
*
77+
* However, this method can be useful for debugging and logging (e.g. if the server responded
78+
* with an unexpected value).
7579
*/
76-
fun status(): Optional<Status> = status.getOptional("status")
80+
@JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type
7781

7882
/**
79-
* The type of the message input. Always set to `message`.
83+
* The status of item. One of `in_progress`, `completed`, or `incomplete`. Populated when items
84+
* are returned via API.
8085
*
8186
* @throws OpenAIInvalidDataException if the JSON field has an unexpected type (e.g. if the
8287
* server responded with an unexpected value).
8388
*/
84-
fun type(): Optional<Type> = type.getOptional("type")
89+
fun status(): Optional<Status> = status.getOptional("status")
8590

8691
/**
8792
* Returns the raw JSON value of [id].
@@ -113,13 +118,6 @@ private constructor(
113118
*/
114119
@JsonProperty("status") @ExcludeMissing fun _status(): JsonField<Status> = status
115120

116-
/**
117-
* Returns the raw JSON value of [type].
118-
*
119-
* Unlike [type], this method doesn't throw if the JSON field has an unexpected type.
120-
*/
121-
@JsonProperty("type") @ExcludeMissing fun _type(): JsonField<Type> = type
122-
123121
@JsonAnySetter
124122
private fun putAdditionalProperty(key: String, value: JsonValue) {
125123
additionalProperties.put(key, value)
@@ -153,17 +151,17 @@ private constructor(
153151
private var id: JsonField<String>? = null
154152
private var content: JsonField<MutableList<ResponseInputContent>>? = null
155153
private var role: JsonField<Role>? = null
154+
private var type: JsonValue = JsonValue.from("message")
156155
private var status: JsonField<Status> = JsonMissing.of()
157-
private var type: JsonField<Type> = JsonMissing.of()
158156
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
159157

160158
@JvmSynthetic
161159
internal fun from(responseInputMessageItem: ResponseInputMessageItem) = apply {
162160
id = responseInputMessageItem.id
163161
content = responseInputMessageItem.content.map { it.toMutableList() }
164162
role = responseInputMessageItem.role
165-
status = responseInputMessageItem.status
166163
type = responseInputMessageItem.type
164+
status = responseInputMessageItem.status
167165
additionalProperties = responseInputMessageItem.additionalProperties.toMutableMap()
168166
}
169167

@@ -249,6 +247,20 @@ private constructor(
249247
*/
250248
fun role(role: JsonField<Role>) = apply { this.role = role }
251249

250+
/**
251+
* Sets the field to an arbitrary JSON value.
252+
*
253+
* It is usually unnecessary to call this method because the field defaults to the
254+
* following:
255+
* ```java
256+
* JsonValue.from("message")
257+
* ```
258+
*
259+
* This method is primarily for setting the field to an undocumented or not yet supported
260+
* value.
261+
*/
262+
fun type(type: JsonValue) = apply { this.type = type }
263+
252264
/**
253265
* The status of item. One of `in_progress`, `completed`, or `incomplete`. Populated when
254266
* items are returned via API.
@@ -263,17 +275,6 @@ private constructor(
263275
*/
264276
fun status(status: JsonField<Status>) = apply { this.status = status }
265277

266-
/** The type of the message input. Always set to `message`. */
267-
fun type(type: Type) = type(JsonField.of(type))
268-
269-
/**
270-
* Sets [Builder.type] to an arbitrary JSON value.
271-
*
272-
* You should usually call [Builder.type] with a well-typed [Type] value instead. This
273-
* method is primarily for setting the field to an undocumented or not yet supported value.
274-
*/
275-
fun type(type: JsonField<Type>) = apply { this.type = type }
276-
277278
fun additionalProperties(additionalProperties: Map<String, JsonValue>) = apply {
278279
this.additionalProperties.clear()
279280
putAllAdditionalProperties(additionalProperties)
@@ -312,8 +313,8 @@ private constructor(
312313
checkRequired("id", id),
313314
checkRequired("content", content).map { it.toImmutable() },
314315
checkRequired("role", role),
315-
status,
316316
type,
317+
status,
317318
additionalProperties.toMutableMap(),
318319
)
319320
}
@@ -328,8 +329,12 @@ private constructor(
328329
id()
329330
content().forEach { it.validate() }
330331
role().validate()
332+
_type().let {
333+
if (it != JsonValue.from("message")) {
334+
throw OpenAIInvalidDataException("'type' is invalid, received $it")
335+
}
336+
}
331337
status().ifPresent { it.validate() }
332-
type().ifPresent { it.validate() }
333338
validated = true
334339
}
335340

@@ -351,8 +356,8 @@ private constructor(
351356
(if (id.asKnown().isPresent) 1 else 0) +
352357
(content.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
353358
(role.asKnown().getOrNull()?.validity() ?: 0) +
354-
(status.asKnown().getOrNull()?.validity() ?: 0) +
355-
(type.asKnown().getOrNull()?.validity() ?: 0)
359+
type.let { if (it == JsonValue.from("message")) 1 else 0 } +
360+
(status.asKnown().getOrNull()?.validity() ?: 0)
356361

357362
/** The role of the message input. One of `user`, `system`, or `developer`. */
358363
class Role @JsonCreator private constructor(private val value: JsonField<String>) : Enum {
@@ -621,126 +626,6 @@ private constructor(
621626
override fun toString() = value.toString()
622627
}
623628

624-
/** The type of the message input. Always set to `message`. */
625-
class Type @JsonCreator private constructor(private val value: JsonField<String>) : Enum {
626-
627-
/**
628-
* Returns this class instance's raw value.
629-
*
630-
* This is usually only useful if this instance was deserialized from data that doesn't
631-
* match any known member, and you want to know that value. For example, if the SDK is on an
632-
* older version than the API, then the API may respond with new members that the SDK is
633-
* unaware of.
634-
*/
635-
@com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value
636-
637-
companion object {
638-
639-
@JvmField val MESSAGE = of("message")
640-
641-
@JvmStatic fun of(value: String) = Type(JsonField.of(value))
642-
}
643-
644-
/** An enum containing [Type]'s known values. */
645-
enum class Known {
646-
MESSAGE
647-
}
648-
649-
/**
650-
* An enum containing [Type]'s known values, as well as an [_UNKNOWN] member.
651-
*
652-
* An instance of [Type] can contain an unknown value in a couple of cases:
653-
* - It was deserialized from data that doesn't match any known member. For example, if the
654-
* SDK is on an older version than the API, then the API may respond with new members that
655-
* the SDK is unaware of.
656-
* - It was constructed with an arbitrary value using the [of] method.
657-
*/
658-
enum class Value {
659-
MESSAGE,
660-
/** An enum member indicating that [Type] was instantiated with an unknown value. */
661-
_UNKNOWN,
662-
}
663-
664-
/**
665-
* Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN]
666-
* if the class was instantiated with an unknown value.
667-
*
668-
* Use the [known] method instead if you're certain the value is always known or if you want
669-
* to throw for the unknown case.
670-
*/
671-
fun value(): Value =
672-
when (this) {
673-
MESSAGE -> Value.MESSAGE
674-
else -> Value._UNKNOWN
675-
}
676-
677-
/**
678-
* Returns an enum member corresponding to this class instance's value.
679-
*
680-
* Use the [value] method instead if you're uncertain the value is always known and don't
681-
* want to throw for the unknown case.
682-
*
683-
* @throws OpenAIInvalidDataException if this class instance's value is a not a known
684-
* member.
685-
*/
686-
fun known(): Known =
687-
when (this) {
688-
MESSAGE -> Known.MESSAGE
689-
else -> throw OpenAIInvalidDataException("Unknown Type: $value")
690-
}
691-
692-
/**
693-
* Returns this class instance's primitive wire representation.
694-
*
695-
* This differs from the [toString] method because that method is primarily for debugging
696-
* and generally doesn't throw.
697-
*
698-
* @throws OpenAIInvalidDataException if this class instance's value does not have the
699-
* expected primitive type.
700-
*/
701-
fun asString(): String =
702-
_value().asString().orElseThrow { OpenAIInvalidDataException("Value is not a String") }
703-
704-
private var validated: Boolean = false
705-
706-
fun validate(): Type = apply {
707-
if (validated) {
708-
return@apply
709-
}
710-
711-
known()
712-
validated = true
713-
}
714-
715-
fun isValid(): Boolean =
716-
try {
717-
validate()
718-
true
719-
} catch (e: OpenAIInvalidDataException) {
720-
false
721-
}
722-
723-
/**
724-
* Returns a score indicating how many valid values are contained in this object
725-
* recursively.
726-
*
727-
* Used for best match union deserialization.
728-
*/
729-
@JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1
730-
731-
override fun equals(other: Any?): Boolean {
732-
if (this === other) {
733-
return true
734-
}
735-
736-
return other is Type && value == other.value
737-
}
738-
739-
override fun hashCode() = value.hashCode()
740-
741-
override fun toString() = value.toString()
742-
}
743-
744629
override fun equals(other: Any?): Boolean {
745630
if (this === other) {
746631
return true
@@ -750,17 +635,17 @@ private constructor(
750635
id == other.id &&
751636
content == other.content &&
752637
role == other.role &&
753-
status == other.status &&
754638
type == other.type &&
639+
status == other.status &&
755640
additionalProperties == other.additionalProperties
756641
}
757642

758643
private val hashCode: Int by lazy {
759-
Objects.hash(id, content, role, status, type, additionalProperties)
644+
Objects.hash(id, content, role, type, status, additionalProperties)
760645
}
761646

762647
override fun hashCode(): Int = hashCode
763648

764649
override fun toString() =
765-
"ResponseInputMessageItem{id=$id, content=$content, role=$role, status=$status, type=$type, additionalProperties=$additionalProperties}"
650+
"ResponseInputMessageItem{id=$id, content=$content, role=$role, type=$type, status=$status, additionalProperties=$additionalProperties}"
766651
}

openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseInputMessageItemTest.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ internal class ResponseInputMessageItemTest {
1717
.addInputTextContent("text")
1818
.role(ResponseInputMessageItem.Role.USER)
1919
.status(ResponseInputMessageItem.Status.IN_PROGRESS)
20-
.type(ResponseInputMessageItem.Type.MESSAGE)
2120
.build()
2221

2322
assertThat(responseInputMessageItem.id()).isEqualTo("id")
@@ -28,7 +27,6 @@ internal class ResponseInputMessageItemTest {
2827
assertThat(responseInputMessageItem.role()).isEqualTo(ResponseInputMessageItem.Role.USER)
2928
assertThat(responseInputMessageItem.status())
3029
.contains(ResponseInputMessageItem.Status.IN_PROGRESS)
31-
assertThat(responseInputMessageItem.type()).contains(ResponseInputMessageItem.Type.MESSAGE)
3230
}
3331

3432
@Test
@@ -40,7 +38,6 @@ internal class ResponseInputMessageItemTest {
4038
.addInputTextContent("text")
4139
.role(ResponseInputMessageItem.Role.USER)
4240
.status(ResponseInputMessageItem.Status.IN_PROGRESS)
43-
.type(ResponseInputMessageItem.Type.MESSAGE)
4441
.build()
4542

4643
val roundtrippedResponseInputMessageItem =

openai-java-core/src/test/kotlin/com/openai/models/responses/ResponseItemTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ internal class ResponseItemTest {
2222
.addInputTextContent("text")
2323
.role(ResponseInputMessageItem.Role.USER)
2424
.status(ResponseInputMessageItem.Status.IN_PROGRESS)
25-
.type(ResponseInputMessageItem.Type.MESSAGE)
2625
.build()
2726

2827
val responseItem = ResponseItem.ofResponseInputMessageItem(responseInputMessageItem)
@@ -61,7 +60,6 @@ internal class ResponseItemTest {
6160
.addInputTextContent("text")
6261
.role(ResponseInputMessageItem.Role.USER)
6362
.status(ResponseInputMessageItem.Status.IN_PROGRESS)
64-
.type(ResponseInputMessageItem.Type.MESSAGE)
6563
.build()
6664
)
6765

openai-java-core/src/test/kotlin/com/openai/models/responses/inputitems/ResponseItemListTest.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ internal class ResponseItemListTest {
2121
.addInputTextContent("text")
2222
.role(ResponseInputMessageItem.Role.USER)
2323
.status(ResponseInputMessageItem.Status.IN_PROGRESS)
24-
.type(ResponseInputMessageItem.Type.MESSAGE)
2524
.build()
2625
)
2726
.firstId("first_id")
@@ -37,7 +36,6 @@ internal class ResponseItemListTest {
3736
.addInputTextContent("text")
3837
.role(ResponseInputMessageItem.Role.USER)
3938
.status(ResponseInputMessageItem.Status.IN_PROGRESS)
40-
.type(ResponseInputMessageItem.Type.MESSAGE)
4139
.build()
4240
)
4341
)
@@ -57,7 +55,6 @@ internal class ResponseItemListTest {
5755
.addInputTextContent("text")
5856
.role(ResponseInputMessageItem.Role.USER)
5957
.status(ResponseInputMessageItem.Status.IN_PROGRESS)
60-
.type(ResponseInputMessageItem.Type.MESSAGE)
6158
.build()
6259
)
6360
.firstId("first_id")

0 commit comments

Comments
 (0)