Skip to content

Commit 2a9be81

Browse files
authored
Merge pull request #1 from json-schema-org/master
update
2 parents 6c00de6 + 8a12994 commit 2a9be81

File tree

162 files changed

+9128
-1639
lines changed

Some content is hidden

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

162 files changed

+9128
-1639
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
runs-on: ubuntu-latest
1515

1616
steps:
17-
- uses: actions/checkout@v1
17+
- uses: actions/checkout@v2
1818
- name: Set up Python
19-
uses: actions/setup-python@v1
19+
uses: actions/setup-python@v2
2020
with:
2121
python-version: 3.7
2222
- name: Install tox

README.md

+83-67
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
JSON Schema Test Suite [![Build Status](https://github.com/json-schema-org/JSON-Schema-Test-Suite/workflows/Test%20Suite%20Sanity%20Checking/badge.svg)](https://github.com/json-schema-org/JSON-Schema-Test-Suite/actions?query=workflow%3A%22Test+Suite+Sanity+Checking%22)
2-
======================
1+
# JSON Schema Test Suite [![Build Status](https://github.com/json-schema-org/JSON-Schema-Test-Suite/workflows/Test%20Suite%20Sanity%20Checking/badge.svg)](https://github.com/json-schema-org/JSON-Schema-Test-Suite/actions?query=workflow%3A%22Test+Suite+Sanity+Checking%22)
32

43
This repository contains a set of JSON objects that implementors of JSON Schema
54
validation libraries can use to test their validators.
@@ -9,110 +8,122 @@ It is meant to be language agnostic and should require only a JSON parser.
98
The conversion of the JSON objects into tests within your test framework of
109
choice is still the job of the validator implementor.
1110

12-
Structure of a Test
13-
-------------------
11+
## Structure of a Test
1412

15-
If you're going to use this suite, you need to know how tests are laid out. The
16-
tests are contained in the `tests` directory at the root of this repository.
13+
The tests in this suite are contained in the `tests` directory at the root of
14+
this repository. Inside that directory is a subdirectory for each draft or
15+
version of the specification.
1716

18-
Inside that directory is a subdirectory for each draft or version of the
19-
schema.
17+
Inside each draft directory, there are a number of `.json` files and one or more
18+
special subdirectories. The subdirectories contain `.json` files meant for a
19+
specific testing purpose, and each `.json` file logically groups a set of test
20+
cases together. Often the grouping is by property under test, but not always.
2021

21-
If you look inside the draft directory, there are a number of `.json` files,
22-
which logically group a set of test cases together. Often the grouping is by
23-
property under test, but not always, especially within optional test files
24-
(discussed below).
22+
The subdirectories are described in the next section.
2523

2624
Inside each `.json` file is a single array containing objects. It's easiest to
2725
illustrate the structure of these with an example:
2826

2927
```json
30-
{
31-
"description": "the description of the test case",
32-
"schema": {"the schema that should" : "be validated against"},
33-
"tests": [
34-
{
35-
"description": "a specific test of a valid instance",
36-
"data": "the instance",
37-
"valid": true
38-
},
39-
{
40-
"description": "another specific test this time, invalid",
41-
"data": 15,
42-
"valid": false
43-
}
44-
]
45-
}
28+
{
29+
"description": "The description of the test case",
30+
"schema": {
31+
"description": "The schema against which the data in each test is validated",
32+
"type": "string"
33+
},
34+
"tests": [
35+
{
36+
"description": "Test for a valid instance",
37+
"data": "the instance to validate",
38+
"valid": true
39+
},
40+
{
41+
"description": "Test for an invalid instance",
42+
"data": 15,
43+
"valid": false
44+
}
45+
]
46+
}
4647
```
4748

48-
So a description, a schema, and some tests, where tests is an array containing
49-
one or more objects with descriptions, data, and a boolean indicating whether
50-
they should be valid or invalid.
49+
In short: a description, a schema under test, and some tests, where each test
50+
in the `tests` array is an objects with a description of the case itself, the
51+
instance under test, and a boolean indicating whether it should be valid
52+
or invalid.
5153

52-
Coverage
53-
--------
54+
## Test Subdirectories
5455

55-
Drafts 07, 06, 04 and 03 should have full coverage, with drafts 06 and
56-
07 being considered current and actively supported.
56+
There is currently only one subdirectory that may exist within each draft
57+
directory. This is:
5758

58-
Draft 2019-09 support is under development. Contributions are very
59-
welcome, especially from implementers as they add support to their own
60-
implementations.
59+
1. `optional/`: Contains tests that are considered optional.
6160

62-
Bug fixes will be made as needed for draft-04 as it is still the most
63-
widely used, while draft-03 is long since deprecated.
61+
## Coverage
6462

65-
If you see anything missing from the current supported drafts, or incorrect
66-
on any draft still accepting bug fixes, please file an issue or submit a PR.
63+
Drafts 07, 06, 04, and 03 should have full coverage, with tests for drafts 06,
64+
07, and 2019-09 being considered current and actively supported. Draft 2019-09
65+
is almost fully covered.
6766

68-
Who Uses the Test Suite
69-
-----------------------
67+
Contributions are very welcome, especially from implementers as they add support
68+
to their own implementations.
69+
70+
If you see anything missing from the current supported drafts, or incorrect on
71+
any draft still accepting bug fixes, please
72+
[file an issue](https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues)
73+
or [submit a PR](https://github.com/json-schema-org/JSON-Schema-Test-Suite).
74+
75+
## Who Uses the Test Suite
7076

7177
This suite is being used by:
7278

73-
### Clojure ###
79+
### Clojure
7480

7581
* [jinx](https://github.com/juxt/jinx)
7682
* [json-schema](https://github.com/tatut/json-schema)
7783

78-
### Coffeescript ###
84+
### Coffeescript
7985

8086
* [jsck](https://github.com/pandastrike/jsck)
8187

82-
### C++ ###
88+
### Common Lisp
89+
90+
* [json-schema](https://github.com/fisxoj/json-schema)
91+
92+
### C++
8393

8494
* [Modern C++ JSON schema validator](https://github.com/pboettch/json-schema-validator)
8595

86-
### Dart ###
96+
### Dart
8797

8898
* [json_schema](https://github.com/patefacio/json_schema)
8999

90-
### Elixir ###
100+
### Elixir
91101

92102
* [ex_json_schema](https://github.com/jonasschmidt/ex_json_schema)
93103

94-
### Erlang ###
104+
### Erlang
95105

96106
* [jesse](https://github.com/for-GET/jesse)
97107

98-
### Go ###
108+
### Go
99109

100110
* [gojsonschema](https://github.com/sigu-399/gojsonschema)
101111
* [validate-json](https://github.com/cesanta/validate-json)
102112

103-
### Haskell ###
113+
### Haskell
104114

105115
* [aeson-schema](https://github.com/timjb/aeson-schema)
106116
* [hjsonschema](https://github.com/seagreen/hjsonschema)
107117

108-
### Java ###
118+
### Java
109119

110120
* [json-schema-validator](https://github.com/daveclayton/json-schema-validator)
111121
* [everit-org/json-schema](https://github.com/everit-org/json-schema)
112122
* [networknt/json-schema-validator](https://github.com/networknt/json-schema-validator)
113123
* [Justify](https://github.com/leadpony/justify)
124+
* [Snow](https://github.com/ssilverman/snowy-json)
114125

115-
### JavaScript ###
126+
### JavaScript
116127

117128
* [json-schema-benchmark](https://github.com/Muscula/json-schema-benchmark)
118129
* [direct-schema](https://github.com/IreneKnapp/direct-schema)
@@ -130,7 +141,7 @@ This suite is being used by:
130141
* [ajv](https://github.com/epoberezkin/ajv)
131142
* [djv](https://github.com/korzio/djv)
132143

133-
### Node.js ###
144+
### Node.js
134145

135146
For node.js developers, the suite is also available as an
136147
[npm](https://www.npmjs.com/package/@json-schema-org/tests) package.
@@ -139,49 +150,54 @@ Node-specific support is maintained in a [separate
139150
repository](https://github.com/json-schema-org/json-schema-test-suite-npm)
140151
which also welcomes your contributions!
141152

142-
### .NET ###
153+
### .NET
143154

144155
* [Newtonsoft.Json.Schema](https://github.com/JamesNK/Newtonsoft.Json.Schema)
145156
* [Manatee.Json](https://github.com/gregsdennis/Manatee.Json)
146157

147-
### PHP ###
158+
### Perl
159+
160+
* [JSON::Schema::Draft201909](https://github.com/karenetheridge/JSON-Schema-Draft201909)
161+
* [Test::JSON::Schema::Acceptance](https://github.com/karenetheridge/Test-JSON-Schema-Acceptance)
162+
163+
### PHP
148164

149165
* [json-schema](https://github.com/justinrainbow/json-schema)
150166
* [json-guard](https://github.com/thephpleague/json-guard)
151167

152-
### PostgreSQL ###
168+
### PostgreSQL
153169

154170
* [postgres-json-schema](https://github.com/gavinwahl/postgres-json-schema)
155171
* [is_jsonb_valid](https://github.com/furstenheim/is_jsonb_valid)
156172

157-
### Python ###
173+
### Python
158174

159175
* [jsonschema](https://github.com/Julian/jsonschema)
160176
* [fastjsonschema](https://github.com/seznam/python-fastjsonschema)
161177
* [hypothesis-jsonschema](https://github.com/Zac-HD/hypothesis-jsonschema)
162178

163-
### Ruby ###
179+
### Ruby
164180

165181
* [json-schema](https://github.com/hoxworth/json-schema)
166182
* [json_schemer](https://github.com/davishmcclurg/json_schemer)
167183

168-
### Rust ###
184+
### Rust
169185

186+
* [jsonschema](https://github.com/Stranger6667/jsonschema-rs)
170187
* [valico](https://github.com/rustless/valico)
171188

172-
### Swift ###
189+
### Swift
173190

174191
* [JSONSchema](https://github.com/kylef/JSONSchema.swift)
175192

176193
If you use it as well, please fork and send a pull request adding yourself to
177194
the list :).
178195

179-
Contributing
180-
------------
196+
## Contributing
181197

182198
If you see something missing or incorrect, a pull request is most welcome!
183199

184-
There are some sanity checks in place for testing the test suite. You
185-
can run them with `bin/jsonschema_suite check` or `tox`. They will be
186-
run automatically by [GitHub Actions](https://github.com/json-schema-org/JSON-Schema-Test-Suite/actions?query=workflow%3A%22Test+Suite+Sanity+Checking%22)
200+
There are some sanity checks in place for testing the test suite. You can run
201+
them with `bin/jsonschema_suite check` or `tox`. They will be run automatically
202+
by [GitHub Actions](https://github.com/json-schema-org/JSON-Schema-Test-Suite/actions?query=workflow%3A%22Test+Suite+Sanity+Checking%22)
187203
as well.

bin/jsonschema_suite

+13-8
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@ if getattr(unittest, "skipIf", None) is None:
1717
unittest.skipIf = lambda cond, msg : lambda fn : fn
1818

1919
try:
20-
import jsonschema
20+
import jsonschema.validators
2121
except ImportError:
2222
jsonschema = None
23-
else:
24-
validators = getattr(
25-
jsonschema.validators, "validators", jsonschema.validators
26-
)
2723

2824

2925
ROOT_DIR = os.path.abspath(
@@ -49,7 +45,15 @@ REMOTES = {
4945
u"integer": {u"type": u"integer"},
5046
u"refToInteger": {u"$ref": u"#/integer"},
5147
},
52-
"folder/folderInteger.json": {u"type": u"integer"}
48+
"subSchemas-defs.json": {
49+
u"$defs": {
50+
u"integer": {u"type": u"integer"},
51+
u"refToInteger": {u"$ref": u"#/$defs/integer"},
52+
}
53+
},
54+
"baseUriChange/folderInteger.json": {u"type": u"integer"},
55+
"baseUriChangeFolder/folderInteger.json": {u"type": u"integer"},
56+
"baseUriChangeFolderInSubschema/folderInteger.json": {u"type": u"integer"},
5357
}
5458
REMOTES_DIR = os.path.join(ROOT_DIR, "remotes")
5559

@@ -120,7 +124,7 @@ class SanityTests(unittest.TestCase):
120124
@unittest.skipIf(jsonschema is None, "Validation library not present!")
121125
def test_all_schemas_are_valid(self):
122126
for schema in os.listdir(SUITE_ROOT_DIR):
123-
schema_validator = validators.get(schema)
127+
schema_validator = jsonschema.validators.validators.get(schema)
124128
if schema_validator is not None:
125129
test_files = collect(os.path.join(SUITE_ROOT_DIR, schema))
126130
for case in cases(test_files):
@@ -134,7 +138,8 @@ class SanityTests(unittest.TestCase):
134138

135139
@unittest.skipIf(jsonschema is None, "Validation library not present!")
136140
def test_suites_are_valid(self):
137-
validator = jsonschema.Draft4Validator(TESTSUITE_SCHEMA)
141+
Validator = jsonschema.validators.validator_for(TESTSUITE_SCHEMA)
142+
validator = Validator(TESTSUITE_SCHEMA)
138143
for tests in files(self.test_files):
139144
try:
140145
validator.validate(tests)

index.js

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const Ajv = require('ajv');
44
const jsonSchemaTest = require('json-schema-test');
5-
const assert = require('assert');
65

76
const refs = {
87
'http://localhost:1234/integer.json': require('./remotes/integer.json'),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "integer"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "integer"
3+
}

remotes/subSchemas-defs.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$defs": {
3+
"integer": {
4+
"type": "integer"
5+
},
6+
"refToInteger": {
7+
"$ref": "#/$defs/integer"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)