Skip to content

Commit 04fa59d

Browse files
authored
Update README.md
1 parent 9413abe commit 04fa59d

File tree

1 file changed

+74
-5
lines changed

1 file changed

+74
-5
lines changed

README.md

+74-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,83 @@
1-
# jsonsubschema
1+
# jsonsubschema #
22

33
[![Travis build status](https://travis-ci.com/IBM/jsonsubschema.svg?branch=master)](https://travis-ci.com/IBM/jsonsubschema) [![Codecov code coverage](https://codecov.io/gh/IBM/jsonsubschema/branch/master/graph/badge.svg)](https://codecov.io/gh/IBM/jsonsubschema)
44

5+
**JSON subschema** checks if one JSON schema is a subschema (subtype) of another.
56

6-
This tool checks if one JSON schema is subtype of another.
7-
For two JSON schemas s1 and s2, s1 <: s2 (reads s1 is subtype/subset or subschema of s2)
8-
is every instance that validates against s1 also validates against s2.
7+
For any two JSON schemas s1 and s2, s1 <: s2 (reads s1 is subschema/subtype of s2)
8+
if every JSON document instance that validates against s1 also validates against s2.
9+
10+
JSON subschema is very useful in analysing schema evolution and ensuring that newer schema versions are backward compatible.
11+
subschema also enables static type checking on different components of a system that uses JSON schema to describe data
12+
interfaces among the system's different components.
13+
14+
The details of JSON subschema are covered in our [**ISSTA 2021** paper](https://andrewhabib.org/publications/issta21-paper-JSONSubschema.pdf):
15+
16+
```
17+
@InProceedings{issta21JSONsubschema,
18+
author = {Andrew Habib, Avraham Shinnar, Martin Hirzel, Michael Pradel},
19+
title = {Finding Data Compatibility Bugs with JSON Subschema Checking},
20+
booktitle = {The ACM SIGSOFT International Symposium on Software Testing and Analysis (ISSTA)},
21+
year = {2021},
22+
}
23+
```
24+
25+
26+
## I) Obtaining the tool ##
27+
28+
### Requirements ###
29+
30+
* python 3.8.*
31+
* Other python dependencies will be installed during the below setup process
32+
33+
You can either install subschema from the source code from github or the pypy package.
34+
35+
### A) Install from github source code ###
36+
Execute the following:
37+
```
38+
git clone https://github.com/IBM/jsonsubschema.git
39+
cd jsonsubschema
40+
python setup.py install
41+
cd ..
42+
```
43+
44+
### B) Install from pypy ###
45+
Execute the following:
46+
```
47+
pip install jsonsubschema
48+
```
49+
50+
## II) Running subschema ##
51+
52+
JSON subschema provides two usage interfaces:
53+
54+
### A) CLI interface ###
55+
1. Create two JSON schema examples by executing the following:
56+
```
57+
echo '{"type": ["null", "string"]}' > s1.json
58+
echo '{"type": ["string", "null"], "not": {"enum": [""]}}' > s2.json
59+
```
60+
61+
2. Invoke the CLI by executing:
62+
```
63+
python -m jsonsubschema.cli s2.json s1.json
64+
```
65+
66+
### B) python API ###
67+
```
68+
from jsonsubschema import isSubschema
69+
70+
def main():
71+
s1 = {'type': "integer"}
72+
s2 = {'type': ["integer", "string"]}
73+
74+
print(f'LHS <: RHS {isSubschema(s1, s2)}')
75+
76+
if __name__ == "__main__":
77+
main()
78+
```
979

1080

11-
This project is still in its early stage.
1281

1382
## License
1483

0 commit comments

Comments
 (0)