Skip to content

Name tasks on DSL class#1250

Open
mcruzdev wants to merge 1 commit intoserverlessworkflow:mainfrom
mcruzdev:issue-1249
Open

Name tasks on DSL class#1250
mcruzdev wants to merge 1 commit intoserverlessworkflow:mainfrom
mcruzdev:issue-1249

Conversation

@mcruzdev
Copy link
Collaborator

@mcruzdev mcruzdev commented Mar 20, 2026

This pull request enhances the Serverless Workflow fluent DSL by adding support for assigning explicit names to all major task types, improving clarity and flexibility when building workflows. It introduces new overloaded static methods in the DSL class to allow specifying task names, and adds comprehensive tests to ensure these features work as intended.

DSL Enhancements for Named Tasks:

  • Added overloaded static methods in DSL.java for all major task types (call, set, emit, listen, forEach, fork, switchCase, raise, tryCatch) to allow specifying explicit task names when building workflows. These methods improve the expressiveness and maintainability of workflow definitions. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]

  • Restored and documented the emit(String, Consumer<EmitTaskBuilder>) method in DSL.java to match the new naming pattern for consistency.

Testing Improvements:

  • Added new tests in WorkflowBuilderTest.java to verify that tasks can be named (including using reserved words like "set"), and to check that all task types accept and correctly handle explicit names via the DSL.
  • Expanded static imports in WorkflowBuilderTest.java to cover the newly overloaded DSL methods, improving test readability and maintainability.

@mcruzdev mcruzdev requested a review from fjtirado as a code owner March 20, 2026 18:27
Copilot AI review requested due to automatic review settings March 20, 2026 18:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Enhances the fluent workflow DSL to allow creating task configurers with explicit task names (instead of auto-generated UUIDs), improving readability and enabling use of reserved/duplicate names in workflow definitions.

Changes:

  • Added DSL overloads for major task types to accept an explicit name parameter (e.g., set(name, ...), call(name, ...), emit(name, ...), etc.).
  • Updated/expanded WorkflowBuilderTest to validate explicitly named tasks, including naming a task "set" and verifying multiple task types can be named.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/dsl/DSL.java Adds named overloads for task factory helpers returning TasksConfigurer.
fluent/spec/src/test/java/io/serverlessworkflow/fluent/spec/WorkflowBuilderTest.java Adds tests exercising named-task DSL usage and validating task names/types in the built workflow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +638 to +647
/**
* Create a {@link TasksConfigurer} that adds an OpenAPI call task with an explicit name.
*
* @param name the task name
* @param configurer OpenAPI configurer
* @return a {@link TasksConfigurer} that adds a CallOpenAPI task
*/
public static TasksConfigurer call(String name, CallOpenAPIConfigurer configurer) {
return list -> list.openapi(name, configurer);
}
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

The new overload call(String name, CallOpenAPIConfigurer) isn’t exercised by the test suite (current tests cover only the HTTP variant). Add a unit test that builds a workflow using call("name", openapi()...) and asserts the TaskItem name and that CallTask.callOpenAPI is present/configured, to prevent regressions in this overload.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@fjtirado fjtirado left a comment

Choose a reason for hiding this comment

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

@ricardozanini This adds the possibility of setting the task name through the dsl, but I think we also need to generate a consistent task name rathern than a random one when the user does not specify one.
I propose to use "taskType"+autoIncrementId, where the counter start at for every new defitinion, this way, the task name will always be the same if the definition is unchanged

Copilot AI review requested due to automatic review settings March 21, 2026 03:35
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/dsl/DSL.java:699

  • The Javadoc for emit(Consumer<EmitTaskBuilder>) has stray * characters at the ends of sentences (e.g., "using a custom configurer. *" and similar). This renders poorly and may trigger Javadoc lint warnings; please remove the trailing * characters so the comment is valid Javadoc.
  /**
   * Adds an {@code emit} task to the workflow's task sequence using a custom configurer. *
   *
   * <p>This method is typically used in conjunction with {@link #produced()} to fluently define the
   * properties of the event being emitted. *
   *

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +143 to +144
d ->
d.set("set", "$.value = 'test'").set("set", s -> s.expr("$.another = 'value'")))
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

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

testTaskNamedSet() is described as verifying naming via the DSL, but it only uses the DoTaskBuilder#set(String, ...) instance methods (which already support explicit names). To specifically cover this PR’s new DSL overloads, consider either rewriting this test to use the static DSL.set("set", ...) helpers (like the next test does) or removing/renaming it to avoid redundant coverage.

Suggested change
d ->
d.set("set", "$.value = 'test'").set("set", s -> s.expr("$.another = 'value'")))
doTasks(
set("set", "$.value = 'test'"),
set("set", s -> s.expr("$.another = 'value'"))))

Copilot uses AI. Check for mistakes.
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.

3 participants