Skip to content

Commit b306bad

Browse files
committed
docs: Make sure the DSL documentation reflects clearly the code
Signed-off-by: Matheus André <matheusandr2@gmail.com>
1 parent ac16ede commit b306bad

3 files changed

Lines changed: 30 additions & 25 deletions

File tree

‎experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/Step.java‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ public <T, R> SELF exportAs(Function<T, R> function, Class<T> taskResultClass) {
156156
/**
157157
* Shapes what the task exports for downstream consumers using a context-aware filter function.
158158
*
159-
* <p>This variant provides access to both workflow and task context, allowing you to inspect
160-
* metadata when shaping the export.
159+
* <p>This variant provides access to the task result, workflow context, and task context,
160+
* allowing you to inspect metadata when shaping the export.
161161
*
162-
* @param <T> the workflow context type
162+
* @param <T> the task result type
163163
* @param <R> the export type (what gets written in the context)
164-
* @param function the filter function with workflow and task context
164+
* @param function the filter function with task result, workflow context, and task context
165165
* @return this step for method chaining
166166
* @see io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations#exportAs(FilterFunction)
167167
*/
@@ -177,10 +177,10 @@ public <T, R> SELF exportAs(FilterFunction<T, R> function) {
177177
* Shapes what the task exports for downstream consumers using a context-aware filter function
178178
* with explicit input type.
179179
*
180-
* @param <T> the workflow context type
180+
* @param <T> the task result type
181181
* @param <R> the export type (what gets written in the context)
182-
* @param function the filter function with workflow and task context
183-
* @param taskResultClass the class of the workflow context type
182+
* @param function the filter function with task result, workflow context, and task context
183+
* @param taskResultClass the class of the task result type
184184
* @return this step for method chaining
185185
* @see io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations#exportAs(FilterFunction,
186186
* Class)
@@ -278,7 +278,7 @@ public SELF exportAs(String jqExpression) {
278278
*
279279
* <pre>{@code
280280
* agent("investmentAnalyst", analyst::analyse, InvestmentMemo.class)
281-
* .outputAs(memo -> Map.of("memo", memo))
281+
* .outputAs(taskOutput -> Map.of("memo", taskOutput))
282282
* .when(condition);
283283
* }</pre>
284284
*
@@ -318,20 +318,21 @@ public <T, R> SELF outputAs(Function<T, R> function, Class<T> taskResultClass) {
318318
* Shapes what gets written back into the workflow data document using a context-aware filter
319319
* function.
320320
*
321-
* <p>This variant provides access to both workflow and task context, allowing you to inspect
322-
* metadata, task input, and raw output when shaping the committed output.
321+
* <p>This variant provides access to the task result as the first lambda parameter, plus the
322+
* workflow and task context for metadata, task input, and raw output when shaping the committed
323+
* output.
323324
*
324325
* <p><strong>Example:</strong>
325326
*
326327
* <pre>{@code
327328
* get("fetchMarketData", "http://localhost:8081/market-data/{ticker}")
328-
* .outputAs((MarketDataSnapshot snapshot,
329+
* .outputAs((MarketDataSnapshot taskOutput,
329330
* WorkflowContextData wf,
330331
* TaskContextData task) -> {
331332
* var input = task.input().asMap().orElseThrow();
332333
* var rawBody = task.rawOutput().asText().orElseThrow();
333334
* return new InvestmentPrompt(
334-
* snapshot.ticker(),
335+
* taskOutput.ticker(),
335336
* input.get("objective").toString(),
336337
* rawBody
337338
* );

‎experimental/lambda/src/test/java/io/serverless/workflow/impl/executors/func/FuncDSLDataFlowTransformationHelpersTest.java‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import static io.serverlessworkflow.fluent.func.dsl.FuncDSL.function;
1919
import static io.serverlessworkflow.fluent.func.dsl.FuncDSL.input;
20-
import static io.serverlessworkflow.fluent.func.dsl.FuncDSL.output;
2120

2221
import io.serverlessworkflow.api.types.Workflow;
2322
import io.serverlessworkflow.fluent.func.FuncWorkflowBuilder;
@@ -82,11 +81,13 @@ void test_input_with_outputAs() {
8281
},
8382
Long.class)
8483
.outputAs(
85-
(object, workflowContext, taskContextData) -> {
86-
softly.assertThat(object).isEqualTo(15L);
84+
(Long taskOutput,
85+
WorkflowContextData workflowContext,
86+
TaskContextData taskContextData) -> {
87+
softly.assertThat(taskOutput).isEqualTo(15L);
8788
Long input = input(workflowContext, Long.class);
8889
softly.assertThat(input).isEqualTo(10L);
89-
return input + object;
90+
return input + taskOutput;
9091
},
9192
Long.class))
9293
.build();
@@ -119,10 +120,9 @@ void test_output_with_exportAs() {
119120
},
120121
Long.class)
121122
.exportAs(
122-
(Long object,
123+
(Long taskOutput,
123124
WorkflowContextData workflowContext,
124125
TaskContextData taskContextData) -> {
125-
Long taskOutput = output(taskContextData, Long.class);
126126
softly.assertThat(taskOutput).isEqualTo(15L);
127127
return taskOutput * 2;
128128
}))
@@ -178,10 +178,9 @@ void test_input_with_exportAs() {
178178
},
179179
Long.class)
180180
.exportAs(
181-
(Long object,
181+
(Long taskOutput,
182182
WorkflowContextData workflowContext,
183183
TaskContextData taskContextData) -> {
184-
Long taskOutput = output(taskContextData, Long.class);
185184
softly.assertThat(taskOutput).isEqualTo(15L);
186185
Long input = input(workflowContext, Long.class);
187186
softly.assertThat(input).isEqualTo(10L);

‎impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowUtils.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,16 @@ public static Optional<WorkflowFilter> buildWorkflowFilter(WorkflowApplication a
8282
}
8383

8484
public static Optional<WorkflowFilter> buildWorkflowFilter(WorkflowApplication app, ExportAs as) {
85-
return as != null
86-
? Optional.of(
87-
buildFilterFromStrObject(
88-
app.expressionFactory(), app.contextFactory(), as.getString(), as.getObject()))
89-
: Optional.empty();
85+
if (as == null) {
86+
return Optional.empty();
87+
}
88+
WorkflowFilter filter =
89+
buildFilterFromStrObject(
90+
app.expressionFactory(), app.contextFactory(), as.getString(), as.getObject());
91+
if (as.getString() == null && as.getObject() != null) {
92+
return Optional.of((w, t, m) -> filter.apply(w, t, t.rawOutput()));
93+
}
94+
return Optional.of(filter);
9095
}
9196

9297
public static WorkflowFilter buildWorkflowFilter(WorkflowApplication app, Object obj) {

0 commit comments

Comments
 (0)