Skip to content

Commit d778461

Browse files
committed
Added openapi support
Signed-off-by: Ricardo Zanini <[email protected]>
1 parent 343b960 commit d778461

26 files changed

+868
-105
lines changed

experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/FuncCallHttpTaskBuilder.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,8 @@ public class FuncCallHttpTaskBuilder extends TaskBaseBuilder<FuncCallHttpTaskBui
2727
FuncTaskTransformations<FuncCallHttpTaskBuilder>,
2828
ConditionalTaskBuilder<FuncCallHttpTaskBuilder> {
2929

30-
private final CallHTTP callHTTP;
31-
32-
protected FuncCallHttpTaskBuilder() {
33-
callHTTP = new CallHTTP();
34-
callHTTP.setWith(new HTTPArguments());
35-
callHTTP.getWith().setOutput(HTTPArguments.HTTPOutput.CONTENT);
36-
super.setTask(this.callHTTP);
37-
}
38-
39-
@Override
40-
public CallHTTP build() {
41-
return callHTTP;
30+
FuncCallHttpTaskBuilder() {
31+
super.setTask(new CallHTTP().withWith(new HTTPArguments()));
4232
}
4333

4434
@Override
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.fluent.func;
17+
18+
import io.serverlessworkflow.api.types.CallOpenAPI;
19+
import io.serverlessworkflow.api.types.OpenAPIArguments;
20+
import io.serverlessworkflow.api.types.WithOpenAPIParameters;
21+
import io.serverlessworkflow.fluent.func.spi.ConditionalTaskBuilder;
22+
import io.serverlessworkflow.fluent.func.spi.FuncTaskTransformations;
23+
import io.serverlessworkflow.fluent.spec.TaskBaseBuilder;
24+
import io.serverlessworkflow.fluent.spec.spi.CallOpenAPITaskFluent;
25+
26+
public class FuncCallOpenAPITaskBuilder extends TaskBaseBuilder<FuncCallOpenAPITaskBuilder>
27+
implements CallOpenAPITaskFluent<FuncCallOpenAPITaskBuilder>,
28+
FuncTaskTransformations<FuncCallOpenAPITaskBuilder>,
29+
ConditionalTaskBuilder<FuncCallOpenAPITaskBuilder> {
30+
31+
FuncCallOpenAPITaskBuilder() {
32+
final CallOpenAPI callOpenAPI = new CallOpenAPI();
33+
callOpenAPI.setWith(new OpenAPIArguments().withParameters(new WithOpenAPIParameters()));
34+
super.setTask(callOpenAPI);
35+
}
36+
37+
@Override
38+
public FuncCallOpenAPITaskBuilder self() {
39+
return this;
40+
}
41+
}

experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/FuncDoTaskBuilder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,11 @@ public FuncDoTaskBuilder http(String name, Consumer<FuncCallHttpTaskBuilder> ite
8989
this.listBuilder().http(name, itemsConfigurer);
9090
return this;
9191
}
92+
93+
@Override
94+
public FuncDoTaskBuilder openapi(
95+
String name, Consumer<FuncCallOpenAPITaskBuilder> itemsConfigurer) {
96+
this.listBuilder().openapi(name, itemsConfigurer);
97+
return this;
98+
}
9299
}

experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/FuncTaskItemListBuilder.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package io.serverlessworkflow.fluent.func;
1717

1818
import io.serverlessworkflow.api.types.CallHTTP;
19+
import io.serverlessworkflow.api.types.CallOpenAPI;
1920
import io.serverlessworkflow.api.types.CallTask;
2021
import io.serverlessworkflow.api.types.Task;
2122
import io.serverlessworkflow.api.types.TaskItem;
@@ -123,8 +124,10 @@ public FuncTaskItemListBuilder fork(String name, Consumer<FuncForkTaskBuilder> i
123124
public FuncTaskItemListBuilder http(
124125
String name, Consumer<FuncCallHttpTaskBuilder> itemsConfigurer) {
125126
name = this.defaultNameAndRequireConfig(name, itemsConfigurer);
127+
126128
final FuncCallHttpTaskBuilder httpTaskJavaBuilder = new FuncCallHttpTaskBuilder();
127129
itemsConfigurer.accept(httpTaskJavaBuilder);
130+
128131
final CallHTTP callHTTP = httpTaskJavaBuilder.build();
129132
final CallTask callTask = new CallTask();
130133
callTask.setCallHTTP(callHTTP);
@@ -133,4 +136,21 @@ public FuncTaskItemListBuilder http(
133136

134137
return this.addTaskItem(new TaskItem(name, task));
135138
}
139+
140+
@Override
141+
public FuncTaskItemListBuilder openapi(
142+
String name, Consumer<FuncCallOpenAPITaskBuilder> itemsConfigurer) {
143+
name = this.defaultNameAndRequireConfig(name, itemsConfigurer);
144+
145+
final FuncCallOpenAPITaskBuilder openAPITaskBuilder = new FuncCallOpenAPITaskBuilder();
146+
itemsConfigurer.accept(openAPITaskBuilder);
147+
148+
final CallOpenAPI callOpenAPI = openAPITaskBuilder.build();
149+
final CallTask callTask = new CallTask();
150+
callTask.setCallOpenAPI(callOpenAPI);
151+
final Task task = new Task();
152+
task.setCallTask(callTask);
153+
154+
return this.addTaskItem(new TaskItem(name, task));
155+
}
136156
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.fluent.func.configurers;
17+
18+
import io.serverlessworkflow.fluent.func.FuncCallOpenAPITaskBuilder;
19+
import java.util.function.Consumer;
20+
21+
@FunctionalInterface
22+
public interface FuncCallOpenAPIConfigurer extends Consumer<FuncCallOpenAPITaskBuilder> {}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.fluent.func.dsl;
17+
18+
import io.serverlessworkflow.api.types.OpenAPIArguments;
19+
import io.serverlessworkflow.fluent.func.FuncCallOpenAPITaskBuilder;
20+
import io.serverlessworkflow.fluent.func.configurers.FuncCallOpenAPIConfigurer;
21+
import io.serverlessworkflow.fluent.spec.configurers.AuthenticationConfigurer;
22+
import io.serverlessworkflow.fluent.spec.spi.CallOpenAPITaskFluent;
23+
import java.net.URI;
24+
import java.util.ArrayList;
25+
import java.util.List;
26+
import java.util.Map;
27+
import java.util.function.Consumer;
28+
29+
public class FuncCallOpenAPISpec implements FuncCallOpenAPIConfigurer {
30+
31+
private final List<Consumer<CallOpenAPITaskFluent<?>>> steps = new ArrayList<>();
32+
33+
public FuncCallOpenAPISpec document(String uri) {
34+
steps.add(b -> b.document(uri));
35+
return this;
36+
}
37+
38+
public FuncCallOpenAPISpec document(
39+
String uri, AuthenticationConfigurer authenticationConfigurer) {
40+
steps.add(b -> b.document(uri, authenticationConfigurer));
41+
return this;
42+
}
43+
44+
public FuncCallOpenAPISpec document(URI uri) {
45+
steps.add(b -> b.document(uri));
46+
return this;
47+
}
48+
49+
public FuncCallOpenAPISpec document(URI uri, AuthenticationConfigurer authenticationConfigurer) {
50+
steps.add(b -> b.document(uri, authenticationConfigurer));
51+
return this;
52+
}
53+
54+
public FuncCallOpenAPISpec operation(String operationId) {
55+
steps.add(b -> b.operation(operationId));
56+
return this;
57+
}
58+
59+
public FuncCallOpenAPISpec parameters(Map<String, Object> params) {
60+
steps.add(b -> b.parameters(params));
61+
return this;
62+
}
63+
64+
public FuncCallOpenAPISpec parameter(String name, String value) {
65+
steps.add(b -> b.parameter(name, value));
66+
return this;
67+
}
68+
69+
public FuncCallOpenAPISpec redirect(boolean redirect) {
70+
steps.add(b -> b.redirect(redirect));
71+
return this;
72+
}
73+
74+
public FuncCallOpenAPISpec authentication(AuthenticationConfigurer authenticationConfigurer) {
75+
steps.add(b -> b.authentication(authenticationConfigurer));
76+
return this;
77+
}
78+
79+
public FuncCallOpenAPISpec output(OpenAPIArguments.WithOpenAPIOutput output) {
80+
steps.add(b -> b.output(output));
81+
return this;
82+
}
83+
84+
@Override
85+
public void accept(FuncCallOpenAPITaskBuilder builder) {
86+
for (var s : steps) {
87+
s.accept(builder);
88+
}
89+
}
90+
}

experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/FuncDSL.java

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,82 @@ public static FuncTaskConfigurer call(String name, FuncCallHttpSpec spec) {
926926
return call(name, spec::accept);
927927
}
928928

929+
/**
930+
* OpenAPI call using a fluent {@link FuncCallOpenAPISpec}.
931+
*
932+
* <p>This overload creates an unnamed OpenAPI call task.
933+
*
934+
* <pre>{@code
935+
* FuncWorkflowBuilder.workflow("openapi-call")
936+
* .tasks(
937+
* FuncDSL.call(
938+
* FuncDSL.openapi()
939+
* .document("https://petstore.swagger.io/v2/swagger.json", DSL.auth("openapi-auth"))
940+
* .operation("getPetById")
941+
* )
942+
* )
943+
* .build();
944+
* }</pre>
945+
*
946+
* @param spec fluent OpenAPI spec built via {@link #openapi()}
947+
* @return a {@link FuncTaskConfigurer} that adds an OpenAPI call task to the workflow
948+
*/
949+
public static FuncTaskConfigurer call(FuncCallOpenAPISpec spec) {
950+
return call(null, spec);
951+
}
952+
953+
/**
954+
* OpenAPI call using a fluent {@link FuncCallOpenAPISpec} with an explicit task name.
955+
*
956+
* <p>Example:
957+
*
958+
* <pre>{@code
959+
* FuncWorkflowBuilder.workflow("openapi-call-named")
960+
* .tasks(
961+
* FuncDSL.call(
962+
* "fetchPet",
963+
* FuncDSL.openapi()
964+
* .document("https://petstore.swagger.io/v2/swagger.json", DSL.auth("openapi-auth"))
965+
* .operation("getPetById")
966+
* .parameter("id", 123)
967+
* )
968+
* )
969+
* .build();
970+
* }</pre>
971+
*
972+
* @param name task name, or {@code null} for an anonymous task
973+
* @param spec fluent OpenAPI spec built via {@link #openapi()}
974+
* @return a {@link FuncTaskConfigurer} that adds a named OpenAPI call task
975+
*/
976+
public static FuncTaskConfigurer call(String name, FuncCallOpenAPISpec spec) {
977+
Objects.requireNonNull(spec, "spec");
978+
return list -> list.openapi(name, spec);
979+
}
980+
981+
/**
982+
* Create a new OpenAPI specification to be used with {@link #call(FuncCallOpenAPISpec)}.
983+
*
984+
* <p>Typical usage:
985+
*
986+
* <pre>{@code
987+
* FuncDSL.call(
988+
* FuncDSL.openapi()
989+
* .document("https://petstore.swagger.io/v2/swagger.json", DSL.auth("openapi-auth"))
990+
* .operation("getPetById")
991+
* .parameter("id", 123)
992+
* );
993+
* }</pre>
994+
*
995+
* <p>The returned spec is a fluent builder that records operations (document, operation,
996+
* parameters, authentication, etc.) and applies them to the underlying OpenAPI call task at build
997+
* time.
998+
*
999+
* @return a new {@link FuncCallOpenAPISpec}
1000+
*/
1001+
public static FuncCallOpenAPISpec openapi() {
1002+
return new FuncCallOpenAPISpec();
1003+
}
1004+
9291005
/**
9301006
* Create a new, empty HTTP specification to be used with {@link #call(FuncCallHttpSpec)}.
9311007
*
@@ -1095,11 +1171,11 @@ public static FuncTaskConfigurer get(String name, URI endpoint, AuthenticationCo
10951171
* }</pre>
10961172
*
10971173
* @param body HTTP request body (literal value or expression-compatible object)
1098-
* @param endpoint literal or expression for the endpoint URL
1174+
* @param endpointExpr literal or expression for the endpoint URL
10991175
* @return a {@link FuncTaskConfigurer} adding a {@code POST} HTTP task
11001176
*/
1101-
public static FuncTaskConfigurer post(Object body, String endpoint) {
1102-
return post(null, body, endpoint);
1177+
public static FuncTaskConfigurer post(Object body, String endpointExpr) {
1178+
return post(null, body, endpointExpr);
11031179
}
11041180

11051181
/**

experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/spi/FuncDoFluent.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package io.serverlessworkflow.fluent.func.spi;
1717

1818
import io.serverlessworkflow.fluent.func.FuncCallHttpTaskBuilder;
19+
import io.serverlessworkflow.fluent.func.FuncCallOpenAPITaskBuilder;
1920
import io.serverlessworkflow.fluent.func.FuncCallTaskBuilder;
2021
import io.serverlessworkflow.fluent.func.FuncEmitTaskBuilder;
2122
import io.serverlessworkflow.fluent.func.FuncForTaskBuilder;
@@ -24,6 +25,7 @@
2425
import io.serverlessworkflow.fluent.func.FuncSetTaskBuilder;
2526
import io.serverlessworkflow.fluent.func.FuncSwitchTaskBuilder;
2627
import io.serverlessworkflow.fluent.spec.spi.CallHttpFluent;
28+
import io.serverlessworkflow.fluent.spec.spi.CallOpenAPIFluent;
2729
import io.serverlessworkflow.fluent.spec.spi.EmitFluent;
2830
import io.serverlessworkflow.fluent.spec.spi.ForEachFluent;
2931
import io.serverlessworkflow.fluent.spec.spi.ForkFluent;
@@ -39,4 +41,5 @@ public interface FuncDoFluent<SELF extends FuncDoFluent<SELF>>
3941
ForkFluent<FuncForkTaskBuilder, SELF>,
4042
ListenFluent<FuncListenTaskBuilder, SELF>,
4143
CallFnFluent<FuncCallTaskBuilder, SELF>,
42-
CallHttpFluent<FuncCallHttpTaskBuilder, SELF> {}
44+
CallHttpFluent<FuncCallHttpTaskBuilder, SELF>,
45+
CallOpenAPIFluent<FuncCallOpenAPITaskBuilder, SELF> {}

0 commit comments

Comments
 (0)