Skip to content

Commit bbff591

Browse files
committed
Rename JsonSchemaFactory to SchemaRegistry
1 parent e2125c6 commit bbff591

File tree

141 files changed

+388
-388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+388
-388
lines changed

src/main/java/com/networknt/schema/Schema.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
/**
4242
* Used for creating a schema with validators for validating inputs. This is
43-
* created using {@link JsonSchemaFactory#getInstance(Version, Consumer)}
43+
* created using {@link SchemaRegistry#getInstance(Version, Consumer)}
4444
* and should be cached for performance.
4545
* <p>
4646
* This is the core of json constraint implementation. It parses json constraint
@@ -1405,7 +1405,7 @@ public List<KeywordValidator> getValidators() {
14051405
* For avoiding issues with concurrency, in 1.0.49 the {@link com.networknt.schema.Schema} instances affiliated with
14061406
* validators were modified to no more preload the schema and lazy loading is used instead.
14071407
* <p>This comes with the issue that this way you cannot rely on validating important schema features, in particular
1408-
* <code>$ref</code> resolution at instantiation from {@link com.networknt.schema.JsonSchemaFactory}.</p>
1408+
* <code>$ref</code> resolution at instantiation from {@link com.networknt.schema.SchemaRegistry}.</p>
14091409
* <p>By calling <code>initializeValidators</code> you can enforce preloading of the {@link com.networknt.schema.Schema}
14101410
* instances of the validators.</p>
14111411
*/

src/main/java/com/networknt/schema/JsonSchemaFactory.java renamed to src/main/java/com/networknt/schema/SchemaRegistry.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
* JsonSchemaFactory instances are thread-safe provided its configuration is not
5555
* modified.
5656
*/
57-
public class JsonSchemaFactory {
58-
private static final Logger logger = LoggerFactory.getLogger(JsonSchemaFactory.class);
57+
public class SchemaRegistry {
58+
private static final Logger logger = LoggerFactory.getLogger(SchemaRegistry.class);
5959

6060
public static class Builder {
6161
private ObjectMapper jsonMapper = null;
@@ -173,8 +173,8 @@ public Builder addMetaSchemas(final Collection<? extends Dialect> jsonMetaSchema
173173
return metaSchemas(jsonMetaSchemas);
174174
}
175175

176-
public JsonSchemaFactory build() {
177-
return new JsonSchemaFactory(
176+
public SchemaRegistry build() {
177+
return new SchemaRegistry(
178178
jsonMapper,
179179
yamlMapper,
180180
jsonNodeReader,
@@ -203,7 +203,7 @@ public JsonSchemaFactory build() {
203203
private static final List<SchemaLoader> DEFAULT_SCHEMA_LOADERS = SchemaLoaders.builder().build();
204204
private static final List<SchemaMapper> DEFAULT_SCHEMA_MAPPERS = SchemaMappers.builder().build();
205205

206-
private JsonSchemaFactory(
206+
private SchemaRegistry(
207207
ObjectMapper jsonMapper,
208208
ObjectMapper yamlMapper,
209209
JsonNodeReader jsonNodeReader,
@@ -241,7 +241,7 @@ public SchemaLoader getSchemaLoader() {
241241
/**
242242
* Builder without keywords or formats.
243243
*
244-
* Typically {@link #builder(JsonSchemaFactory)} is what is required.
244+
* Typically {@link #builder(SchemaRegistry)} is what is required.
245245
*
246246
* @return a builder instance without any keywords or formats - usually not what one needs.
247247
*/
@@ -256,7 +256,7 @@ public static Builder builder() {
256256
* @param versionFlag the default dialect
257257
* @return the factory
258258
*/
259-
public static JsonSchemaFactory getInstance(Specification.Version versionFlag) {
259+
public static SchemaRegistry getInstance(Specification.Version versionFlag) {
260260
return getInstance(versionFlag, null);
261261
}
262262

@@ -268,10 +268,10 @@ public static JsonSchemaFactory getInstance(Specification.Version versionFlag) {
268268
* @param customizer to customize the factory
269269
* @return the factory
270270
*/
271-
public static JsonSchemaFactory getInstance(Specification.Version versionFlag,
272-
Consumer<JsonSchemaFactory.Builder> customizer) {
271+
public static SchemaRegistry getInstance(Specification.Version versionFlag,
272+
Consumer<SchemaRegistry.Builder> customizer) {
273273
Dialect dialect = checkVersion(versionFlag);
274-
JsonSchemaFactory.Builder builder = builder().defaultMetaSchemaIri(dialect.getIri())
274+
SchemaRegistry.Builder builder = builder().defaultMetaSchemaIri(dialect.getIri())
275275
.metaSchema(dialect);
276276
if (customizer != null) {
277277
customizer.accept(builder);
@@ -300,7 +300,7 @@ public static Dialect checkVersion(Specification.Version version){
300300
}
301301

302302
/**
303-
* Builder from an existing {@link JsonSchemaFactory}.
303+
* Builder from an existing {@link SchemaRegistry}.
304304
* <p>
305305
* <code>
306306
* JsonSchemaFactory.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909));
@@ -309,7 +309,7 @@ public static Dialect checkVersion(Specification.Version version){
309309
* @param blueprint the existing factory
310310
* @return the builder
311311
*/
312-
public static Builder builder(final JsonSchemaFactory blueprint) {
312+
public static Builder builder(final SchemaRegistry blueprint) {
313313
Builder builder = builder()
314314
.metaSchemas(blueprint.metaSchemas.values())
315315
.defaultMetaSchemaIri(blueprint.defaultMetaSchemaIri)

src/main/java/com/networknt/schema/SpecificationVersionDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static Optional<Version> detectOptionalVersion(JsonNode jsonNode, boolean
7575
return Optional.ofNullable(jsonNode.get(SCHEMA_TAG)).map(schemaTag -> {
7676

7777
String schemaTagValue = schemaTag.asText();
78-
String schemaUri = JsonSchemaFactory.normalizeMetaSchemaUri(schemaTagValue);
78+
String schemaUri = SchemaRegistry.normalizeMetaSchemaUri(schemaTagValue);
7979

8080
if (throwIfUnsupported) {
8181
return Version.fromDialectId(schemaUri)

src/main/java/com/networknt/schema/ValidationContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@
2727

2828
public class ValidationContext {
2929
private final Dialect dialect;
30-
private final JsonSchemaFactory jsonSchemaFactory;
30+
private final SchemaRegistry jsonSchemaFactory;
3131
private final SchemaValidatorsConfig config;
3232
private final ConcurrentMap<String, Schema> schemaReferences;
3333
private final ConcurrentMap<String, Schema> schemaResources;
3434
private final ConcurrentMap<String, Schema> dynamicAnchors;
3535

3636
public ValidationContext(Dialect dialect,
37-
JsonSchemaFactory jsonSchemaFactory, SchemaValidatorsConfig config) {
37+
SchemaRegistry jsonSchemaFactory, SchemaValidatorsConfig config) {
3838
this(dialect, jsonSchemaFactory, config, new ConcurrentHashMap<>(), new ConcurrentHashMap<>(), new ConcurrentHashMap<>());
3939
}
4040

41-
public ValidationContext(Dialect dialect, JsonSchemaFactory jsonSchemaFactory,
41+
public ValidationContext(Dialect dialect, SchemaRegistry jsonSchemaFactory,
4242
SchemaValidatorsConfig config, ConcurrentMap<String, Schema> schemaReferences,
4343
ConcurrentMap<String, Schema> schemaResources, ConcurrentMap<String, Schema> dynamicAnchors) {
4444
if (dialect == null) {
@@ -69,7 +69,7 @@ public String resolveSchemaId(JsonNode schemaNode) {
6969
return this.dialect.readId(schemaNode);
7070
}
7171

72-
public JsonSchemaFactory getJsonSchemaFactory() {
72+
public SchemaRegistry getJsonSchemaFactory() {
7373
return this.jsonSchemaFactory;
7474
}
7575

src/main/java/com/networknt/schema/dialect/DefaultDialectRegistry.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import com.networknt.schema.Error;
2323
import com.networknt.schema.InvalidSchemaException;
2424
import com.networknt.schema.Schema;
25-
import com.networknt.schema.JsonSchemaFactory;
25+
import com.networknt.schema.SchemaRegistry;
2626
import com.networknt.schema.SchemaLocation;
2727
import com.networknt.schema.SchemaValidatorsConfig;
2828
import com.networknt.schema.Specification;
@@ -33,15 +33,15 @@
3333
*/
3434
public class DefaultDialectRegistry implements DialectRegistry {
3535
@Override
36-
public Dialect getDialect(String dialectId, JsonSchemaFactory schemaFactory, SchemaValidatorsConfig config) {
36+
public Dialect getDialect(String dialectId, SchemaRegistry schemaFactory, SchemaValidatorsConfig config) {
3737
// Is it a well-known dialect?
38-
return Specification.Version.fromDialectId(dialectId).map(JsonSchemaFactory::checkVersion).orElseGet(() -> {
38+
return Specification.Version.fromDialectId(dialectId).map(SchemaRegistry::checkVersion).orElseGet(() -> {
3939
// Custom dialect
4040
return loadDialect(dialectId, schemaFactory, config);
4141
});
4242
}
4343

44-
protected Dialect loadDialect(String iri, JsonSchemaFactory schemaFactory, SchemaValidatorsConfig config) {
44+
protected Dialect loadDialect(String iri, SchemaRegistry schemaFactory, SchemaValidatorsConfig config) {
4545
try {
4646
Dialect result = loadDialectBuilder(iri, schemaFactory, config).build();
4747
return result;
@@ -53,7 +53,7 @@ protected Dialect loadDialect(String iri, JsonSchemaFactory schemaFactory, Schem
5353
}
5454
}
5555

56-
protected Dialect.Builder loadDialectBuilder(String iri, JsonSchemaFactory schemaFactory,
56+
protected Dialect.Builder loadDialectBuilder(String iri, SchemaRegistry schemaFactory,
5757
SchemaValidatorsConfig config) {
5858
Schema schema = schemaFactory.getSchema(SchemaLocation.of(iri), config);
5959
Dialect.Builder builder = Dialect.builder(iri, schema.getValidationContext().getMetaSchema());

src/main/java/com/networknt/schema/dialect/DialectRegistry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.networknt.schema.dialect;
1717

18-
import com.networknt.schema.JsonSchemaFactory;
18+
import com.networknt.schema.SchemaRegistry;
1919
import com.networknt.schema.SchemaValidatorsConfig;
2020

2121
/**
@@ -36,5 +36,5 @@ public interface DialectRegistry {
3636
* @param config the config
3737
* @return the dialect
3838
*/
39-
Dialect getDialect(String dialectId, JsonSchemaFactory schemaFactory, SchemaValidatorsConfig config);
39+
Dialect getDialect(String dialectId, SchemaRegistry schemaFactory, SchemaValidatorsConfig config);
4040
}

src/main/java/com/networknt/schema/dialect/DisallowUnknownDialectFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717

1818
import com.networknt.schema.Error;
1919
import com.networknt.schema.InvalidSchemaException;
20-
import com.networknt.schema.JsonSchemaFactory;
20+
import com.networknt.schema.SchemaRegistry;
2121
import com.networknt.schema.SchemaValidatorsConfig;
2222

2323
/**
2424
* A {@link DialectRegistry} that does not meta-schemas that aren't
25-
* explicitly configured in the {@link JsonSchemaFactory}.
25+
* explicitly configured in the {@link SchemaRegistry}.
2626
*/
2727
public class DisallowUnknownDialectFactory implements DialectRegistry {
2828
@Override
29-
public Dialect getDialect(String dialectId, JsonSchemaFactory schemaFactory, SchemaValidatorsConfig config) {
29+
public Dialect getDialect(String dialectId, SchemaRegistry schemaFactory, SchemaValidatorsConfig config) {
3030
throw new InvalidSchemaException(Error.builder()
3131
.message("Unknown dialect ''{0}''. Only dialects that are explicitly configured can be used.")
3232
.arguments(dialectId).build());

src/test/java/com/networknt/schema/AbstractJsonSchemaTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private JsonNode getJsonNodeFromPath(String dataPath) {
5959
}
6060

6161
private Schema getJsonSchema(JsonNode schemaNode) {
62-
return JsonSchemaFactory
62+
return SchemaRegistry
6363
.getInstance(SpecificationVersionDetector.detectOptionalVersion(schemaNode, false).orElse(DEFAULT_VERSION_FLAG))
6464
.getSchema(schemaNode);
6565
}

src/test/java/com/networknt/schema/AbstractJsonSchemaTestSuite.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private Stream<DynamicNode> buildContainer(Version defaultVersion, TestSource te
168168

169169
private DynamicNode buildContainer(Version defaultVersion, TestCase testCase) {
170170
try {
171-
JsonSchemaFactory validatorFactory = buildValidatorFactory(defaultVersion, testCase);
171+
SchemaRegistry validatorFactory = buildValidatorFactory(defaultVersion, testCase);
172172

173173
return dynamicContainer(testCase.getDisplayName(), testCase.getTests().stream().map(testSpec -> {
174174
return buildTest(validatorFactory, testSpec);
@@ -182,7 +182,7 @@ private DynamicNode buildContainer(Version defaultVersion, TestCase testCase) {
182182
}
183183
}
184184

185-
private JsonSchemaFactory buildValidatorFactory(Version defaultVersion, TestCase testCase) {
185+
private SchemaRegistry buildValidatorFactory(Version defaultVersion, TestCase testCase) {
186186
if (testCase.isDisabled()) return null;
187187
SchemaLoader schemaLoader = new SchemaLoader() {
188188
@Override
@@ -202,8 +202,8 @@ public InputStreamSource getSchema(AbsoluteIri absoluteIri) {
202202
}
203203
};
204204
Version specVersion = detectVersion(testCase.getSchema(), testCase.getSpecification(), defaultVersion, false);
205-
JsonSchemaFactory base = JsonSchemaFactory.getInstance(specVersion);
206-
return JsonSchemaFactory
205+
SchemaRegistry base = SchemaRegistry.getInstance(specVersion);
206+
return SchemaRegistry
207207
.builder(base)
208208
.schemaMappers(schemaMappers -> schemaMappers
209209
.mapPrefix("https://", "http://")
@@ -212,7 +212,7 @@ public InputStreamSource getSchema(AbsoluteIri absoluteIri) {
212212
.build();
213213
}
214214

215-
private DynamicNode buildTest(JsonSchemaFactory validatorFactory, TestSpec testSpec) {
215+
private DynamicNode buildTest(SchemaRegistry validatorFactory, TestSpec testSpec) {
216216
if (testSpec.isDisabled()) {
217217
return dynamicTest(testSpec.getDescription(), () -> abortAndReset(testSpec.getReason()));
218218
}

src/test/java/com/networknt/schema/AdditionalPropertiesValidatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void messageFalse() {
4545
+ " },\r\n"
4646
+ " \"additionalProperties\": false\r\n"
4747
+ "}";
48-
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(Version.DRAFT_2020_12);
48+
SchemaRegistry factory = SchemaRegistry.getInstance(Version.DRAFT_2020_12);
4949
SchemaValidatorsConfig config = SchemaValidatorsConfig.builder().build();
5050
Schema schema = factory.getSchema(schemaData, config);
5151
String inputData = "{\r\n"
@@ -80,7 +80,7 @@ void messageSchema() {
8080
+ " },\r\n"
8181
+ " \"additionalProperties\": { \"type\": \"number\" }\r\n"
8282
+ "}";
83-
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(Version.DRAFT_2020_12);
83+
SchemaRegistry factory = SchemaRegistry.getInstance(Version.DRAFT_2020_12);
8484
SchemaValidatorsConfig config = SchemaValidatorsConfig.builder().build();
8585
Schema schema = factory.getSchema(schemaData, config);
8686
String inputData = "{\r\n"

0 commit comments

Comments
 (0)