Skip to content

fix(kotlin-spring): fix Flow<String> and Flux<T> array return types for reactive generators#24101

Merged
wing328 merged 6 commits into
OpenAPITools:masterfrom
Picazsoo:bugfix/flow-or-flux-of-string-to-mono-list
Jul 14, 2026
Merged

fix(kotlin-spring): fix Flow<String> and Flux<T> array return types for reactive generators#24101
wing328 merged 6 commits into
OpenAPITools:masterfrom
Picazsoo:bugfix/flow-or-flux-of-string-to-mono-list

Conversation

@Picazsoo

@Picazsoo Picazsoo commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Just for documentation purposes as the change has been already merged:

Why string arrays return suspend List<String> even when useFlowForArrayReturnType = true

When targeting a reactive Kotlin Spring server, useFlowForArrayReturnType = true normally
makes array responses return Flow<T> (a streamed publisher). For string arrays
(T = kotlin.String) we deliberately override this and emit suspend fun ...: List<String>
(or Set<String> for uniqueItems) instead.

The reason

Spring WebFlux's StringDecoder intercepts a reactive stream of String before Jackson
runs. Instead of decoding each JSON array element, it hands back the entire JSON array as a
single raw string blob
. As a result, Flow<String> array endpoints silently produce
corrupted / undecoded data.

This is a limitation specific to T = String. Flow<Pet>, Flow<Long>, etc. decode
correctly and are left unchanged.

Why not just honor the flag?

For T = String, useFlowForArrayReturnType = true is an unsatisfiable request: there is
no Flow<String> shape that decodes correctly. So the generator's only options are:

  1. Emit Flow<String> anyway → compiles, silently corrupts data. ❌
  2. Emit suspend List<String> → correct, but changes the method signature. ✅ (chosen)

Correct, non-corrupting option was chosen. A signature that silently corrupts data is worse than a compile-time
signature change the user can adapt to.

Why there is no opt-out flag to force Flow<String> back on

Such a flag would be a supported, documented switch whose only effect is to re-enable known-broken decoding - a
footgun, not a legitimate preference. A generator option should let users choose between two working shapes, not between "correct" and "corrupt."

Summary

Config Element type Output Correct?
useFlowForArrayReturnType = true non-String Flow<T>
useFlowForArrayReturnType = false String suspend List<String>
useFlowForArrayReturnType = true String suspend List<String> (overridden)

Note: this is a breaking signature change for users who previously generated
Flow<String> array endpoints. It is intentional — those endpoints did not decode
correctly to begin with.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Fixes reactive array return types in Kotlin Spring to avoid broken decoding and invalid signatures. Arrays of strings now return List<String>/Set<String> with suspend (not Flow<String>), and declarative Reactor interfaces return Mono<List<T>>/Mono<Set<T>> (not Flux<T>).

  • Bug Fixes

    • Coroutines (kotlin-spring): for array-of-string responses, generate suspend + List<String>/Set<String> to avoid Spring WebFlux StringDecoder swallowing JSON arrays (issue 22662).
    • Declarative Reactor (spring-declarative-http-interface): arrays now use Mono<{{returnContainer}}<T>> (e.g., Mono<List<T>>, Mono<Set<T>>), including Mono<ResponseEntity<...>> when enabled; removed reactor.core.publisher.Flux import.
    • Kotlin type handling: unwrap Set/MutableSet like List so returnType is the inner type and returnContainer is Set, fixing cases like Mono<set<kotlin.collections.Set<...>>>.
    • Added x-reactive-array-string-return vendor extension and updated templates to conditionally emit the new signatures.
    • Updated samples to use Mono<List<...>>/Mono<Set<...>> and drop Flux imports.
  • Migration

    • Coroutines server: replace Flow<String> with List<String> (or Set<String> for uniqueItems) and mark methods suspend.
    • Declarative Reactor: replace Flux<T> with Mono<List<T>>/Mono<Set<T>> (and Mono<ResponseEntity<...>> when used); update imports.

Written for commit a10b418. Summary will update on new commits.

Review in cubic

Picazsoo and others added 4 commits June 23, 2026 00:46
…tring> arrays

doDataTypeAssignment only unwrapped List/MutableList, leaving Set (uniqueItems) return types as the full 'kotlin.collections.Set<...>' with a raw 'set' container. This broke reactive array-of-string handling for Sets: the declarative reactor path emitted the non-compiling 'Mono<set<kotlin.collections.Set<kotlin.String>>>', and the coroutines path emitted a nonsensical non-suspend 'Flow<kotlin.collections.Set<kotlin.String>>'.

Unwrap Set/MutableSet like List so returnType becomes the inner type and returnContainer is 'Set'. This makes the x-reactive-array-string-return fix apply to Set<String> too, and also fixes the same latent bug in kotlin-server (ktor/javalin). Tightened the reactive tests to exercise the uniqueItems Set operation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Picazsoo Picazsoo changed the title fix(kotlin-spring): fix Flow<String> and Flux<T> array return types f… fix(kotlin-spring): fix Flow<String> and Flux<T> array return types for reactive generators Jul 14, 2026
Picazsoo added 2 commits July 14, 2026 08:58
This reverts commit 6e851b4.
This reverts commit 7733960.
@Picazsoo Picazsoo marked this pull request as ready for review July 14, 2026 19:52

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 14 files

Re-trigger cubic

@wing328 wing328 merged commit 5b14fee into OpenAPITools:master Jul 14, 2026
69 checks passed
@wing328 wing328 added this to the 7.24.0 milestone Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants