Skip to content

feat(kotlin-spring): add suspendFunctions option for coroutine support#23444

Open
thejeff77 wants to merge 3 commits intoOpenAPITools:masterfrom
thejeff77:feat/suspend-functions-option
Open

feat(kotlin-spring): add suspendFunctions option for coroutine support#23444
thejeff77 wants to merge 3 commits intoOpenAPITools:masterfrom
thejeff77:feat/suspend-functions-option

Conversation

@thejeff77
Copy link
Copy Markdown
Contributor

@thejeff77 thejeff77 commented Apr 2, 2026

Summary

  • Adds a new suspendFunctions boolean config option (default: false) to the kotlin-spring generator
  • When enabled, all generated API operations get the suspend keyword on controller interfaces, delegate interfaces, service interfaces, and standalone controllers
  • Enables Spring MVC + Kotlin coroutines without requiring the full reactive stack (WebFlux/Flow), eliminating the need for runBlocking in delegate implementations

Changes

  • KotlinSpringServerCodegen.java: Added constant, field, CLI switch, and processOpts() handling
  • api.mustache, apiDelegate.mustache, apiInterface.mustache, service.mustache: Added suspend keyword when suspendFunctions=true, falling back to existing reactive logic when false
  • KotlinSpringServerCodegenTest.java: 3 new tests (interface-only, delegate pattern, defaults-to-false)
  • docs/generators/kotlin-spring.md: Documented new option

Usage

configOptions:
  delegatePattern: "true"
  suspendFunctions: "true"

Test plan

  • suspendFunctionsInterfaceOnly — verifies suspend fun in interface-only mode
  • suspendFunctionsWithDelegatePattern — verifies suspend fun in both API interface and delegate
  • suspendFunctionsDefaultsToFalse — verifies no suspend when option not set
  • Existing reactive tests pass (no regressions)

🤖 Generated with Claude Code


Summary by cubic

Adds a suspendFunctions option to the kotlin-spring generator to emit suspend for all API operations, enabling Kotlin coroutines with Spring MVC without WebFlux. Default is false; no changes unless enabled, removing the need for runBlocking in delegates.

  • New Features

    • New suspendFunctions switch (default: false) in KotlinSpringServerCodegen; persisted via processOpts and usable via additionalProperties/configOptions.
    • Templates (api.mustache, apiInterface.mustache, apiDelegate.mustache, service.mustache) add suspend when enabled and fall back to existing reactive logic otherwise; works with delegatePattern, serviceInterface, and interface-only. Docs updated; tests cover these modes and default-off.
  • Bug Fixes

    • Tests use StandardCharsets.UTF_8 when reading files to satisfy the forbiddenapis plugin.

Written for commit 5aa0cdb. Summary will update on new commits.

thejeff77 and others added 2 commits April 2, 2026 11:07
Add a new `suspendFunctions` boolean config option (default: false) to
the kotlin-spring generator. When enabled, all generated API operations
get the `suspend` keyword on controller interfaces, delegate interfaces,
service interfaces, and standalone controllers.

This enables Spring MVC + Kotlin coroutines without requiring the full
reactive stack (WebFlux/Flow). Users no longer need `runBlocking` in
their delegate implementations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add suspendFunctionsWithServiceInterface test covering service.mustache
- Replace java.nio.file.Files with already-imported Files

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 7 files

The forbiddenapis plugin rejects String(byte[]) without explicit charset.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@thejeff77
Copy link
Copy Markdown
Contributor Author

Requesting Review

Tagging the Kotlin technical committee and recent active contributors to the kotlin-spring generator for visibility:

Kotlin TC: @karismann @Zomzog @4brunu @yutaka0m @stefankoppier @e5l @dennisameling

Recent active contributors to kotlin-spring: @metlicka @wing328 @neeme-praks-sympower @takkiraz

This PR adds a suspendFunctions config option (default: false) that generates suspend fun for all API operations without requiring the full reactive stack. It's useful for Spring MVC + Kotlin coroutines — the current workaround is wrapping delegate calls in runBlocking, which this eliminates.

The change is minimal (8 lines in the codegen class, 1 line per template × 4 templates) and backward-compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant