feat(kotlin-spring): add suspendFunctions option for coroutine support#23444
feat(kotlin-spring): add suspendFunctions option for coroutine support#23444thejeff77 wants to merge 3 commits intoOpenAPITools:masterfrom
Conversation
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>
The forbiddenapis plugin rejects String(byte[]) without explicit charset. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Requesting ReviewTagging 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 The change is minimal (8 lines in the codegen class, 1 line per template × 4 templates) and backward-compatible. |
|
Friendly bump! 👋 Would love to get some eyes on this when anyone has a chance. Kotlin TC: @karismann @Zomzog @4brunu @yutaka0m @stefankoppier @e5l @dennisameling Happy to address any feedback. Thanks! |
|
Re: the failing All actual openapi-generator modules (core library, executable, maven-plugin) built and tested successfully. The other 3 CircleCI nodes pass, and all GitHub Actions checks are green. |
Summary
suspendFunctionsboolean config option (default:false) to the kotlin-spring generatorsuspendkeyword on controller interfaces, delegate interfaces, service interfaces, and standalone controllersrunBlockingin delegate implementationsChanges
KotlinSpringServerCodegen.java: Added constant, field, CLI switch, andprocessOpts()handlingapi.mustache,apiDelegate.mustache,apiInterface.mustache,service.mustache: Addedsuspendkeyword whensuspendFunctions=true, falling back to existingreactivelogic when falseKotlinSpringServerCodegenTest.java: 3 new tests (interface-only, delegate pattern, defaults-to-false)docs/generators/kotlin-spring.md: Documented new optionUsage
Test plan
suspendFunctionsInterfaceOnly— verifiessuspend funin interface-only modesuspendFunctionsWithDelegatePattern— verifiessuspend funin both API interface and delegatesuspendFunctionsDefaultsToFalse— verifies nosuspendwhen option not set🤖 Generated with Claude Code
Summary by cubic
Adds a
suspendFunctionsoption to thekotlin-springgenerator to emitsuspendfor all API operations, enabling Kotlin coroutines with Spring MVC without WebFlux. Default is false; no changes unless enabled, removing the need forrunBlockingin delegates.New Features
suspendFunctionsswitch (default:false) inKotlinSpringServerCodegen; persisted viaprocessOptsand usable viaadditionalProperties/configOptions.api.mustache,apiInterface.mustache,apiDelegate.mustache,service.mustache) addsuspendwhen enabled and fall back to existingreactivelogic otherwise; works withdelegatePattern,serviceInterface, and interface-only. Docs updated; tests cover these modes and default-off.Bug Fixes
StandardCharsets.UTF_8when reading files to satisfy the forbiddenapis plugin.Written for commit 5aa0cdb. Summary will update on new commits.