From cbfb2e79059794fbc95fa4073b559ca96c7e8920 Mon Sep 17 00:00:00 2001 From: kuntal1461 Date: Mon, 13 Jul 2026 01:28:09 +0530 Subject: [PATCH] fix: accept quoted numeric strings in OrganizationCostsResult.Amount.value() (#769) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The live API returns `OrganizationCostsResult.Amount.value` as a quoted numeric string (e.g. "0E-6176") despite the OpenAPI spec declaring `type: number`. Jackson's CoercionAction.Fail for String→Float causes tryDeserialize to return null, leaving a JsonString in the JsonField which getOptional() then rejects as invalid data. Fix adds a BigDecimal fallback in Amount.value(): if asKnown() is absent and the backing field is a JsonString, parse via BigDecimal → Double with an isFinite() guard to reject overflow. Authored-By: Kuntal maity --- .../organization/usage/UsageCostsResponse.kt | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageCostsResponse.kt b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageCostsResponse.kt index 760f89b5c..f9c764d77 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageCostsResponse.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/admin/organization/usage/UsageCostsResponse.kt @@ -6677,7 +6677,26 @@ private constructor( * @throws OpenAIInvalidDataException if the JSON field has an unexpected type * (e.g. if the server responded with an unexpected value). */ - fun value(): Optional = value.getOptional("value") + fun value(): Optional { + if (value.isMissing() || value.isNull()) return Optional.empty() + val known = value.asKnown() + if (known.isPresent) return known + // The live API returns this field as a quoted numeric string despite the + // schema declaring type:number. Accept valid finite numeric strings for + // compat. + val str = + value.asString().orElseThrow { + OpenAIInvalidDataException("`value` is invalid, received $value") + } + val d = + str.toBigDecimalOrNull()?.toDouble() + ?: throw OpenAIInvalidDataException( + "`value` is invalid, received $value" + ) + if (!d.isFinite()) + throw OpenAIInvalidDataException("`value` is invalid, received $value") + return Optional.of(d) + } /** * Returns the raw JSON value of [currency].