Implement asyncapi DSL - #1619
Closed
mcruzdev wants to merge 2 commits into
Closed
Conversation
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an AsyncAPI call DSL to the fluent WorkflowBuilder API and refactors several runtime components to resolve SPI implementations via WorkflowApplication instead of direct ServiceLoader usage.
Changes:
- Introduces fluent DSL/builders/configurers for
call(asyncapi()...)plus comprehensive DSL tests. - Centralizes service discovery into
WorkflowApplication.serviceLoadedClass(es)(...)and updates multiple executors/builders to use it. - Makes fluent workflow building fail-fast by throwing when a
.tasks(...)call results in an empty task list (with tests added).
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/HttpExecutorBuilder.java | Switches HTTP request decorator discovery to WorkflowApplication service loading. |
| impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowApplication.java | Adds cached service-loading helpers for SPI discovery. |
| impl/core/src/main/java/io/serverlessworkflow/impl/executors/RunTaskExecutor.java | Uses application-scoped SPI loading for RunnableTaskBuilder selection. |
| impl/core/src/main/java/io/serverlessworkflow/impl/executors/RunScriptExecutorBuilder.java | Uses application-scoped SPI loading for ScriptRunner selection. |
| impl/core/src/main/java/io/serverlessworkflow/impl/executors/EmitExecutor.java | Resolves EmittedEventDecorator implementations via WorkflowApplication. |
| impl/core/src/main/java/io/serverlessworkflow/impl/executors/DefaultTaskExecutorFactory.java | Resolves CallableTaskBuilder implementations via WorkflowApplication. |
| impl/core/src/main/java/io/serverlessworkflow/impl/auth/OpenIdAuthProvider.java | Threads WorkflowApplication through to shared OAuth token resolution. |
| impl/core/src/main/java/io/serverlessworkflow/impl/auth/OAuth2AuthProvider.java | Threads WorkflowApplication through to shared OAuth token resolution. |
| impl/core/src/main/java/io/serverlessworkflow/impl/auth/CommonOAuthProvider.java | Replaces static SPI singletons with application-scoped SPI lookups. |
| fluent/spec/src/test/java/io/serverlessworkflow/fluent/spec/WorkflowBuilderTest.java | Adds coverage for empty-task-list behavior. |
| fluent/spec/src/test/java/io/serverlessworkflow/fluent/spec/dsl/CallAsyncApiDslTest.java | Adds AsyncAPI DSL tests covering publish/subscribe variants and auth. |
| fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/TaskItemListBuilder.java | Adds .asyncapi(...) task-item construction. |
| fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/spi/DoFluent.java | Wires AsyncAPI call fluent API into the Do fluent surface. |
| fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/spi/CallAsyncAPITaskFluent.java | Adds fluent methods to configure AsyncAPI call task details. |
| fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/spi/CallAsyncAPIFluent.java | Adds list-level fluent API for adding AsyncAPI call tasks. |
| fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/dsl/DSL.java | Exposes DSL.asyncapi() and DSL.call(CallAsyncAPIConfigurer) overloads. |
| fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/dsl/CallAsyncAPISpec.java | Implements the AsyncAPI DSL spec/configurer that records configuration steps. |
| fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/DoTaskBuilder.java | Adds AsyncAPI task wiring in the do-task builder. |
| fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/configurers/CallAsyncAPIConfigurer.java | Adds configurer type for call(asyncapi()). |
| fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/CallAsyncAPITaskBuilder.java | Adds builder backing the AsyncAPI call task fluent methods. |
| fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/BaseWorkflowBuilder.java | Changes behavior to throw when tasks are empty after configuration. |
| fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/BaseTaskItemListBuilder.java | Adds TYPE_ASYNCAPI constant used for naming/type defaults. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+139
to
+143
| if (newItems == null || newItems.isEmpty()) { | ||
| throw new IllegalStateException( | ||
| "Task list must contain at least one task. " | ||
| + "Use .tasks(d -> d.set(...)) or similar to define tasks."); | ||
| } |
Comment on lines
+713
to
+716
| @SuppressWarnings("unchecked") | ||
| public <T extends Comparable<?>> List<T> serviceLoadedClasses(Class<T> clazz) { | ||
| ServiceLoader<?> serviceLoader = servicesLoaded.computeIfAbsent(clazz, ServiceLoader::load); | ||
| return (List<T>) serviceLoader.stream().map(ServiceLoader.Provider::get).sorted().toList(); |
Comment on lines
+136
to
+140
| workflow | ||
| .definition() | ||
| .application() | ||
| .serviceLoadedClasses(EmittedEventDecorator.class) | ||
| .forEach(d -> d.decorate(ceBuilder, workflow, taskContext)); |
Comment on lines
+88
to
92
| private <T extends TaskBase> CallableTaskBuilder<T> findCallTask( | ||
| Class<T> clazz, WorkflowApplication app) { | ||
| List<CallableTaskBuilder> callTasks = app.serviceLoadedClasses(CallableTaskBuilder.class); | ||
| return (CallableTaskBuilder<T>) | ||
| callTasks.stream() |
Comment on lines
75
to
85
| private static WorkflowValueResolver<AccessTokenProvider> build( | ||
| OAuth2AuthenticationData authenticationData, AuthRequestBuilder authBuilder) { | ||
| OAuth2AuthenticationData authenticationData, | ||
| AuthRequestBuilder authBuilder, | ||
| WorkflowApplication app) { | ||
| AccessTokenProvider tokenProvider = | ||
| accessTokenProviderFactory.build( | ||
| authBuilder.apply(authenticationData), authenticationData.getIssuers(), jwtConverter); | ||
| app.serviceLoadedClass(AccessTokenProviderFactory.class) | ||
| .build( | ||
| authBuilder.apply(authenticationData), | ||
| authenticationData.getIssuers(), | ||
| app.serviceLoadedClass(JWTConverter.class)); | ||
| return (w, t, m) -> tokenProvider; |
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.
Many thanks for submitting your Pull Request ❤️!
What this PR does / why we need it:
Special notes for reviewers:
Additional information (if needed):