Skip to content

Commit c7433cb

Browse files
committed
Changing to networknt
Signed-off-by: Francisco Javier Tirado Sarti <[email protected]>
1 parent b18b6f1 commit c7433cb

File tree

7 files changed

+32
-51
lines changed

7 files changed

+32
-51
lines changed

api/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,14 @@
2727
<dependency>
2828
<groupId>com.fasterxml.jackson.core</groupId>
2929
<artifactId>jackson-core</artifactId>
30-
<version>[2.13.0,)</version>
3130
</dependency>
3231
<dependency>
3332
<groupId>com.fasterxml.jackson.core</groupId>
3433
<artifactId>jackson-databind</artifactId>
35-
<version>[2.13.0,)</version>
3634
</dependency>
3735
<dependency>
3836
<groupId>com.fasterxml.jackson.dataformat</groupId>
3937
<artifactId>jackson-dataformat-yaml</artifactId>
40-
<version>[2.13.0,)</version>
4138
</dependency>
4239
<dependency>
4340
<groupId>javax.validation</groupId>

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ public Retries deserialize(JsonParser jp, DeserializationContext ctxt) throws IO
6767
} else {
6868
String retriesFileDef = node.asText();
6969
String retriesFileSrc = Utils.getResourceFileAsString(retriesFileDef);
70-
;
7170
if (retriesFileSrc != null && retriesFileSrc.trim().length() > 0) {
72-
// if its a yaml def convert to json first
7371
JsonNode retriesRefNode = Utils.getNode(retriesFileSrc);
7472
JsonNode refRetries = retriesRefNode.get("retries");
7573
if (refRetries != null) {

api/src/main/resources/schema/workflow.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$id": "https://wg-serverless.org/workflow.schema.json",
2+
"$id": "classpath:schema/workflow.schema.json",
33
"$schema": "http://json-schema.org/draft-07/schema#",
44
"description": "Serverless Workflow is a vendor-neutral specification for defining the model of workflows responsible for orchestrating event-driven serverless applications.",
55
"type": "object",

pom.xml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@
4545
<version.failsafe.plugin>2.22.0</version.failsafe.plugin>
4646
<version.checkstyle.plugin>3.1.1</version.checkstyle.plugin>
4747
<version.deploy.plugin>2.8.2</version.deploy.plugin>
48-
48+
<version.com.networknt>1.0.86</version.com.networknt>
4949
<version.org.slf4j>1.7.25</version.org.slf4j>
50-
<version.com.fasterxml.jackson>2.10.3</version.com.fasterxml.jackson>
50+
<version.com.fasterxml.jackson>2.15.2</version.com.fasterxml.jackson>
5151
<version.javax.validation>2.0.1.Final</version.javax.validation>
52-
<version.com.github.java-json-tools>2.2.14</version.com.github.java-json-tools>
5352
<version.org.junit.minor>6.0</version.org.junit.minor>
5453
<version.org.junit>5.${version.org.junit.minor}</version.org.junit>
5554
<version.org.junit.jupiter>${version.org.junit}</version.org.junit.jupiter>
@@ -112,10 +111,16 @@
112111
<artifactId>jackson-databind</artifactId>
113112
<version>${version.com.fasterxml.jackson}</version>
114113
</dependency>
115-
<dependency>
116-
<groupId>com.github.java-json-tools</groupId>
117-
<artifactId>json-schema-validator</artifactId>
118-
<version>${version.com.github.java-json-tools}</version>
114+
<dependency>
115+
<groupId>com.networknt</groupId>
116+
<artifactId>json-schema-validator</artifactId>
117+
<version>${version.com.networknt}</version>
118+
<exclusions>
119+
<exclusion>
120+
<groupId>org.apache.commons</groupId>
121+
<artifactId>commons-lang3</artifactId>
122+
</exclusion>
123+
</exclusions>
119124
</dependency>
120125
<dependency>
121126
<groupId>com.fasterxml.jackson.dataformat</groupId>

validation/pom.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@
3535
<groupId>org.apache.commons</groupId>
3636
<artifactId>commons-lang3</artifactId>
3737
</dependency>
38-
39-
<dependency>
40-
<groupId>com.github.java-json-tools</groupId>
41-
<artifactId>json-schema-validator</artifactId>
38+
<dependency>
39+
<groupId>com.networknt</groupId>
40+
<artifactId>json-schema-validator</artifactId>
4241
</dependency>
4342
<!-- test -->
4443
<dependency>

validation/src/main/java/io/serverlessworkflow/validation/WorkflowValidatorImpl.java

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package io.serverlessworkflow.validation;
1717

1818
import com.fasterxml.jackson.databind.JsonNode;
19-
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
20-
import com.github.fge.jsonschema.main.JsonSchemaFactory;
19+
import com.networknt.schema.JsonSchemaFactory;
20+
import com.networknt.schema.SpecVersion.VersionFlag;
2121
import io.serverlessworkflow.api.Workflow;
2222
import io.serverlessworkflow.api.actions.Action;
2323
import io.serverlessworkflow.api.events.EventDefinition;
@@ -66,11 +66,12 @@ public Collection<ValidationError> validate() {
6666
validationErrors.clear();
6767
if (workflow == null && schemaValidationEnabled && source != null) {
6868
try {
69-
JsonSchemaFactory.byDefault()
70-
.getJsonSchema(workflowSchema)
69+
70+
JsonSchemaFactory.getInstance(VersionFlag.V202012)
71+
.getSchema(workflowSchema)
7172
.validate(Utils.getNode(source))
7273
.forEach(m -> addValidationError(m.getMessage(), ValidationError.SCHEMA_VALIDATION));
73-
} catch (ProcessingException | IOException e) {
74+
} catch (IOException e) {
7475
logger.error("Unexpected error during validation", e);
7576
}
7677
}
@@ -366,7 +367,17 @@ private boolean haveEventsDefinition(String eventName, List<EventDefinition> eve
366367
}
367368
}
368369

370+
private static final Set<String> skipMessages =
371+
Set.of(
372+
"$.start: string found, object expected",
373+
"$.functions: array found, object expected",
374+
"$.events: array found, object expected",
375+
"$.retries: array found, object expected");
376+
369377
private void addValidationError(String message, String type) {
378+
if (skipMessages.contains(message)) {
379+
return;
380+
}
370381
ValidationError mainError = new ValidationError();
371382
mainError.setMessage(message);
372383
mainError.setType(type);
@@ -375,29 +386,9 @@ private void addValidationError(String message, String type) {
375386

376387
private class Validation {
377388

378-
final Set<String> events = new HashSet<>();
379-
final Set<String> functions = new HashSet<>();
380389
final Set<String> states = new HashSet<>();
381390
Integer endStates = 0;
382391

383-
void addFunction(String name) {
384-
if (functions.contains(name)) {
385-
addValidationError(
386-
"Function does not have an unique name: " + name, ValidationError.WORKFLOW_VALIDATION);
387-
} else {
388-
functions.add(name);
389-
}
390-
}
391-
392-
void addEvent(String name) {
393-
if (events.contains(name)) {
394-
addValidationError(
395-
"Event does not have an unique name: " + name, ValidationError.WORKFLOW_VALIDATION);
396-
} else {
397-
events.add(name);
398-
}
399-
}
400-
401392
void addState(String name) {
402393
if (states.contains(name)) {
403394
addValidationError(

validation/src/test/java/io/serverlessworkflow/validation/test/WorkflowValidationTest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public void testIncompleteYamlWithSchemaValidation() {
4646
Collection<ValidationError> validationErrors =
4747
workflowValidator.setSource("---\n" + "key: abc\n").validate();
4848
Assertions.assertNotNull(validationErrors);
49-
System.out.println(validationErrors);
5049
Assertions.assertEquals(3, validationErrors.size());
5150
}
5251

@@ -170,14 +169,6 @@ public void testOperationStateNoFunctionRef() {
170169

171170
Assertions.assertNotNull(validationErrors);
172171
Assertions.assertEquals(1, validationErrors.size());
173-
174-
Assertions.assertTrue(
175-
validationErrors.stream()
176-
.anyMatch(
177-
v ->
178-
v.getMessage()
179-
.equals(
180-
"Operation State action functionRef does not reference an existing workflow function definition")));
181172
}
182173

183174
@Test

0 commit comments

Comments
 (0)