Skip to content

Commit 84d76ed

Browse files
committed
draft-6 related docs
* noting in introduction that this is the only implementation which supports Draft 6 * installation method: changing to jitpack * section about draft-4 and draft-6 * schemaLocation docs * listing new formats
1 parent 43658bb commit 84d76ed

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

README.md

Lines changed: 43 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,25 @@ try (InputStream inputStream = getClass().getResourceAsStream("/path/to/your/sch
7182
}
7283
```
7384

85+
## Draft 4 or draft 6?
86+
87+
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.
88+
89+
Quick reference:
90+
* if there is `"$schema": "http://json-schema.org/draft-04/schema"` in the schema root, then Draft 4 will be used
91+
* if there is `"$schema": "http://json-schema.org/draft-06/schema"` in the schema root, then Draft 6 will be used
92+
* if none of these is found then Draft 4 will be assumed as default
93+
94+
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:
95+
96+
```java
97+
SchemaLoader loader = SchemaLoader.builder()
98+
.schemaJson(yourSchemaJSON)
99+
.draftV6Support()
100+
.build();
101+
Schema schema = loader.load().build();
102+
```
103+
74104
## Investigating failures
75105

76106

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

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

176210
## Format validators
177211

@@ -185,6 +219,12 @@ Starting from version `1.2.0` the library supports the [`"format"` keyword][draf
185219
* ipv4
186220
* ipv6
187221
* uri
222+
223+
If you use the library in Draft 6 mode, then the followings are also supported:
224+
225+
* uri-reference
226+
* uri-template
227+
* json-pointer
188228

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

0 commit comments

Comments
 (0)