Skip to content

Commit 75b89d9

Browse files
committed
Rename Specification.Version to SpecificationVersion and refactor
1 parent 0ccbbc7 commit 75b89d9

File tree

151 files changed

+505
-653
lines changed

Some content is hidden

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

151 files changed

+505
-653
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import com.fasterxml.jackson.databind.JsonNode;
3333
import com.fasterxml.jackson.databind.node.ObjectNode;
34-
import com.networknt.schema.Specification.Version;
3534
import com.networknt.schema.keyword.DiscriminatorValidator;
3635
import com.networknt.schema.keyword.KeywordValidator;
3736
import com.networknt.schema.keyword.TypeValidator;
@@ -51,7 +50,7 @@
5150
* modified.
5251
*/
5352
public class Schema implements Validator {
54-
private static final long DRAFT_2019_09_VALUE = Version.DRAFT_2019_09.getOrder();
53+
private static final long DRAFT_2019_09_VALUE = SpecificationVersion.DRAFT_2019_09.getOrder();
5554
private final String id;
5655

5756
/**
@@ -656,7 +655,7 @@ private List<KeywordValidator> read(JsonNode schemaNode) {
656655
}
657656

658657
// Ignore siblings for older drafts
659-
if (null != refValidator && getSchemaContext().getDialect().getSpecification().getOrder() < DRAFT_2019_09_VALUE) {
658+
if (null != refValidator && getSchemaContext().getDialect().getSpecificationVersion().getOrder() < DRAFT_2019_09_VALUE) {
660659
validators.clear();
661660
validators.add(refValidator);
662661
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@
1616

1717
package com.networknt.schema;
1818

19-
import java.util.Optional;
2019
import java.util.concurrent.ConcurrentHashMap;
2120
import java.util.concurrent.ConcurrentMap;
2221

2322
import com.fasterxml.jackson.databind.JsonNode;
24-
import com.networknt.schema.Specification.Version;
2523
import com.networknt.schema.dialect.Dialect;
2624
import com.networknt.schema.keyword.KeywordValidator;
2725

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.networknt.schema;
1818

1919
import com.fasterxml.jackson.databind.JsonNode;
20-
import com.networknt.schema.Specification.Version;
2120
import com.networknt.schema.dialect.BasicDialectRegistry;
2221
import com.networknt.schema.dialect.DefaultDialectRegistry;
2322
import com.networknt.schema.dialect.Dialect;
@@ -174,7 +173,7 @@ public SchemaLoader getSchemaLoader() {
174173
* Builder without keywords or formats.
175174
* <p>
176175
* Typically {@link #builder(SchemaRegistry)} or
177-
* {@link #withDefaultDialect(Version)} or {@link #withDialect(Dialect)} would be used instead.
176+
* {@link #withDefaultDialect(SpecificationVersion)} or {@link #withDialect(Dialect)} would be used instead.
178177
*
179178
* @return a builder instance without any keywords or formats - usually not what
180179
* one needs.
@@ -192,7 +191,7 @@ public static Builder builder() {
192191
* not specify the $schema keyword
193192
* @return the factory
194193
*/
195-
public static SchemaRegistry withDefaultDialect(Specification.Version specificationVersion) {
194+
public static SchemaRegistry withDefaultDialect(SpecificationVersion specificationVersion) {
196195
return withDefaultDialect(specificationVersion, null);
197196
}
198197

@@ -206,7 +205,7 @@ public static SchemaRegistry withDefaultDialect(Specification.Version specificat
206205
* @param customizer to customize the registry
207206
* @return the factory
208207
*/
209-
public static SchemaRegistry withDefaultDialect(Specification.Version specificationVersion,
208+
public static SchemaRegistry withDefaultDialect(SpecificationVersion specificationVersion,
210209
Consumer<SchemaRegistry.Builder> customizer) {
211210
Dialect dialect = Specification.getDialect(specificationVersion);
212211
return withDefaultDialectId(dialect.getId(), customizer);
@@ -628,7 +627,7 @@ private boolean isYaml(final SchemaLocation schemaUri) {
628627
*/
629628
static protected String normalizeDialectId(String id) {
630629
boolean found = false;
631-
for (Version flag : Specification.Version.values()) {
630+
for (SpecificationVersion flag : SpecificationVersion.values()) {
632631
if(flag.getDialectId().equals(id)) {
633632
found = true;
634633
break;

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

Lines changed: 0 additions & 152 deletions
This file was deleted.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2020 Network New Technologies Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.networknt.schema;
17+
18+
import java.util.Optional;
19+
20+
import com.networknt.schema.dialect.DialectId;
21+
22+
/**
23+
* The version of the JSON Schema specification that defines the standard
24+
* dialects.
25+
*/
26+
public enum SpecificationVersion {
27+
/**
28+
* Draft 4.
29+
*/
30+
DRAFT_4(4, DialectId.DRAFT_4),
31+
/**
32+
* Draft 6.
33+
*/
34+
DRAFT_6(6, DialectId.DRAFT_6),
35+
/**
36+
* Draft 7.
37+
*/
38+
DRAFT_7(7, DialectId.DRAFT_7),
39+
/**
40+
* Draft 2019-09.
41+
*/
42+
DRAFT_2019_09(8, DialectId.DRAFT_2019_09),
43+
/**
44+
* Draft 2020-12.
45+
*/
46+
DRAFT_2020_12(9, DialectId.DRAFT_2020_12);
47+
48+
private final int order;
49+
private final String dialectId;
50+
51+
SpecificationVersion(int order, String dialectId) {
52+
this.order = order;
53+
this.dialectId = dialectId;
54+
}
55+
56+
/**
57+
* Gets the dialect id used for the $schema keyword. The dialect id is an IRI
58+
* that identifies the meta schema used to validate the dialect.
59+
*
60+
* @return the dialect id
61+
*/
62+
public String getDialectId() {
63+
return this.dialectId;
64+
}
65+
66+
/**
67+
* Gets the unique release order of the specification version used that
68+
* indicates when the specification was released. Lower numbers indicate the
69+
* specification was released earlier.
70+
*
71+
* @return the order when the specification was released
72+
*/
73+
public int getOrder() {
74+
return this.order;
75+
}
76+
77+
/**
78+
* Gets the specification version that matches the dialect id indicated by
79+
* $schema keyword. The dialect id is an IRI that identifies the meta schema
80+
* used to validate the dialect.
81+
*
82+
* @param dialectId the dialect id specified by $schema keyword
83+
* @return the specification version if it matches the dialect id
84+
*/
85+
public static Optional<SpecificationVersion> fromDialectId(String dialectId) {
86+
for (SpecificationVersion version : SpecificationVersion.values()) {
87+
if (version.dialectId.equals(dialectId)) {
88+
return Optional.of(version);
89+
}
90+
}
91+
return Optional.empty();
92+
}
93+
}

0 commit comments

Comments
 (0)