Skip to content

Commit b1d97be

Browse files
committed
Merge branch 'v6-docs'
2 parents 0e76768 + 446f44f commit b1d97be

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

README.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [When to use this library?](#when-to-use-this-library)
66
* [Maven installation](#maven-installation)
77
* [Java7 version](#java7-version)
8+
* [Draft 4 or Draft 6?](#draft-4-or-draft-6)
89
* [Quickstart](#quickstart)
910
* [Investigating failures](#investigating-failures)
1011
* [JSON report of the failures](#json-report-of-the-failures)
@@ -13,7 +14,7 @@
1314
* [Resolution scopes](#resolution-scopes)
1415

1516

16-
This project is an implementation of the [JSON Schema Core Draft v4][draft-zyp-json-schema-04] specification.
17+
This project is an implementation of the JSON Schema [Draft v4][draft-zyp-json-schema-04] and [Draft-6](https://tools.ietf.org/html/draft-wright-json-schema-01) specifications.
1718
It uses the [org.json API](http://stleary.github.io/JSON-java/) (created by Douglas Crockford) for representing JSON data.
1819

1920
# When to use this library?
@@ -23,6 +24,7 @@ But - as you may have already discovered - there is also an [other Java implemen
2324
of the JSON Schema specification. So here are some advices about which one to use:
2425
* if you use Jackson to handle JSON in Java code, then [daveclayton/json-schema-validator] is obviously a better choice, since it uses Jackson
2526
* if you want to use the [org.json API](http://www.json.org/java/) then this library is the better choice
27+
* if you need JSON Schema Draft 6 support, then you need this library.
2628
* if you want to use anything else for handling JSON (like GSON or javax.json), then you are in a little trouble, since
2729
currently there is no schema validation library backed by these libraries. It means that you will have to parse the JSON
2830
twice: once for the schema validator, and once for your own processing. In a case like that, this library is probably still
@@ -37,12 +39,21 @@ Add the following to your `pom.xml`:
3739

3840
```xml
3941
<dependency>
40-
<groupId>org.everit.json</groupId>
42+
<groupId>com.github.everit-org.json-schema</groupId>
4143
<artifactId>org.everit.json.schema</artifactId>
42-
<version>1.5.1</version>
44+
<version>1.6.0</version>
4345
</dependency>
46+
...
47+
<repositories>
48+
<repository>
49+
<id>jitpack.io</id>
50+
<url>https://jitpack.io</url>
51+
</repository>
52+
</repositories>
4453
```
4554

55+
_Note_: from version `1.6.0`, the library is primarily distributed through JitPack. Previous versions are also available through maven central.
56+
4657
### Java7 version
4758

4859
If you are looking for a version which works on Java7, then you can use this artifact, kindly backported by [Doctusoft](https://doctusoft.com/):
@@ -71,6 +82,28 @@ try (InputStream inputStream = getClass().getResourceAsStream("/path/to/your/sch
7182
}
7283
```
7384

85+
## Draft 4 or draft 6?
86+
87+
JSON Schema has currently 3 major releases, Draft 3, Draft 4 and Draft 6. This library implements the 2 newer ones, you can have a quick look at the differences [here](https://github.com/json-schema-org/json-schema-spec/wiki/FAQ:-draft-wright-json-schema%5B-validation%5D-01#changes).
88+
Since the two versions have a number of differences - and draft 6 is not backwards-compatible with draft 4 - it is good to know which version will you use.
89+
90+
The best way to denote the JSON Schema version you want to use is to include its meta-schema URL in the document root with the `"$schema"` key. This is a common notation, facilitated by the library to determine which version should be used.
91+
92+
Quick reference:
93+
* if there is `"$schema": "http://json-schema.org/draft-04/schema"` in the schema root, then Draft 4 will be used
94+
* if there is `"$schema": "http://json-schema.org/draft-06/schema"` in the schema root, then Draft 6 will be used
95+
* if none of these is found then Draft 4 will be assumed as default
96+
97+
If you want to specify the meta-schema version explicitly then you can change the default from Draft 4 to Draft 6 by configuring the loader this way:
98+
99+
```java
100+
SchemaLoader loader = SchemaLoader.builder()
101+
.schemaJson(yourSchemaJSON)
102+
.draftV6Support()
103+
.build();
104+
Schema schema = loader.load().build();
105+
```
106+
74107
## Investigating failures
75108

76109

@@ -169,9 +202,13 @@ following keys:
169202
* `"keyword"`: the JSON Schema keyword which was violated
170203
* `"pointerToViolation"`: a JSON Pointer denoting the path from the input document root to its fragment which caused
171204
the validation failure
205+
* `"schemaLocation"`: a JSON Pointer denoting the path from the schema JSON root to the violated keyword
172206
* `"causingExceptions"`: a (possibly empty) array of sub-exceptions. Each sub-exception is represented as a JSON object,
173207
with the same structure as described in this listing. See more above about causing exceptions.
174208

209+
Please take into account that the complete failure report is a *hierarchical tree structure*: sub-causes of a cause can
210+
be obtained using `#getCausingExceptions()` .
211+
175212

176213
## Format validators
177214

@@ -185,6 +222,12 @@ Starting from version `1.2.0` the library supports the [`"format"` keyword][draf
185222
* ipv4
186223
* ipv6
187224
* uri
225+
226+
If you use the library in Draft 6 mode, then the followings are also supported:
227+
228+
* uri-reference
229+
* uri-template
230+
* json-pointer
188231

189232
The library also supports adding custom format validators. To use a custom validator basically you have to
190233

0 commit comments

Comments
 (0)