Skip to content

Commit bae3ca0

Browse files
committed
update
1 parent a684c84 commit bae3ca0

30 files changed

+503
-251
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ Assertions contains the following additional information
366366
| Message Key | The message key used for generating the message for localization. |
367367
| Arguments | The arguments used for generating the message. |
368368
| Keyword | The keyword that generated the message. |
369-
| Schema Node | The `JsonNode` pointed to by the Schema Location. This is the schema data that caused the input data to fail. It is possible to get the location information by configuring the `JsonSchemaFactory` with a `JsonNodeReader` that uses the `LocationJsonNodeFactoryFactory` and using `JsonNodes.tokenLocationOf(schemaNode)`. |
370-
| Instance Node | The `JsonNode` pointed to by the Instance Location. This is the input data that failed validation. It is possible to get the location information by configuring the `JsonSchemaFactory` with a `JsonNodeReader` that uses the `LocationJsonNodeFactoryFactory` and using `JsonNodes.tokenLocationOf(instanceNode)`. |
369+
| Schema Node | The `JsonNode` pointed to by the Schema Location. This is the schema data that caused the input data to fail. It is possible to get the location information by configuring the `SchemaRegistry` with a `NodeReader` that uses the `LocationJsonNodeFactoryFactory` and using `JsonNodes.tokenStreamLocationOf(schemaNode)`. |
370+
| Instance Node | The `JsonNode` pointed to by the Instance Location. This is the input data that failed validation. It is possible to get the location information by configuring the `SchemaRegistry` with a `NodeReader` that uses the `LocationJsonNodeFactoryFactory` and using `JsonNodes.tokenStreamLocationOf(instanceNode)`. |
371371
| Error | The error. |
372372
| Details | Additional details that can be set by custom keyword validator implementations. The library will set the `property` and `index` details for certain errors. For instane the `required` keyword will set the `property`. Note that this is not part of the instance location as that points to the instance node. |
373373

@@ -381,7 +381,7 @@ Annotations contains the following additional information
381381

382382
The library can be configured to store line and column information in the `JsonNode` instances for the instance and schema nodes. This will adversely affect performance and is not configured by default.
383383

384-
This is done by configuring a `NodeReader` that uses the `LocationJsonNodeFactoryFactory`on the `SchemaRegistry`. The `JsonLocation` information can then be retrieved using `JsonNodes.tokenStreamLocationOf(jsonNode)`.
384+
This is done by configuring a `NodeReader` that uses the `LocationJsonNodeFactoryFactory` on the `SchemaRegistry`. The `JsonLocation` information can then be retrieved using `JsonNodes.tokenStreamLocationOf(jsonNode)`.
385385

386386
```java
387387
String schemaData = "{\r\n"
@@ -554,23 +554,23 @@ The following is sample output from the Hierarchical format.
554554
| `failFast` | Whether to return failure immediately when an assertion is generated. | `false` |
555555
| `formatAssertionsEnabled` | The default is to generate format assertions from Draft 4 to Draft 7 and to only generate annotations from Draft 2019-09. Setting to `true` or `false` will override the default behavior. | `null` |
556556
| `locale` | The locale to use for generating messages in `Error`. | `Locale.getDefault()` |
557-
| `losslessNarrowing` | Whether lossless narrowing is used for the `type` keyword. | `false` |
557+
| `losslessNarrowing` | Whether lossless narrowing is used for the `type` keyword. Since Draft 6 a value of `1.0` is interpreted as an integer whether or not this is enabled. | `false` |
558558
| `messageSource` | This is used to retrieve the locale specific messages. | `DefaultMessageSource.getInstance()` |
559559
| `pathType` | The path type to use for reporting the instance location and evaluation path. Set to `PathType.JSON_PATH` to use JSON Path. | `PathType.JSON_POINTER` |
560-
| `preloadJsonSchema` | Whether the schema will be preloaded before processing any input. This will use memory but the execution of the validation will be faster. | `true` |
560+
| `preloadSchema` | Whether the schema will be preloaded before processing any input. This will use memory but the execution of the validation will be faster. | `true` |
561561
| `regularExpressionFactory` | The factory to use to create regular expressions for instance `JoniRegularExpressionFactory` or `GraalJSRegularExpressionFactory`. This requires the dependency to be manually added to the project or a `ClassNotFoundException` will be thrown. | `JDKRegularExpressionFactory.getInstance()` |
562562
| `schemaIdValidator` | This is used to customize how the `$id` values are validated. Note that the default implementation allows non-empty fragments where no base IRI is specified and also allows non-absolute IRI `$id` values in the root schema. | `JsonSchemaIdValidator.DEFAULT` |
563-
| `strict` | This is set whether keywords are strict in their validation. What this does depends on the individual validators. |
563+
| `strict` | This is set whether keywords are strict in their validation. What this does depends on the individual validators. | |
564564
| `typeLoose` | Whether types are interpreted in a loose manner. If set to true, a single value can be interpreted as a size 1 array. Strings may also be interpreted as number, integer or boolean. | `false` |
565565

566566
### Walk Configuration
567567

568568
| Name | Description | Default Value |
569569
| ---------------------------- | ------------------------------------------------------------------------------------------- | ----------------------------------------------------- |
570570
| `applyDefaultsStrategy` | The strategy for applying defaults when walking when missing or null nodes are encountered. | `ApplyDefaultsStrategy.EMPTY_APPLY_DEFAULTS_STRATEGY` |
571-
| `keywordWalkListenerRunner` | The `WalkListenerRunner` triggered for keywords. | `NoOpWalkListenerRunner.getInstance()` |
572-
| `propertyWalkListenerRunner` | The `WalkListenerRunner` triggered for properties. | `NoOpWalkListenerRunner.getInstance()` |
573-
| `itemWalkListenerRunner` | The `WalkListenerRunner` triggered for items. | `NoOpWalkListenerRunner.getInstance()` |
571+
| `keywordWalkHandler` | The `WalkHandler` triggered for keywords. | `NoOpWalkHandler.getInstance()` |
572+
| `propertyWalkHandler` | The `WalkHandler` triggered for properties. | `NoOpWalkHandler.getInstance()` |
573+
| `itemWalkHandler` | The `WalkHandler` triggered for items. | `NoOpWalkHandler.getInstance()` |
574574

575575
## Performance Considerations
576576

@@ -603,7 +603,7 @@ The library assumes that the schemas being loaded are trusted. This security mod
603603

604604
## [OpenAPI Specification](doc/openapi.md)
605605

606-
## [JSON Schema Walkers and WalkListeners](doc/walkers.md)
606+
## [Schema Walkers](doc/walkers.md)
607607

608608
## [Regular Expressions](doc/ecma-262.md)
609609

doc/schema-retrieval.md

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ String schemaData = "{\r\n"
1515
+ " \"type\": \"integer\"\r\n"
1616
+ "}";
1717
Map<String, String> schemas = Collections.singletonMap("https://www.example.com/integer.json", schemaData);
18-
JsonSchemaFactory schemaFactory = JsonSchemaFactory
19-
.getInstance(VersionFlag.V7,
20-
builder -> builder.schemaLoaders(schemaLoaders -> schemaLoaders.schemas(schemas)));
18+
SchemaRegistry schemaRegistry = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_7,
19+
builder -> builder.schemas(schemas));
2120
```
2221

2322
Schemas can be loaded through a function.
@@ -27,9 +26,8 @@ String schemaData = "{\r\n"
2726
+ " \"type\": \"integer\"\r\n"
2827
+ "}";
2928
Map<String, String> schemas = Collections.singletonMap("https://www.example.com/integer.json", schemaData);
30-
JsonSchemaFactory schemaFactory = JsonSchemaFactory
31-
.getInstance(VersionFlag.V7,
32-
builder -> builder.schemaLoaders(schemaLoaders -> schemaLoaders.schemas(schemas::get)));
29+
SchemaRegistry schemaRegistry = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_7,
30+
builder -> builder.schemas(schemas::get));
3331
```
3432

3533
Schemas can also be loaded in the following manner.
@@ -52,9 +50,8 @@ String schemaData = "{\r\n"
5250
+ "}";
5351
Map<String, RegistryEntry> registry = Collections
5452
.singletonMap("https://www.example.com/integer.json", new RegistryEntry(schemaData));
55-
JsonSchemaFactory schemaFactory = JsonSchemaFactory
56-
.getInstance(VersionFlag.V7, builder -> builder
57-
.schemaLoaders(schemaLoaders -> schemaLoaders.schemas(registry::get, RegistryEntry::getSchemaData)));
53+
SchemaRegistry schemaRegistry = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_7,
54+
builder -> builder.schemas(registry::get, RegistryEntry::getSchemaData));
5855
```
5956

6057
## Mapping Schema Identifier to Retrieval IRI
@@ -64,9 +61,9 @@ The schema identifier can be mapped to the retrieval IRI by implementing the `Sc
6461
### Configuring Schema Mapper
6562

6663
```java
67-
class CustomSchemaMapper implements SchemaMapper {
64+
class CustomSchemaIdResolver implements SchemaIdResolver {
6865
@Override
69-
public AbsoluteIri map(AbsoluteIri absoluteIRI) {
66+
public AbsoluteIri resolve(AbsoluteIri absoluteIRI) {
7067
String iri = absoluteIRI.toString();
7168
if ("https://www.example.com/integer.json".equals(iri)) {
7269
return AbsoluteIri.of("classpath:schemas/integer.json");
@@ -75,20 +72,19 @@ class CustomSchemaMapper implements SchemaMapper {
7572
}
7673
}
7774

78-
JsonSchemaFactory schemaFactory = JsonSchemaFactory
79-
.getInstance(VersionFlag.V7,
80-
builder -> builder.schemaMappers(schemaMappers -> schemaMappers.add(new CustomSchemaMapper())));
75+
SchemaRegistry schemaRegistry = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_7,
76+
builder -> builder
77+
.schemaIdResolvers(schemaIdResolvers -> schemaIdResolvers.add(new CustomSchemaIdResolver())))
8178
```
8279

8380
### Configuring Prefix Mappings
8481

8582
```java
86-
JsonSchemaFactory schemaFactory = JsonSchemaFactory
87-
.getInstance(VersionFlag.V7,
88-
builder -> builder
89-
.schemaMappers(schemaMappers -> schemaMappers
90-
.mapPrefix("https://json-schema.org", "classpath:")
91-
.mapPrefix("http://json-schema.org", "classpath:")));
83+
SchemaRegistry schemaRegistry = SchemaRegistry
84+
.withDefaultDialect(SpecificationVersion.DRAFT_7,
85+
builder -> builder.schemaIdResolvers(schemaIdResolvers -> schemaIdResolvers
86+
.mapPrefix("https://json-schema.org", "classpath:")
87+
.mapPrefix("http://json-schema.org", "classpath:")));
9288
```
9389

9490
### Configuring Mappings
@@ -97,9 +93,9 @@ JsonSchemaFactory schemaFactory = JsonSchemaFactory
9793
Map<String, String> mappings = Collections
9894
.singletonMap("https://www.example.com/integer.json", "classpath:schemas/integer.json");
9995

100-
JsonSchemaFactory schemaFactory = JsonSchemaFactory
101-
.getInstance(VersionFlag.V7,
102-
builder -> builder.schemaMappers(schemaMappers -> schemaMappers.mappings(mappings)));
96+
SchemaRegistry schemaRegistry = SchemaRegistry
97+
.withDefaultDialect(SpecificationVersion.DRAFT_7,
98+
builder -> builder.schemaIdResolvers(schemaIdResolvers -> schemaIdResolvers.mappings(mappings)));
10399
```
104100

105101
## Customizing Network Schema Retrieval
@@ -108,17 +104,17 @@ The default `UriSchemaLoader` implementation uses JDK connection/socket without
108104

109105
### Configuring Custom URI Schema Loader
110106

111-
The default `UriSchemaLoader` can be overwritten in order to customize its behaviour in regards of authorization or error handling.
107+
The default `IriResourceLoader` can be overwritten in order to customize its behaviour in regards of authorization or error handling.
112108

113-
The `SchemaLoader` interface must implemented and the implementation configured on the `JsonSchemaFactory`.
109+
The `ResourceLoader` interface must implemented and the implementation configured on the `SchemaRegistry`.
114110

115111
```java
116-
public class CustomUriSchemaLoader implements SchemaLoader {
117-
private static final Logger LOGGER = LoggerFactory.getLogger(CustomUriSchemaLoader.class);
112+
public class CustomUriResourceLoader implements ResourceLoader {
113+
private static final Logger LOGGER = LoggerFactory.getLogger(CustomUriResourceLoader.class);
118114
private final String authorizationToken;
119115
private final HttpClient client;
120116

121-
public CustomUriSchemaLoader(String authorizationToken) {
117+
public CustomUriResourceLoader(String authorizationToken) {
122118
this.authorizationToken = authorizationToken;
123119
this.client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build();
124120
}
@@ -147,12 +143,12 @@ public class CustomUriSchemaLoader implements SchemaLoader {
147143
}
148144
```
149145

150-
Within the `JsonSchemaFactory` the custom `SchemaLoader` must be configured.
146+
Within the `SchemaRegistry` the custom `ResourceLoader` must be configured.
151147

152148
```java
153-
CustomUriSchemaLoader uriSchemaLoader = new CustomUriSchemaLoader(authorizationToken);
149+
CustomUriResourceLoader uriResourceLoader = new CustomUriResourceLoader(authorizationToken);
154150

155-
JsonSchemaFactory schemaFactory = JsonSchemaFactory
156-
.getInstance(VersionFlag.V7,
157-
builder -> builder.schemaLoaders(schemaLoaders -> schemaLoaders.add(uriSchemaLoader)));
151+
SchemaRegistry schemaRegistry = SchemaRegistry
152+
.withDefaultDialect(SpecificationVersion.DRAFT_7,
153+
builder -> builder.resourceLoaders(resourceLoaders -> resourceLoaders.add(uriSchemaLoader)));
158154
```

0 commit comments

Comments
 (0)