Skip to content

Commit d0f17a0

Browse files
committed
[Fix #418] Adding const support
Signed-off-by: Javier <[email protected]>
1 parent 3823d60 commit d0f17a0

File tree

5 files changed

+80
-1
lines changed

5 files changed

+80
-1
lines changed

api/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<usePrimitives>true</usePrimitives>
102102
<useJakartaValidation>true</useJakartaValidation>
103103
<customRuleFactory>io.serverlessworkflow.generator.UnreferencedFactory</customRuleFactory>
104+
<customAnnotator>io.serverlessworkflow.generator.ConstAnnotator</customAnnotator>
104105
</configuration>
105106
<dependencies>
106107
<dependency>

api/src/test/java/io/serverlessworkflow/api/ApiTest.java

+19
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static io.serverlessworkflow.api.WorkflowReader.readWorkflowFromClasspath;
1919
import static org.assertj.core.api.Assertions.assertThat;
2020

21+
import io.serverlessworkflow.api.types.CallFunction;
2122
import io.serverlessworkflow.api.types.CallHTTP;
2223
import io.serverlessworkflow.api.types.CallTask;
2324
import io.serverlessworkflow.api.types.Task;
@@ -44,4 +45,22 @@ void testCallHTTPAPI() throws IOException {
4445
assertThat(httpCall.getWith().getMethod()).isEqualTo("get");
4546
}
4647
}
48+
49+
@Test
50+
void testCallFunctionAPIWithoutArguments() throws IOException {
51+
Workflow workflow = readWorkflowFromClasspath("features/callFunction.yaml");
52+
assertThat(workflow.getDo()).isNotEmpty();
53+
assertThat(workflow.getDo().get(0).getName()).isNotNull();
54+
assertThat(workflow.getDo().get(0).getTask()).isNotNull();
55+
Task task = workflow.getDo().get(0).getTask();
56+
CallTask callTask = task.getCallTask();
57+
assertThat(callTask).isNotNull();
58+
assertThat(callTask.get()).isInstanceOf(CallFunction.class);
59+
if (callTask.get() instanceof CallFunction) {
60+
CallFunction functionCall = callTask.getCallFunction();
61+
assertThat(functionCall).isNotNull();
62+
assertThat(callTask.getCallAsyncAPI()).isNull();
63+
assertThat(functionCall.getWith()).isNull();
64+
}
65+
}
4766
}

api/src/test/java/io/serverlessworkflow/api/FeaturesTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public class FeaturesTest {
4343
"features/set.yaml",
4444
"features/switch.yaml",
4545
"features/try.yaml",
46-
"features/listen.yaml"
46+
"features/listen.yaml",
47+
"features/callFunction.yaml"
4748
})
4849
public void testSpecFeaturesParsing(String workflowLocation) throws IOException {
4950
Workflow workflow = readWorkflowFromClasspath(workflowLocation);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
document:
2+
dsl: 1.0.0-alpha1
3+
namespace: default
4+
name: http-call-with-response-output
5+
6+
use:
7+
functions:
8+
getPet:
9+
call: http
10+
with:
11+
method: get
12+
endpoint:
13+
uri: https://petstore.swagger.io/v2/pet/{petId}
14+
output: response
15+
16+
do:
17+
- getPetFunctionCall:
18+
call: getPet
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.generator;
17+
18+
import com.fasterxml.jackson.databind.JsonNode;
19+
import com.sun.codemodel.JDefinedClass;
20+
import com.sun.codemodel.JFieldVar;
21+
import jakarta.validation.constraints.Pattern;
22+
import org.jsonschema2pojo.AbstractAnnotator;
23+
import org.jsonschema2pojo.GenerationConfig;
24+
25+
public class ConstAnnotator extends AbstractAnnotator {
26+
27+
private static final String CONST = "const";
28+
29+
public ConstAnnotator(GenerationConfig generationConfig) {
30+
super(generationConfig);
31+
}
32+
33+
@Override
34+
public void propertyField(
35+
JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) {
36+
if (propertyNode.has(CONST)) {
37+
field.annotate(Pattern.class).param("regexp", propertyNode.get(CONST).asText());
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)