Skip to content

Commit 42f1a90

Browse files
committed
refactor: simplify JSON Schema validation setup and update factorypath to use version 7.0.5-SNAPSHOT
1 parent 3974f47 commit 42f1a90

2 files changed

Lines changed: 13 additions & 16 deletions

File tree

core/src/main/java/com/predic8/membrane/core/interceptor/schemavalidation/json/JSONYAMLSchemaValidator.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public class JSONYAMLSchemaValidator extends AbstractMessageValidator {
4949

5050
private final YAMLFactory factory = YAMLFactory.builder().enable(STRICT_DUPLICATE_DETECTION).build();
5151
private final ObjectMapper yamlObjectMapper = new ObjectMapper(factory);
52-
private final ObjectMapper jsonObjectMapper = new ObjectMapper();
5352

5453
public static final String SCHEMA_VERSION_2020_12 = "2020-12";
5554

@@ -63,11 +62,6 @@ public class JSONYAMLSchemaValidator extends AbstractMessageValidator {
6362

6463
private Map<String, String> schemaMappings = new HashMap<>();
6564

66-
/**
67-
* JsonSchemaFactory instances are thread-safe provided its configuration is not modified.
68-
*/
69-
SchemaRegistry jsonSchemaFactory;
70-
7165
/**
7266
* JsonSchema instances are thread-safe provided its configuration is not modified.
7367
*/
@@ -100,22 +94,25 @@ public String getName() {
10094
public void init() {
10195
super.init();
10296

103-
jsonSchemaFactory = SchemaRegistry.withDefaultDialect(schemaId, b -> b.schemaLoader(SchemaLoader.builder()
104-
.schemaIdResolvers(r -> r.mappings(schemaMappings))
105-
.resourceLoaders(rl -> rl.values(list -> list.addFirst(new MembraneSchemaLoader(resolver))))
106-
.build()));
107-
10897
try (InputStream in = resolver.resolve(jsonSchema)) {
109-
InputFormat schemaFormat =
110-
(jsonSchema.endsWith(".yaml") || jsonSchema.endsWith(".yml")) ? YAML : JSON;
111-
112-
schema = jsonSchemaFactory.getSchema(SchemaLocation.of(jsonSchema), in, schemaFormat);
98+
schema = getJsonSchemaFactory().getSchema(SchemaLocation.of(jsonSchema), in, getSchemaFormat());
11399
schema.initializeValidators();
114100
} catch (IOException e) {
115101
throw new RuntimeException("Cannot read JSON Schema from: " + jsonSchema, e);
116102
}
117103
}
118104

105+
private @NotNull InputFormat getSchemaFormat() {
106+
return (jsonSchema.endsWith(".yaml") || jsonSchema.endsWith(".yml")) ? YAML : JSON;
107+
}
108+
109+
private SchemaRegistry getJsonSchemaFactory() {
110+
return SchemaRegistry.withDefaultDialect(schemaId, b -> b.schemaLoader(SchemaLoader.builder()
111+
.schemaIdResolvers(r -> r.mappings(schemaMappings))
112+
.resourceLoaders(rl -> rl.values(list -> list.addFirst(new MembraneSchemaLoader(resolver))))
113+
.build()));
114+
}
115+
119116
public Outcome validateMessage(Exchange exc, Flow flow) throws Exception {
120117
return validateMessage(exc, flow, UTF_8);
121118
}

war/.factorypath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?><factorypath>
2-
<factorypathentry enabled="true" id="M2_REPO/org/membrane-soa/service-proxy-annot/6.3.12-SNAPSHOT/service-proxy-annot-6.3.12-SNAPSHOT.jar" kind="VARJAR" runInBatchMode="false"/>
2+
<factorypathentry enabled="true" id="M2_REPO/org/membrane-soa/service-proxy-annot/7.0.5-SNAPSHOT/service-proxy-annot-7.0.5-SNAPSHOT.jar" kind="VARJAR" runInBatchMode="false"/>
33
</factorypath>

0 commit comments

Comments
 (0)