From 3bf493834d353ba9058f3ff8befb1059ec1ec8da Mon Sep 17 00:00:00 2001 From: Sparshal Kothari <41056517+spor3006@users.noreply.github.com> Date: Tue, 19 May 2026 23:32:51 +0530 Subject: [PATCH] fix(audio): treat DIARIZED_JSON as a JSON response format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AudioResponseFormat.isJson() omitted DIARIZED_JSON from its when() branches and fell through to the `else -> false` default. As a result, `AudioTranscriptionService.create(...)` with `response_format = DIARIZED_JSON` parsed the response body as plain text — the entire diarized JSON payload was dropped into `TranscriptionCreateResponse.transcription.text` instead of populating `TranscriptionCreateResponse.diarized`. Callers had to round-trip the text field through an external Jackson reader to recover the structured result. Add `DIARIZED_JSON -> true` to isJson() and add an AudioResponseFormatTest that enumerates every value of AudioResponseFormat.Known explicitly, so any future format added to the enum forces a conscious decision about whether it is JSON — the same class of bug cannot regress when a new format is introduced. Fixes #652 Signed-off-by: Sparshal Kothari <41056517+spor3006@users.noreply.github.com> --- .../models/audio/AudioResponseFormat.kt | 1 + .../models/audio/AudioResponseFormatTest.kt | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 openai-java-core/src/test/kotlin/com/openai/models/audio/AudioResponseFormatTest.kt diff --git a/openai-java-core/src/main/kotlin/com/openai/models/audio/AudioResponseFormat.kt b/openai-java-core/src/main/kotlin/com/openai/models/audio/AudioResponseFormat.kt index fa2a75a45..394c6cab1 100644 --- a/openai-java-core/src/main/kotlin/com/openai/models/audio/AudioResponseFormat.kt +++ b/openai-java-core/src/main/kotlin/com/openai/models/audio/AudioResponseFormat.kt @@ -166,6 +166,7 @@ class AudioResponseFormat @JsonCreator private constructor(private val value: Js SRT -> false VERBOSE_JSON -> true VTT -> false + DIARIZED_JSON -> true else -> false } diff --git a/openai-java-core/src/test/kotlin/com/openai/models/audio/AudioResponseFormatTest.kt b/openai-java-core/src/test/kotlin/com/openai/models/audio/AudioResponseFormatTest.kt new file mode 100644 index 000000000..780d70174 --- /dev/null +++ b/openai-java-core/src/test/kotlin/com/openai/models/audio/AudioResponseFormatTest.kt @@ -0,0 +1,54 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.openai.models.audio + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class AudioResponseFormatTest { + + /** + * Regression test for [#652](https://github.com/openai/openai-java/issues/652). + * + * Each value of [AudioResponseFormat.Known] is enumerated explicitly so that adding a new + * format also requires adding it to this test. That makes it impossible to introduce a new JSON + * format without consciously deciding whether [AudioResponseFormat.isJson] should return `true` + * for it — the bug that caused `DIARIZED_JSON` responses to be parsed as plain text and stashed + * in `TranscriptionCreateResponse.transcription.text` instead of populating + * `TranscriptionCreateResponse.diarized`. + */ + @Test + fun isJson_returnsTrue_forEveryJsonResponseFormat() { + for (known in AudioResponseFormat.Known.values()) { + val format = AudioResponseFormat.of(known.toString().lowercase()) + val expected = + when (known) { + AudioResponseFormat.Known.JSON -> true + AudioResponseFormat.Known.TEXT -> false + AudioResponseFormat.Known.SRT -> false + AudioResponseFormat.Known.VERBOSE_JSON -> true + AudioResponseFormat.Known.VTT -> false + AudioResponseFormat.Known.DIARIZED_JSON -> true + } + assertThat(format.isJson()) + .withFailMessage( + "AudioResponseFormat.$known.isJson() returned %s but expected %s", + format.isJson(), + expected, + ) + .isEqualTo(expected) + } + } + + /** + * Pinning [#652](https://github.com/openai/openai-java/issues/652) directly: a SDK consumer + * that requests `diarized_json` and feeds the value back through [AudioResponseFormat.of] must + * see [AudioResponseFormat.isJson] return `true`, otherwise the response body is treated as + * plain text by the transcription parser. + */ + @Test + fun diarizedJson_isReportedAsJson() { + assertThat(AudioResponseFormat.DIARIZED_JSON.isJson()).isTrue() + assertThat(AudioResponseFormat.of("diarized_json").isJson()).isTrue() + } +}