feat(kotlin-spring): add suspendFunctions option for coroutine support#23444
Open
thejeff77 wants to merge 3 commits intoOpenAPITools:masterfrom
Open
feat(kotlin-spring): add suspendFunctions option for coroutine support#23444thejeff77 wants to merge 3 commits intoOpenAPITools:masterfrom
thejeff77 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>
Contributor
Author
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.