Skip to content

Commit c2ee799

Browse files
committed
Adjust openapi step
Signed-off-by: Ricardo Zanini <[email protected]>
1 parent 9a16384 commit c2ee799

File tree

8 files changed

+235
-138
lines changed

8 files changed

+235
-138
lines changed

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

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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.fluent.func.FuncCallHttpTaskBuilder;
19+
import io.serverlessworkflow.fluent.func.FuncTaskItemListBuilder;
20+
import io.serverlessworkflow.fluent.spec.dsl.BaseCallHttpSpec;
21+
import io.serverlessworkflow.fluent.spec.spi.CallHttpTaskFluent;
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
import java.util.function.Consumer;
25+
26+
public class FuncCallHttpStep extends Step<FuncCallHttpStep, FuncCallHttpTaskBuilder>
27+
implements BaseCallHttpSpec<FuncCallHttpStep> {
28+
29+
private final List<Consumer<CallHttpTaskFluent<?>>> steps = new ArrayList<>();
30+
31+
private String name;
32+
33+
public FuncCallHttpStep(String name) {
34+
this.name = name;
35+
}
36+
37+
public FuncCallHttpStep() {}
38+
39+
@Override
40+
public FuncCallHttpStep self() {
41+
return this;
42+
}
43+
44+
protected void configure(FuncTaskItemListBuilder list, Consumer<FuncCallHttpTaskBuilder> post) {
45+
if (name == null) {
46+
list.http(
47+
builder -> {
48+
// Apply HTTP config (BaseCallHttpSpec)
49+
this.accept(builder); // default method from BaseCallHttpSpec
50+
// Apply Step’s post-configurers (when / inputFrom / outputAs / exportAs)
51+
post.accept(builder);
52+
});
53+
} else {
54+
list.http(
55+
name,
56+
builder -> {
57+
this.accept(builder);
58+
post.accept(builder);
59+
});
60+
}
61+
}
62+
63+
@Override
64+
public List<Consumer<CallHttpTaskFluent<?>>> steps() {
65+
return steps;
66+
}
67+
}
Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import io.serverlessworkflow.api.types.OpenAPIArguments;
1919
import io.serverlessworkflow.fluent.func.FuncCallOpenAPITaskBuilder;
20-
import io.serverlessworkflow.fluent.func.configurers.FuncCallOpenAPIConfigurer;
20+
import io.serverlessworkflow.fluent.func.FuncTaskItemListBuilder;
2121
import io.serverlessworkflow.fluent.spec.configurers.AuthenticationConfigurer;
2222
import io.serverlessworkflow.fluent.spec.spi.CallOpenAPITaskFluent;
2323
import java.net.URI;
@@ -26,65 +26,93 @@
2626
import java.util.Map;
2727
import java.util.function.Consumer;
2828

29-
public class FuncCallOpenAPISpec implements FuncCallOpenAPIConfigurer {
29+
public class FuncCallOpenAPIStep extends Step<FuncCallOpenAPIStep, FuncCallOpenAPITaskBuilder> {
3030

3131
private final List<Consumer<CallOpenAPITaskFluent<?>>> steps = new ArrayList<>();
3232

33-
public FuncCallOpenAPISpec document(String uri) {
33+
private String name;
34+
35+
public FuncCallOpenAPIStep(String name) {
36+
this.name = name;
37+
}
38+
39+
public FuncCallOpenAPIStep() {}
40+
41+
public void setName(String name) {
42+
this.name = name;
43+
}
44+
45+
public FuncCallOpenAPIStep document(String uri) {
3446
steps.add(b -> b.document(uri));
3547
return this;
3648
}
3749

38-
public FuncCallOpenAPISpec document(
50+
public FuncCallOpenAPIStep document(
3951
String uri, AuthenticationConfigurer authenticationConfigurer) {
4052
steps.add(b -> b.document(uri, authenticationConfigurer));
4153
return this;
4254
}
4355

44-
public FuncCallOpenAPISpec document(URI uri) {
56+
public FuncCallOpenAPIStep document(URI uri) {
4557
steps.add(b -> b.document(uri));
4658
return this;
4759
}
4860

49-
public FuncCallOpenAPISpec document(URI uri, AuthenticationConfigurer authenticationConfigurer) {
61+
public FuncCallOpenAPIStep document(URI uri, AuthenticationConfigurer authenticationConfigurer) {
5062
steps.add(b -> b.document(uri, authenticationConfigurer));
5163
return this;
5264
}
5365

54-
public FuncCallOpenAPISpec operation(String operationId) {
66+
public FuncCallOpenAPIStep operation(String operationId) {
5567
steps.add(b -> b.operation(operationId));
5668
return this;
5769
}
5870

59-
public FuncCallOpenAPISpec parameters(Map<String, Object> params) {
71+
public FuncCallOpenAPIStep parameters(Map<String, Object> params) {
6072
steps.add(b -> b.parameters(params));
6173
return this;
6274
}
6375

64-
public FuncCallOpenAPISpec parameter(String name, String value) {
76+
public FuncCallOpenAPIStep parameter(String name, String value) {
6577
steps.add(b -> b.parameter(name, value));
6678
return this;
6779
}
6880

69-
public FuncCallOpenAPISpec redirect(boolean redirect) {
81+
public FuncCallOpenAPIStep redirect(boolean redirect) {
7082
steps.add(b -> b.redirect(redirect));
7183
return this;
7284
}
7385

74-
public FuncCallOpenAPISpec authentication(AuthenticationConfigurer authenticationConfigurer) {
86+
public FuncCallOpenAPIStep authentication(AuthenticationConfigurer authenticationConfigurer) {
7587
steps.add(b -> b.authentication(authenticationConfigurer));
7688
return this;
7789
}
7890

79-
public FuncCallOpenAPISpec output(OpenAPIArguments.WithOpenAPIOutput output) {
91+
public FuncCallOpenAPIStep output(OpenAPIArguments.WithOpenAPIOutput output) {
8092
steps.add(b -> b.output(output));
8193
return this;
8294
}
8395

8496
@Override
85-
public void accept(FuncCallOpenAPITaskBuilder builder) {
86-
for (var s : steps) {
87-
s.accept(builder);
97+
protected void configure(
98+
FuncTaskItemListBuilder list, Consumer<FuncCallOpenAPITaskBuilder> post) {
99+
if (name == null) {
100+
list.openapi(
101+
builder -> {
102+
for (Consumer<CallOpenAPITaskFluent<?>> c : steps) {
103+
c.accept(builder); // OpenAPI DSL
104+
}
105+
post.accept(builder); // when/inputFrom/outputAs/exportAs
106+
});
107+
} else {
108+
list.openapi(
109+
name,
110+
builder -> {
111+
for (Consumer<CallOpenAPITaskFluent<?>> c : steps) {
112+
c.accept(builder);
113+
}
114+
post.accept(builder);
115+
});
88116
}
89117
}
90118
}

0 commit comments

Comments
 (0)