Skip to content

Commit 9c68ef2

Browse files
committed
Constanst.setRefValue() was always null
Setting the ref value when constant is an uri to allow implementations to try load them in case default loading fails Signed-off-by: Francisco Javier Tirado Sarti <[email protected]>
1 parent 96cc7a6 commit 9c68ef2

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

api/src/main/java/io/serverlessworkflow/api/deserializers/ConstantsDeserializer.java

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public Constants deserialize(JsonParser jp, DeserializationContext ctxt) throws
6262
constantsDefinition = node;
6363
} else {
6464
String constantsFileDef = node.asText();
65+
constants.setRefValue(constantsFileDef);
6566
String constantsFileSrc = Utils.getResourceFileAsString(constantsFileDef);
6667
JsonNode constantsRefNode;
6768
ObjectMapper jsonWriter = new ObjectMapper();

api/src/main/java/io/serverlessworkflow/api/serializers/WorkflowSerializer.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,12 @@ public void serialize(Workflow workflow, JsonGenerator gen, SerializerProvider p
159159
gen.writeEndArray();
160160
}
161161

162-
if (workflow.getConstants() != null && !workflow.getConstants().getConstantsDef().isEmpty()) {
163-
gen.writeObjectField("constants", workflow.getConstants().getConstantsDef());
162+
if (workflow.getConstants() != null) {
163+
if (!workflow.getConstants().getConstantsDef().isEmpty()) {
164+
gen.writeObjectField("constants", workflow.getConstants().getConstantsDef());
165+
} else if (workflow.getConstants().getRefValue() != null) {
166+
gen.writeStringField("constants", workflow.getConstants().getRefValue());
167+
}
164168
}
165169

166170
if (workflow.getTimeouts() != null) {

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

+17
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,23 @@ public void testConstants(String workflowLocation) {
569569
JsonNode serbianTranslationNode = translationDogNode.get("Serbian");
570570
assertEquals("pas", serbianTranslationNode.asText());
571571
}
572+
573+
574+
@ParameterizedTest
575+
@ValueSource(strings = {"/features/constantsRef.json", "/features/constantsRef.yml"})
576+
public void testConstantsRef(String workflowLocation) {
577+
Workflow workflow = Workflow.fromSource(WorkflowTestUtils.readWorkflowFile(workflowLocation));
578+
579+
assertNotNull(workflow);
580+
assertNotNull(workflow.getId());
581+
assertNotNull(workflow.getName());
582+
assertNotNull(workflow.getStates());
583+
584+
assertNotNull(workflow.getConstants());
585+
Constants constants = workflow.getConstants();
586+
assertNotNull(constants.getRefValue());
587+
}
588+
572589

573590
@ParameterizedTest
574591
@ValueSource(strings = {"/features/timeouts.json", "/features/timeouts.yml"})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"id": "secrets",
3+
"version": "1.0",
4+
"specVersion": "0.8",
5+
"name": "Custom secrets flow",
6+
"expressionLang": "abc",
7+
"start": "TestFunctionRefs",
8+
"constants": "contantsValues.json",
9+
"states": [
10+
{
11+
"name": "TestFunctionRefs",
12+
"type": "operation",
13+
"actions": [],
14+
"end": true
15+
}
16+
]
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
id: secrets
2+
version: '1.0'
3+
specVersion: '0.8'
4+
name: Custom secrets flow
5+
expressionLang: abc
6+
start: TestFunctionRefs
7+
constants:
8+
constantValues.json
9+
states:
10+
- name: TestFunctionRefs
11+
type: operation
12+
actionMode: sequential
13+
actions:
14+
end: true

0 commit comments

Comments
 (0)