Skip to content

Commit 0ccbbc7

Browse files
committed
Refactor naming
1 parent 885110e commit 0ccbbc7

26 files changed

+108
-120
lines changed

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* modified.
5252
*/
5353
public class Schema implements Validator {
54-
private static final long V201909_VALUE = Version.DRAFT_2019_09.getOrder();
54+
private static final long DRAFT_2019_09_VALUE = Version.DRAFT_2019_09.getOrder();
5555
private final String id;
5656

5757
/**
@@ -656,7 +656,7 @@ private List<KeywordValidator> read(JsonNode schemaNode) {
656656
}
657657

658658
// Ignore siblings for older drafts
659-
if (null != refValidator && activeDialect() < V201909_VALUE) {
659+
if (null != refValidator && getSchemaContext().getDialect().getSpecification().getOrder() < DRAFT_2019_09_VALUE) {
660660
validators.clear();
661661
validators.add(refValidator);
662662
}
@@ -667,13 +667,6 @@ private List<KeywordValidator> read(JsonNode schemaNode) {
667667
return validators;
668668
}
669669

670-
private long activeDialect() {
671-
return this.schemaContext
672-
.activeDialect()
673-
.map(Version::getOrder)
674-
.orElse(Integer.MAX_VALUE);
675-
}
676-
677670
/**
678671
* A comparator that sorts validators, such that 'properties' comes before 'required',
679672
* so that we can apply default values before validating required.

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,6 @@ public Dialect getDialect() {
171171
return this.dialect;
172172
}
173173

174-
public Optional<Version> activeDialect() {
175-
return Optional.of(this.dialect.getSpecification());
176-
}
177-
178174
public boolean isDiscriminatorKeywordEnabled() {
179175
return discriminatorKeywordEnabled;
180176
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public static SchemaRegistry withDefaultDialect(Specification.Version specificat
209209
public static SchemaRegistry withDefaultDialect(Specification.Version specificationVersion,
210210
Consumer<SchemaRegistry.Builder> customizer) {
211211
Dialect dialect = Specification.getDialect(specificationVersion);
212-
return withDefaultDialectId(dialect.getIri(), customizer);
212+
return withDefaultDialectId(dialect.getId(), customizer);
213213
}
214214

215215
/**
@@ -251,7 +251,7 @@ public static SchemaRegistry withDialect(Dialect dialect) {
251251
* @return the schema registry
252252
*/
253253
public static SchemaRegistry withDialect(Dialect dialect, Consumer<SchemaRegistry.Builder> customizer) {
254-
SchemaRegistry.Builder builder = builder().defaultDialectId(dialect.getIri())
254+
SchemaRegistry.Builder builder = builder().defaultDialectId(dialect.getId())
255255
.dialectRegistry(new BasicDialectRegistry(dialect));
256256
if (customizer != null) {
257257
customizer.accept(builder);
@@ -345,7 +345,7 @@ private Schema doCreate(SchemaContext schemaContext, SchemaLocation schemaLocati
345345
*/
346346
private SchemaContext withDialect(SchemaContext schemaContext, JsonNode schemaNode) {
347347
Dialect dialect = getDialect(schemaNode, schemaContext.getSchemaRegistryConfig());
348-
if (dialect != null && !dialect.getIri().equals(schemaContext.getDialect().getIri())) {
348+
if (dialect != null && !dialect.getId().equals(schemaContext.getDialect().getId())) {
349349
return new SchemaContext(dialect, schemaContext.getSchemaRegistry(),
350350
schemaContext.getSchemaReferences(), schemaContext.getSchemaResources(),
351351
schemaContext.getDynamicAnchors());

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ public class Vocabularies {
2626

2727
static {
2828
Map<String, Vocabulary> mapping = new HashMap<>();
29-
mapping.put(Vocabulary.V201909_CORE.getIri(), Vocabulary.V201909_CORE);
30-
mapping.put(Vocabulary.V201909_APPLICATOR.getIri(), Vocabulary.V201909_APPLICATOR);
31-
mapping.put(Vocabulary.V201909_VALIDATION.getIri(), Vocabulary.V201909_VALIDATION);
32-
mapping.put(Vocabulary.V201909_META_DATA.getIri(), Vocabulary.V201909_META_DATA);
33-
mapping.put(Vocabulary.V201909_FORMAT.getIri(), Vocabulary.V201909_FORMAT);
34-
mapping.put(Vocabulary.V201909_CONTENT.getIri(), Vocabulary.V201909_CONTENT);
29+
mapping.put(Vocabulary.DRAFT_2019_09_CORE.getIri(), Vocabulary.DRAFT_2019_09_CORE);
30+
mapping.put(Vocabulary.DRAFT_2019_09_APPLICATOR.getIri(), Vocabulary.DRAFT_2019_09_APPLICATOR);
31+
mapping.put(Vocabulary.DRAFT_2019_09_VALIDATION.getIri(), Vocabulary.DRAFT_2019_09_VALIDATION);
32+
mapping.put(Vocabulary.DRAFT_2019_09_META_DATA.getIri(), Vocabulary.DRAFT_2019_09_META_DATA);
33+
mapping.put(Vocabulary.DRAFT_2019_09_FORMAT.getIri(), Vocabulary.DRAFT_2019_09_FORMAT);
34+
mapping.put(Vocabulary.DRAFT_2019_09_CONTENT.getIri(), Vocabulary.DRAFT_2019_09_CONTENT);
3535

36-
mapping.put(Vocabulary.V202012_CORE.getIri(), Vocabulary.V202012_CORE);
37-
mapping.put(Vocabulary.V202012_APPLICATOR.getIri(), Vocabulary.V202012_APPLICATOR);
38-
mapping.put(Vocabulary.V202012_UNEVALUATED.getIri(), Vocabulary.V202012_UNEVALUATED);
39-
mapping.put(Vocabulary.V202012_VALIDATION.getIri(), Vocabulary.V202012_VALIDATION);
40-
mapping.put(Vocabulary.V202012_META_DATA.getIri(), Vocabulary.V202012_META_DATA);
41-
mapping.put(Vocabulary.V202012_FORMAT_ANNOTATION.getIri(), Vocabulary.V202012_FORMAT_ANNOTATION);
42-
mapping.put(Vocabulary.V202012_FORMAT_ASSERTION.getIri(), Vocabulary.V202012_FORMAT_ASSERTION);
43-
mapping.put(Vocabulary.V202012_CONTENT.getIri(), Vocabulary.V202012_CONTENT);
36+
mapping.put(Vocabulary.DRAFT_2020_12_CORE.getIri(), Vocabulary.DRAFT_2020_12_CORE);
37+
mapping.put(Vocabulary.DRAFT_2020_12_APPLICATOR.getIri(), Vocabulary.DRAFT_2020_12_APPLICATOR);
38+
mapping.put(Vocabulary.DRAFT_2020_12_UNEVALUATED.getIri(), Vocabulary.DRAFT_2020_12_UNEVALUATED);
39+
mapping.put(Vocabulary.DRAFT_2020_12_VALIDATION.getIri(), Vocabulary.DRAFT_2020_12_VALIDATION);
40+
mapping.put(Vocabulary.DRAFT_2020_12_META_DATA.getIri(), Vocabulary.DRAFT_2020_12_META_DATA);
41+
mapping.put(Vocabulary.DRAFT_2020_12_FORMAT_ANNOTATION.getIri(), Vocabulary.DRAFT_2020_12_FORMAT_ANNOTATION);
42+
mapping.put(Vocabulary.DRAFT_2020_12_FORMAT_ASSERTION.getIri(), Vocabulary.DRAFT_2020_12_FORMAT_ASSERTION);
43+
mapping.put(Vocabulary.DRAFT_2020_12_CONTENT.getIri(), Vocabulary.DRAFT_2020_12_CONTENT);
4444

4545
mapping.put(Vocabulary.OPENAPI_3_1_BASE.getIri(), Vocabulary.OPENAPI_3_1_BASE);
4646

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@
3333
public class Vocabulary {
3434

3535
// 2019-09
36-
public static final Vocabulary V201909_CORE = new Vocabulary("https://json-schema.org/draft/2019-09/vocab/core",
36+
public static final Vocabulary DRAFT_2019_09_CORE = new Vocabulary("https://json-schema.org/draft/2019-09/vocab/core",
3737
new NonValidationKeyword("$id"), new NonValidationKeyword("$schema"), new NonValidationKeyword("$anchor"),
3838
ValidatorTypeCode.REF, ValidatorTypeCode.RECURSIVE_REF, new NonValidationKeyword("$recursiveAnchor"),
3939
new NonValidationKeyword("$vocabulary"), new NonValidationKeyword("$comment"),
4040
new NonValidationKeyword("$defs"));
41-
public static final Vocabulary V201909_APPLICATOR = new Vocabulary(
41+
public static final Vocabulary DRAFT_2019_09_APPLICATOR = new Vocabulary(
4242
"https://json-schema.org/draft/2019-09/vocab/applicator", new NonValidationKeyword("additionalItems"),
4343
ValidatorTypeCode.UNEVALUATED_ITEMS, ValidatorTypeCode.ITEMS, ValidatorTypeCode.CONTAINS,
4444
ValidatorTypeCode.ADDITIONAL_PROPERTIES, ValidatorTypeCode.UNEVALUATED_PROPERTIES,
4545
ValidatorTypeCode.PROPERTIES, ValidatorTypeCode.PATTERN_PROPERTIES, ValidatorTypeCode.DEPENDENT_SCHEMAS,
4646
ValidatorTypeCode.PROPERTYNAMES, ValidatorTypeCode.IF_THEN_ELSE, new NonValidationKeyword("then"),
4747
new NonValidationKeyword("else"), ValidatorTypeCode.ALL_OF, ValidatorTypeCode.ANY_OF,
4848
ValidatorTypeCode.ONE_OF, ValidatorTypeCode.NOT);
49-
public static final Vocabulary V201909_VALIDATION = new Vocabulary(
49+
public static final Vocabulary DRAFT_2019_09_VALIDATION = new Vocabulary(
5050
"https://json-schema.org/draft/2019-09/vocab/validation", ValidatorTypeCode.MULTIPLE_OF,
5151
ValidatorTypeCode.MAXIMUM, ValidatorTypeCode.EXCLUSIVE_MAXIMUM, ValidatorTypeCode.MINIMUM,
5252
ValidatorTypeCode.EXCLUSIVE_MINIMUM, ValidatorTypeCode.MAX_LENGTH, ValidatorTypeCode.MIN_LENGTH,
@@ -55,49 +55,49 @@ ValidatorTypeCode.PROPERTYNAMES, ValidatorTypeCode.IF_THEN_ELSE, new NonValidati
5555
ValidatorTypeCode.MAX_PROPERTIES, ValidatorTypeCode.MIN_PROPERTIES, ValidatorTypeCode.REQUIRED,
5656
ValidatorTypeCode.DEPENDENT_REQUIRED, ValidatorTypeCode.CONST, ValidatorTypeCode.ENUM,
5757
ValidatorTypeCode.TYPE);
58-
public static final Vocabulary V201909_META_DATA = new Vocabulary(
58+
public static final Vocabulary DRAFT_2019_09_META_DATA = new Vocabulary(
5959
"https://json-schema.org/draft/2019-09/vocab/meta-data", new AnnotationKeyword("title"),
6060
new AnnotationKeyword("description"), new AnnotationKeyword("default"), new AnnotationKeyword("deprecated"),
6161
ValidatorTypeCode.READ_ONLY, ValidatorTypeCode.WRITE_ONLY, new AnnotationKeyword("examples"));
62-
public static final Vocabulary V201909_FORMAT = new Vocabulary("https://json-schema.org/draft/2019-09/vocab/format",
62+
public static final Vocabulary DRAFT_2019_09_FORMAT = new Vocabulary("https://json-schema.org/draft/2019-09/vocab/format",
6363
ValidatorTypeCode.FORMAT);
64-
public static final Vocabulary V201909_CONTENT = new Vocabulary(
64+
public static final Vocabulary DRAFT_2019_09_CONTENT = new Vocabulary(
6565
"https://json-schema.org/draft/2019-09/vocab/content", new AnnotationKeyword("contentMediaType"),
6666
new AnnotationKeyword("contentEncoding"), new AnnotationKeyword("contentSchema"));
6767

6868
// 2020-12
69-
public static final Vocabulary V202012_CORE = new Vocabulary("https://json-schema.org/draft/2020-12/vocab/core",
69+
public static final Vocabulary DRAFT_2020_12_CORE = new Vocabulary("https://json-schema.org/draft/2020-12/vocab/core",
7070
new NonValidationKeyword("$id"), new NonValidationKeyword("$schema"), ValidatorTypeCode.REF,
7171
new NonValidationKeyword("$anchor"), ValidatorTypeCode.DYNAMIC_REF,
7272
new NonValidationKeyword("$dynamicAnchor"), new NonValidationKeyword("$vocabulary"),
7373
new NonValidationKeyword("$comment"), new NonValidationKeyword("$defs"));
74-
public static final Vocabulary V202012_APPLICATOR = new Vocabulary(
74+
public static final Vocabulary DRAFT_2020_12_APPLICATOR = new Vocabulary(
7575
"https://json-schema.org/draft/2020-12/vocab/applicator", ValidatorTypeCode.PREFIX_ITEMS,
7676
ValidatorTypeCode.ITEMS_202012, ValidatorTypeCode.CONTAINS, ValidatorTypeCode.ADDITIONAL_PROPERTIES,
7777
ValidatorTypeCode.PROPERTIES, ValidatorTypeCode.PATTERN_PROPERTIES, ValidatorTypeCode.DEPENDENT_SCHEMAS,
7878
ValidatorTypeCode.PROPERTYNAMES, ValidatorTypeCode.IF_THEN_ELSE, new NonValidationKeyword("then"),
7979
new NonValidationKeyword("else"), ValidatorTypeCode.ALL_OF, ValidatorTypeCode.ANY_OF,
8080
ValidatorTypeCode.ONE_OF, ValidatorTypeCode.NOT);
81-
public static final Vocabulary V202012_UNEVALUATED = new Vocabulary(
81+
public static final Vocabulary DRAFT_2020_12_UNEVALUATED = new Vocabulary(
8282
"https://json-schema.org/draft/2020-12/vocab/unevaluated", ValidatorTypeCode.UNEVALUATED_ITEMS,
8383
ValidatorTypeCode.UNEVALUATED_PROPERTIES);
84-
public static final Vocabulary V202012_VALIDATION = new Vocabulary(
84+
public static final Vocabulary DRAFT_2020_12_VALIDATION = new Vocabulary(
8585
"https://json-schema.org/draft/2020-12/vocab/validation", ValidatorTypeCode.TYPE, ValidatorTypeCode.CONST,
8686
ValidatorTypeCode.ENUM, ValidatorTypeCode.MULTIPLE_OF, ValidatorTypeCode.MAXIMUM,
8787
ValidatorTypeCode.EXCLUSIVE_MAXIMUM, ValidatorTypeCode.MINIMUM, ValidatorTypeCode.EXCLUSIVE_MINIMUM,
8888
ValidatorTypeCode.MAX_LENGTH, ValidatorTypeCode.MIN_LENGTH, ValidatorTypeCode.PATTERN,
8989
ValidatorTypeCode.MAX_ITEMS, ValidatorTypeCode.MIN_ITEMS, ValidatorTypeCode.UNIQUE_ITEMS,
9090
ValidatorTypeCode.MAX_CONTAINS, ValidatorTypeCode.MIN_CONTAINS, ValidatorTypeCode.MAX_PROPERTIES,
9191
ValidatorTypeCode.MIN_PROPERTIES, ValidatorTypeCode.REQUIRED, ValidatorTypeCode.DEPENDENT_REQUIRED);
92-
public static final Vocabulary V202012_META_DATA = new Vocabulary(
92+
public static final Vocabulary DRAFT_2020_12_META_DATA = new Vocabulary(
9393
"https://json-schema.org/draft/2020-12/vocab/meta-data", new AnnotationKeyword("title"),
9494
new AnnotationKeyword("description"), new AnnotationKeyword("default"), new AnnotationKeyword("deprecated"),
9595
ValidatorTypeCode.READ_ONLY, ValidatorTypeCode.WRITE_ONLY, new AnnotationKeyword("examples"));
96-
public static final Vocabulary V202012_FORMAT_ANNOTATION = new Vocabulary(
96+
public static final Vocabulary DRAFT_2020_12_FORMAT_ANNOTATION = new Vocabulary(
9797
"https://json-schema.org/draft/2020-12/vocab/format-annotation", ValidatorTypeCode.FORMAT);
98-
public static final Vocabulary V202012_FORMAT_ASSERTION = new Vocabulary(
98+
public static final Vocabulary DRAFT_2020_12_FORMAT_ASSERTION = new Vocabulary(
9999
"https://json-schema.org/draft/2020-12/vocab/format-assertion", ValidatorTypeCode.FORMAT);
100-
public static final Vocabulary V202012_CONTENT = new Vocabulary(
100+
public static final Vocabulary DRAFT_2020_12_CONTENT = new Vocabulary(
101101
"https://json-schema.org/draft/2020-12/vocab/content", new AnnotationKeyword("contentEncoding"),
102102
new AnnotationKeyword("contentMediaType"), new AnnotationKeyword("contentSchema"));
103103

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public BasicDialectRegistry(Function<String, Dialect> dialects) {
2929
}
3030

3131
public BasicDialectRegistry(Dialect dialect) {
32-
this.dialects = dialectId -> dialect.getIri().equals(dialectId) ? dialect : null;
32+
this.dialects = dialectId -> dialect.getId().equals(dialectId) ? dialect : null;
3333
}
3434

3535
@Override

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public interface FormatKeywordFactory {
7474
* Builder for {@link Dialect}.
7575
*/
7676
public static class Builder {
77-
private String iri;
77+
private String id;
7878
private String idKeyword = "$id";
7979
private Version specification = null;
8080
private final Map<String, Keyword> keywords = new HashMap<>();
@@ -84,8 +84,8 @@ public static class Builder {
8484
private VocabularyFactory vocabularyFactory = null;
8585
private KeywordFactory unknownKeywordFactory = null;
8686

87-
public Builder(String iri) {
88-
this.iri = iri;
87+
public Builder(String id) {
88+
this.id = id;
8989
}
9090

9191
private Map<String, Keyword> createKeywordsMap(Map<String, Keyword> kwords, Map<String, Format> formats) {
@@ -306,28 +306,28 @@ public Dialect build() {
306306
} else if (Boolean.TRUE.equals(entry.getValue())) {
307307
Error error = Error.builder()
308308
.message("Meta-schema ''{0}'' has unknown required vocabulary ''{1}''")
309-
.arguments(this.iri, id).build();
309+
.arguments(this.id, id).build();
310310
throw new InvalidSchemaException(error);
311311
}
312312
}
313313
}
314314
}
315315
Map<String, Keyword> result = createKeywordsMap(keywords, this.formats);
316-
return new Dialect(this.iri, this.idKeyword, result, this.vocabularies, this.specification, this);
316+
return new Dialect(this.id, this.idKeyword, result, this.vocabularies, this.specification, this);
317317
}
318318
}
319319

320-
private final String iri;
320+
private final String id;
321321
private final String idKeyword;
322322
private final Map<String, Keyword> keywords;
323323
private final Map<String, Boolean> vocabularies;
324324
private final Version specification;
325325

326326
private final Builder builder;
327327

328-
Dialect(String iri, String idKeyword, Map<String, Keyword> keywords, Map<String, Boolean> vocabularies, Version specification, Builder builder) {
329-
if (StringUtils.isBlank(iri)) {
330-
throw new IllegalArgumentException("iri must not be null or blank");
328+
Dialect(String dialectId, String idKeyword, Map<String, Keyword> keywords, Map<String, Boolean> vocabularies, Version specification, Builder builder) {
329+
if (StringUtils.isBlank(dialectId)) {
330+
throw new IllegalArgumentException("dialect id must not be null or blank");
331331
}
332332
if (StringUtils.isBlank(idKeyword)) {
333333
throw new IllegalArgumentException("idKeyword must not be null or blank");
@@ -336,7 +336,7 @@ public Dialect build() {
336336
throw new IllegalArgumentException("keywords must not be null ");
337337
}
338338

339-
this.iri = iri;
339+
this.id = dialectId;
340340
this.idKeyword = idKeyword;
341341
this.keywords = keywords;
342342
this.specification = specification;
@@ -347,37 +347,37 @@ public Dialect build() {
347347
/**
348348
* Create a builder without keywords or formats.
349349
*
350-
* @param iri the IRI of the metaschema that will be defined via this builder.
350+
* @param id the IRI of the dialect that will be defined via this builder.
351351
* @return a builder instance without any keywords or formats - usually not what one needs.
352352
*/
353-
public static Builder builder(String iri) {
354-
return new Builder(iri);
353+
public static Builder builder(String id) {
354+
return new Builder(id);
355355
}
356356

357357
/**
358358
* Create a builder.
359359
*
360-
* @param iri the IRI of your new JsonMetaSchema that will be defined via
360+
* @param id the IRI of your new Dialect that will be defined via
361361
* this builder.
362-
* @param blueprint the JsonMetaSchema to base your custom JsonMetaSchema on.
362+
* @param blueprint the Dialect to base your custom Dialect on.
363363
* @return a builder instance preconfigured to be the same as blueprint, but
364364
* with a different uri.
365365
*/
366-
public static Builder builder(String iri, Dialect blueprint) {
366+
public static Builder builder(String id, Dialect blueprint) {
367367
Builder builder = builder(blueprint);
368-
builder.iri = iri;
368+
builder.id = id;
369369
return builder;
370370
}
371371

372372
/**
373373
* Create a builder.
374374
*
375-
* @param blueprint the JsonMetaSchema to base your custom JsonMetaSchema on.
375+
* @param blueprint the Dialect to base your custom Dialect on.
376376
* @return a builder instance preconfigured to be the same as blueprint
377377
*/
378378
public static Builder builder(Dialect blueprint) {
379379
Map<String, Boolean> vocabularies = new HashMap<>(blueprint.getVocabularies());
380-
return builder(blueprint.getIri())
380+
return builder(blueprint.getId())
381381
.idKeyword(blueprint.idKeyword)
382382
.keywords(blueprint.builder.keywords.values())
383383
.formats(blueprint.builder.formats.values())
@@ -418,8 +418,8 @@ private static String readText(JsonNode node, String field) {
418418
return fieldNode == null ? null : fieldNode.textValue();
419419
}
420420

421-
public String getIri() {
422-
return this.iri;
421+
public String getId() {
422+
return this.id;
423423
}
424424

425425
public Map<String, Keyword> getKeywords() {
@@ -486,12 +486,12 @@ public KeywordValidator newValidator(SchemaContext schemaContext, SchemaLocation
486486

487487
@Override
488488
public String toString() {
489-
return this.iri;
489+
return this.id;
490490
}
491491

492492
@Override
493493
public int hashCode() {
494-
return Objects.hash(iri);
494+
return id.hashCode();
495495
}
496496

497497
@Override
@@ -503,6 +503,6 @@ public boolean equals(Object obj) {
503503
if (getClass() != obj.getClass())
504504
return false;
505505
Dialect other = (Dialect) obj;
506-
return Objects.equals(iri, other.iri);
506+
return Objects.equals(id, other.id);
507507
}
508508
}

0 commit comments

Comments
 (0)