Skip to content
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

Merged
merged 3 commits into from
Jul 31, 2024

Conversation

jeet23
Copy link
Contributor

@jeet23 jeet23 commented Jul 31, 2024

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 with CompletionStage.

@@ -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) {
Copy link
Owner

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

Copy link
Contributor Author

@jeet23 jeet23 Jul 31, 2024

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.

Copy link
Contributor Author

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 =
Copy link
Owner

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) {...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@cjbooms cjbooms merged commit 46487ff into cjbooms:master Jul 31, 2024
1 check passed
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.

2 participants