-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new x-async-support
extension for generating async controllers
#305
Conversation
@@ -78,7 +79,8 @@ class SpringControllerInterfaceGenerator( | |||
.addSpringFunAnnotation(op, verb, path.pathString) | |||
.addSuspendModifier() | |||
|
|||
val funcSpec = if (options.contains(ControllerCodeGenOptionType.COMPLETION_STAGE)) { | |||
val asyncSupport = op.extensions.containsKey(EXTENSION_ASYNC_SUPPORT) | |||
val funcSpec = if (options.contains(ControllerCodeGenOptionType.COMPLETION_STAGE) || asyncSupport) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we allow asyncSupport to override default?
x-async-support: false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, in that case we should not add CompletionStage
.
I have added a check to only accept x-async-support: true
case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the support for handling both true and false.
@@ -78,7 +79,9 @@ class SpringControllerInterfaceGenerator( | |||
.addSpringFunAnnotation(op, verb, path.pathString) | |||
.addSuspendModifier() | |||
|
|||
val funcSpec = if (options.contains(ControllerCodeGenOptionType.COMPLETION_STAGE)) { | |||
val asyncSupport = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would rather see this changed to something like below:
val explicitAsyncSupport = op.extensions[EXTENSION_ASYNC_SUPPORT] as? Boolean
val asyncSupport = explicitAsyncSupport ?: options.contains(ControllerCodeGenOptionType.COMPLETION_STAGE)
val funcSpec = if (asyncSupport) {...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Recently a new capability to generate
CompletionStage
wrapped controllers was added in #304. However, it was using an--http-controller-opts
option which does it for all or none controllers.There are situations where clients require CompletionStage for only specific endpoints in a given controller. This PR adds a fine-grained control to specify which endpoint requires CompletionStage.
OpenAPI's extensions are used to denote it. If you decorate the path of an endpoint with
x-async-support: true
, the controller generated will be wrapped withCompletionStage
.