feat(kotlin-spring): add suspendFunctions option for coroutine support - #23444
Conversation
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. |
|
@thejeff77 thanks for the PR can you please resolve the merge conflicts when you've time? Then please PM me via Slack to have this reviewed and merged https://join.slack.com/t/openapi-generator/shared_invite/zt-36ucx4ybl-jYrN6euoYn6zxXNZdldoZA |
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. Includes tests for interface-only, delegate pattern, default-disabled, and service-interface variants. Uses StandardCharsets.UTF_8 explicitly to satisfy the forbiddenapis plugin. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3055e0a to
a8ab0af
Compare
|
Ran some tests locally and the result is good. Thanks for the contribution. |
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 new
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 and services.New Features
suspendFunctionsswitch (default:false) inKotlinSpringServerCodegen; exposed via CLIaddSwitch, persisted viaprocessOpts, configurable viaadditionalProperties/configOptions.api.mustache,apiInterface.mustache,apiDelegate.mustache,service.mustache) addsuspendwhen enabled; otherwise use existingreactivelogic. Works withdelegatePattern,serviceInterface, and interface-only. Docs updated (option added to table).Bug Fixes
StandardCharsets.UTF_8to satisfy the forbiddenapis plugin.Written for commit a8ab0af. Summary will update on new commits. Review in cubic