Skip to content

Commit 5a95fa6

Browse files
committed
Rename JsonMetaSchema to Dialect
1 parent a6701f9 commit 5a95fa6

34 files changed

+120
-117
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public class DefaultJsonMetaSchemaFactory implements JsonMetaSchemaFactory {
2828
@Override
29-
public JsonMetaSchema getMetaSchema(String iri, JsonSchemaFactory schemaFactory, SchemaValidatorsConfig config) {
29+
public Dialect getMetaSchema(String iri, JsonSchemaFactory schemaFactory, SchemaValidatorsConfig config) {
3030
// Is it a well-known dialect?
3131
return Specification.Version.fromDialectId(iri)
3232
.map(JsonSchemaFactory::checkVersion)
@@ -37,10 +37,10 @@ public JsonMetaSchema getMetaSchema(String iri, JsonSchemaFactory schemaFactory,
3737
});
3838
}
3939

40-
protected JsonMetaSchema loadMetaSchema(String iri, JsonSchemaFactory schemaFactory,
40+
protected Dialect loadMetaSchema(String iri, JsonSchemaFactory schemaFactory,
4141
SchemaValidatorsConfig config) {
4242
try {
43-
JsonMetaSchema result = loadMetaSchemaBuilder(iri, schemaFactory, config).build();
43+
Dialect result = loadMetaSchemaBuilder(iri, schemaFactory, config).build();
4444
return result;
4545
} catch (InvalidSchemaException e) {
4646
throw e;
@@ -51,10 +51,10 @@ protected JsonMetaSchema loadMetaSchema(String iri, JsonSchemaFactory schemaFact
5151
}
5252
}
5353

54-
protected JsonMetaSchema.Builder loadMetaSchemaBuilder(String iri, JsonSchemaFactory schemaFactory,
54+
protected Dialect.Builder loadMetaSchemaBuilder(String iri, JsonSchemaFactory schemaFactory,
5555
SchemaValidatorsConfig config) {
5656
JsonSchema schema = schemaFactory.getSchema(SchemaLocation.of(iri), config);
57-
JsonMetaSchema.Builder builder = JsonMetaSchema.builder(iri, schema.getValidationContext().getMetaSchema());
57+
Dialect.Builder builder = Dialect.builder(iri, schema.getValidationContext().getMetaSchema());
5858
Version specification = schema.getValidationContext().getMetaSchema().getSpecification();
5959
if (specification != null) {
6060
if (specification.getOrder() >= Version.DRAFT_2019_09.getOrder()) {

src/main/java/com/networknt/schema/JsonMetaSchema.java renamed to src/main/java/com/networknt/schema/Dialect.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@
3737
import java.util.function.Consumer;
3838

3939
/**
40-
* Represents a meta-schema which is uniquely identified by its IRI.
40+
* A dialect represents the set of keywords and semantics that can be used to
41+
* evaluate a schema. The dialect can be uniquely identified by its IRI which
42+
* points to the meta-schema used to validate schemas written for that dialect.
43+
* The dialect for a particular schema is indicated using the $schema keyword.
4144
*/
42-
public class JsonMetaSchema {
43-
private static final Logger logger = LoggerFactory.getLogger(JsonMetaSchema.class);
45+
public class Dialect {
46+
private static final Logger logger = LoggerFactory.getLogger(Dialect.class);
4447

4548
/**
4649
* Factory for creating a format keyword.
@@ -56,7 +59,7 @@ public interface FormatKeywordFactory {
5659
}
5760

5861
/**
59-
* Builder for {@link JsonMetaSchema}.
62+
* Builder for {@link Dialect}.
6063
*/
6164
public static class Builder {
6265
private String iri;
@@ -269,7 +272,7 @@ public Builder idKeyword(String idKeyword) {
269272
return this;
270273
}
271274

272-
public JsonMetaSchema build() {
275+
public Dialect build() {
273276
// create builtin keywords with (custom) formats.
274277
Map<String, Keyword> keywords = this.keywords;
275278
if (this.specification != null) {
@@ -298,7 +301,7 @@ public JsonMetaSchema build() {
298301
}
299302
}
300303
Map<String, Keyword> result = createKeywordsMap(keywords, this.formats);
301-
return new JsonMetaSchema(this.iri, this.idKeyword, result, this.vocabularies, this.specification, this);
304+
return new Dialect(this.iri, this.idKeyword, result, this.vocabularies, this.specification, this);
302305
}
303306

304307
@Deprecated
@@ -330,7 +333,7 @@ public Builder addFormats(Collection<? extends Format> formats) {
330333

331334
private final Builder builder;
332335

333-
JsonMetaSchema(String iri, String idKeyword, Map<String, Keyword> keywords, Map<String, Boolean> vocabularies, Version specification, Builder builder) {
336+
Dialect(String iri, String idKeyword, Map<String, Keyword> keywords, Map<String, Boolean> vocabularies, Version specification, Builder builder) {
334337
if (StringUtils.isBlank(iri)) {
335338
throw new IllegalArgumentException("iri must not be null or blank");
336339
}
@@ -349,23 +352,23 @@ public Builder addFormats(Collection<? extends Format> formats) {
349352
this.builder = builder;
350353
}
351354

352-
public static JsonMetaSchema getV4() {
355+
public static Dialect getV4() {
353356
return new Version4().getInstance();
354357
}
355358

356-
public static JsonMetaSchema getV6() {
359+
public static Dialect getV6() {
357360
return new Version6().getInstance();
358361
}
359362

360-
public static JsonMetaSchema getV7() {
363+
public static Dialect getV7() {
361364
return new Version7().getInstance();
362365
}
363366

364-
public static JsonMetaSchema getV201909() {
367+
public static Dialect getV201909() {
365368
return new Version201909().getInstance();
366369
}
367370

368-
public static JsonMetaSchema getV202012() {
371+
public static Dialect getV202012() {
369372
return new Version202012().getInstance();
370373
}
371374

@@ -394,7 +397,7 @@ public static Builder builder(String iri) {
394397
* @return a builder instance preconfigured to be the same as blueprint, but
395398
* with a different uri.
396399
*/
397-
public static Builder builder(String iri, JsonMetaSchema blueprint) {
400+
public static Builder builder(String iri, Dialect blueprint) {
398401
Builder builder = builder(blueprint);
399402
builder.iri = iri;
400403
return builder;
@@ -406,7 +409,7 @@ public static Builder builder(String iri, JsonMetaSchema blueprint) {
406409
* @param blueprint the JsonMetaSchema to base your custom JsonMetaSchema on.
407410
* @return a builder instance preconfigured to be the same as blueprint
408411
*/
409-
public static Builder builder(JsonMetaSchema blueprint) {
412+
public static Builder builder(Dialect blueprint) {
410413
Map<String, Boolean> vocabularies = new HashMap<>(blueprint.getVocabularies());
411414
return builder(blueprint.getIri())
412415
.idKeyword(blueprint.idKeyword)
@@ -533,7 +536,7 @@ public boolean equals(Object obj) {
533536
return false;
534537
if (getClass() != obj.getClass())
535538
return false;
536-
JsonMetaSchema other = (JsonMetaSchema) obj;
539+
Dialect other = (Dialect) obj;
537540
return Objects.equals(iri, other.iri);
538541
}
539542
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
public class DisallowUnknownJsonMetaSchemaFactory implements JsonMetaSchemaFactory {
2323
@Override
24-
public JsonMetaSchema getMetaSchema(String iri, JsonSchemaFactory schemaFactory, SchemaValidatorsConfig config) {
24+
public Dialect getMetaSchema(String iri, JsonSchemaFactory schemaFactory, SchemaValidatorsConfig config) {
2525
throw new InvalidSchemaException(Error.builder()
2626
.message("Unknown meta-schema ''{0}''. Only meta-schemas that are explicitly configured can be used.")
2727
.arguments(iri).build());

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

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

1818
/**
19-
* Factory for {@link JsonMetaSchema}.
19+
* Factory for {@link Dialect}.
2020
*/
2121
@FunctionalInterface
2222
public interface JsonMetaSchemaFactory {
@@ -28,5 +28,5 @@ public interface JsonMetaSchemaFactory {
2828
* @param config the config
2929
* @return the meta-schema
3030
*/
31-
JsonMetaSchema getMetaSchema(String iri, JsonSchemaFactory schemaFactory, SchemaValidatorsConfig config);
31+
Dialect getMetaSchema(String iri, JsonSchemaFactory schemaFactory, SchemaValidatorsConfig config);
3232
}

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static class Builder {
5757
private ObjectMapper yamlMapper = null;
5858
private JsonNodeReader jsonNodeReader = null;
5959
private String defaultMetaSchemaIri;
60-
private final ConcurrentMap<String, JsonMetaSchema> metaSchemas = new ConcurrentHashMap<>();
60+
private final ConcurrentMap<String, Dialect> metaSchemas = new ConcurrentHashMap<>();
6161
private SchemaLoaders.Builder schemaLoadersBuilder = null;
6262
private SchemaMappers.Builder schemaMappersBuilder = null;
6363
private boolean enableSchemaCache = true;
@@ -120,19 +120,19 @@ public Builder metaSchemaFactory(final JsonMetaSchemaFactory jsonMetaSchemaFacto
120120
return this;
121121
}
122122

123-
public Builder metaSchema(final JsonMetaSchema jsonMetaSchema) {
123+
public Builder metaSchema(final Dialect jsonMetaSchema) {
124124
this.metaSchemas.put(normalizeMetaSchemaUri(jsonMetaSchema.getIri()), jsonMetaSchema);
125125
return this;
126126
}
127127

128-
public Builder metaSchemas(final Collection<? extends JsonMetaSchema> jsonMetaSchemas) {
129-
for (JsonMetaSchema jsonMetaSchema : jsonMetaSchemas) {
128+
public Builder metaSchemas(final Collection<? extends Dialect> jsonMetaSchemas) {
129+
for (Dialect jsonMetaSchema : jsonMetaSchemas) {
130130
metaSchema(jsonMetaSchema);
131131
}
132132
return this;
133133
}
134134

135-
public Builder metaSchemas(Consumer<Map<String, JsonMetaSchema>> customizer) {
135+
public Builder metaSchemas(Consumer<Map<String, Dialect>> customizer) {
136136
customizer.accept(this.metaSchemas);
137137
return this;
138138
}
@@ -159,12 +159,12 @@ public Builder schemaMappers(Consumer<SchemaMappers.Builder> schemaMappersBuilde
159159
}
160160

161161
@Deprecated
162-
public Builder addMetaSchema(final JsonMetaSchema jsonMetaSchema) {
162+
public Builder addMetaSchema(final Dialect jsonMetaSchema) {
163163
return metaSchema(jsonMetaSchema);
164164
}
165165

166166
@Deprecated
167-
public Builder addMetaSchemas(final Collection<? extends JsonMetaSchema> jsonMetaSchemas) {
167+
public Builder addMetaSchemas(final Collection<? extends Dialect> jsonMetaSchemas) {
168168
return metaSchemas(jsonMetaSchemas);
169169
}
170170

@@ -190,7 +190,7 @@ public JsonSchemaFactory build() {
190190
private final SchemaLoaders.Builder schemaLoadersBuilder;
191191
private final SchemaMappers.Builder schemaMappersBuilder;
192192
private final SchemaLoader schemaLoader;
193-
private final ConcurrentMap<String, JsonMetaSchema> metaSchemas;
193+
private final ConcurrentMap<String, Dialect> metaSchemas;
194194
private final ConcurrentMap<SchemaLocation, JsonSchema> schemaCache = new ConcurrentHashMap<>();
195195
private final boolean enableSchemaCache;
196196
private final JsonMetaSchemaFactory metaSchemaFactory;
@@ -205,7 +205,7 @@ private JsonSchemaFactory(
205205
String defaultMetaSchemaIri,
206206
SchemaLoaders.Builder schemaLoadersBuilder,
207207
SchemaMappers.Builder schemaMappersBuilder,
208-
ConcurrentMap<String, JsonMetaSchema> metaSchemas,
208+
ConcurrentMap<String, Dialect> metaSchemas,
209209
boolean enableSchemaCache,
210210
JsonMetaSchemaFactory metaSchemaFactory) {
211211
this.metaSchemas = metaSchemas;
@@ -266,7 +266,7 @@ public static JsonSchemaFactory getInstance(Specification.Version versionFlag) {
266266
public static JsonSchemaFactory getInstance(Specification.Version versionFlag,
267267
Consumer<JsonSchemaFactory.Builder> customizer) {
268268
JsonSchemaVersion jsonSchemaVersion = checkVersion(versionFlag);
269-
JsonMetaSchema metaSchema = jsonSchemaVersion.getInstance();
269+
Dialect metaSchema = jsonSchemaVersion.getInstance();
270270
JsonSchemaFactory.Builder builder = builder().defaultMetaSchemaIri(metaSchema.getIri())
271271
.metaSchema(metaSchema);
272272
if (customizer != null) {
@@ -384,7 +384,7 @@ private JsonSchema doCreate(ValidationContext validationContext, SchemaLocation
384384
* @return the validation context to use
385385
*/
386386
private ValidationContext withMetaSchema(ValidationContext validationContext, JsonNode schemaNode) {
387-
JsonMetaSchema metaSchema = getMetaSchema(schemaNode, validationContext.getConfig());
387+
Dialect metaSchema = getMetaSchema(schemaNode, validationContext.getConfig());
388388
if (metaSchema != null && !metaSchema.getIri().equals(validationContext.getMetaSchema().getIri())) {
389389
SchemaValidatorsConfig config = validationContext.getConfig();
390390
if (metaSchema.getKeywords().containsKey("discriminator") && !config.isDiscriminatorKeywordEnabled()) {
@@ -415,7 +415,7 @@ protected SchemaLocation getSchemaLocation(SchemaLocation schemaLocation) {
415415
}
416416

417417
protected ValidationContext createValidationContext(final JsonNode schemaNode, SchemaValidatorsConfig config) {
418-
final JsonMetaSchema jsonMetaSchema = getMetaSchemaOrDefault(schemaNode, config);
418+
final Dialect jsonMetaSchema = getMetaSchemaOrDefault(schemaNode, config);
419419
SchemaValidatorsConfig configResult = config;
420420
if (jsonMetaSchema.getKeywords().containsKey("discriminator") && !config.isDiscriminatorKeywordEnabled()) {
421421
configResult = SchemaValidatorsConfig.builder(config)
@@ -426,17 +426,17 @@ protected ValidationContext createValidationContext(final JsonNode schemaNode, S
426426
return new ValidationContext(jsonMetaSchema, this, configResult);
427427
}
428428

429-
private JsonMetaSchema getMetaSchema(final JsonNode schemaNode, SchemaValidatorsConfig config) {
429+
private Dialect getMetaSchema(final JsonNode schemaNode, SchemaValidatorsConfig config) {
430430
final JsonNode iriNode = schemaNode.get("$schema");
431431
if (iriNode != null && iriNode.isTextual()) {
432-
JsonMetaSchema result = metaSchemas.computeIfAbsent(normalizeMetaSchemaUri(iriNode.textValue()),
432+
Dialect result = metaSchemas.computeIfAbsent(normalizeMetaSchemaUri(iriNode.textValue()),
433433
id -> loadMetaSchema(id, config));
434434
return result;
435435
}
436436
return null;
437437
}
438438

439-
private JsonMetaSchema getMetaSchemaOrDefault(final JsonNode schemaNode, SchemaValidatorsConfig config) {
439+
private Dialect getMetaSchemaOrDefault(final JsonNode schemaNode, SchemaValidatorsConfig config) {
440440
final JsonNode iriNode = schemaNode.get("$schema");
441441
if (iriNode != null && !iriNode.isNull() && !iriNode.isTextual()) {
442442
throw new JsonSchemaException("Unknown MetaSchema: " + iriNode);
@@ -452,9 +452,9 @@ private JsonMetaSchema getMetaSchemaOrDefault(final JsonNode schemaNode, SchemaV
452452
* @param config the schema validators config
453453
* @return the meta-schema
454454
*/
455-
public JsonMetaSchema getMetaSchema(String iri, SchemaValidatorsConfig config) {
455+
public Dialect getMetaSchema(String iri, SchemaValidatorsConfig config) {
456456
String key = normalizeMetaSchemaUri(iri);
457-
JsonMetaSchema result = metaSchemas.computeIfAbsent(key, id -> loadMetaSchema(id, config));
457+
Dialect result = metaSchemas.computeIfAbsent(key, id -> loadMetaSchema(id, config));
458458
return result;
459459
}
460460

@@ -465,7 +465,7 @@ public JsonMetaSchema getMetaSchema(String iri, SchemaValidatorsConfig config) {
465465
* @param config the schema validators config
466466
* @return the meta-schema
467467
*/
468-
protected JsonMetaSchema loadMetaSchema(String iri, SchemaValidatorsConfig config) {
468+
protected Dialect loadMetaSchema(String iri, SchemaValidatorsConfig config) {
469469
return this.metaSchemaFactory != null ? this.metaSchemaFactory.getMetaSchema(iri, this, config)
470470
: DefaultJsonMetaSchemaFactory.getInstance().getMetaSchema(iri, this, config);
471471
}
@@ -678,7 +678,7 @@ protected JsonSchema getMappedSchema(final SchemaLocation schemaUri, SchemaValid
678678
schemaNode = readTree(inputStream, InputFormat.JSON);
679679
}
680680

681-
final JsonMetaSchema jsonMetaSchema = getMetaSchemaOrDefault(schemaNode, config);
681+
final Dialect jsonMetaSchema = getMetaSchemaOrDefault(schemaNode, config);
682682
JsonNodePath evaluationPath = new JsonNodePath(config.getPathType());
683683
if (schemaUri.getFragment() == null
684684
|| schemaUri.getFragment().getNameCount() == 0) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ public interface JsonSchemaVersion {
2424
*
2525
* @return the instance
2626
*/
27-
JsonMetaSchema getInstance();
27+
Dialect getInstance();
2828
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@
2525
import com.networknt.schema.keyword.KeywordValidator;
2626

2727
public class ValidationContext {
28-
private final JsonMetaSchema metaSchema;
28+
private final Dialect metaSchema;
2929
private final JsonSchemaFactory jsonSchemaFactory;
3030
private final SchemaValidatorsConfig config;
3131
private final ConcurrentMap<String, JsonSchema> schemaReferences;
3232
private final ConcurrentMap<String, JsonSchema> schemaResources;
3333
private final ConcurrentMap<String, JsonSchema> dynamicAnchors;
3434

35-
public ValidationContext(JsonMetaSchema metaSchema,
35+
public ValidationContext(Dialect metaSchema,
3636
JsonSchemaFactory jsonSchemaFactory, SchemaValidatorsConfig config) {
3737
this(metaSchema, jsonSchemaFactory, config, new ConcurrentHashMap<>(), new ConcurrentHashMap<>(), new ConcurrentHashMap<>());
3838
}
3939

40-
public ValidationContext(JsonMetaSchema metaSchema, JsonSchemaFactory jsonSchemaFactory,
40+
public ValidationContext(Dialect metaSchema, JsonSchemaFactory jsonSchemaFactory,
4141
SchemaValidatorsConfig config, ConcurrentMap<String, JsonSchema> schemaReferences,
4242
ConcurrentMap<String, JsonSchema> schemaResources, ConcurrentMap<String, JsonSchema> dynamicAnchors) {
4343
if (metaSchema == null) {
@@ -103,7 +103,7 @@ public ConcurrentMap<String, JsonSchema> getDynamicAnchors() {
103103
return this.dynamicAnchors;
104104
}
105105

106-
public JsonMetaSchema getMetaSchema() {
106+
public Dialect getMetaSchema() {
107107
return this.metaSchema;
108108
}
109109

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public class Version201909 implements JsonSchemaVersion {
2727
}
2828

2929
private static class Holder {
30-
private static final JsonMetaSchema INSTANCE;
30+
private static final Dialect INSTANCE;
3131
static {
32-
INSTANCE = JsonMetaSchema.builder(IRI)
32+
INSTANCE = Dialect.builder(IRI)
3333
.specification(Specification.Version.DRAFT_2019_09)
3434
.idKeyword(ID)
3535
.formats(Formats.DEFAULT)
@@ -44,7 +44,7 @@ private static class Holder {
4444
}
4545

4646
@Override
47-
public JsonMetaSchema getInstance() {
47+
public Dialect getInstance() {
4848
return Holder.INSTANCE;
4949
}
5050
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public class Version202012 implements JsonSchemaVersion {
2828
}
2929

3030
private static class Holder {
31-
private static final JsonMetaSchema INSTANCE;
31+
private static final Dialect INSTANCE;
3232
static {
33-
INSTANCE = JsonMetaSchema.builder(IRI)
33+
INSTANCE = Dialect.builder(IRI)
3434
.specification(Specification.Version.DRAFT_2020_12)
3535
.idKeyword(ID)
3636
.formats(Formats.DEFAULT)
@@ -45,7 +45,7 @@ private static class Holder {
4545
}
4646

4747
@Override
48-
public JsonMetaSchema getInstance() {
48+
public Dialect getInstance() {
4949
return Holder.INSTANCE;
5050
}
5151
}

0 commit comments

Comments
 (0)