Skip to content

Commit 8dfb552

Browse files
committed
Can process not keyword
1 parent cc2d549 commit 8dfb552

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
- Added audit functionality. Thanks to Duncan and https://github.com/OpenDataServices/json-schema-auditor
1313
- Can process dependentSchemas keyword
1414
- Can process if / then / else keywords
15+
- Can process not keyword
1516

1617
### Removed
1718

compiletojsonschema/compiletojsonschema.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def __process_data(self, source):
122122
for k, v in source["dependentSchemas"].items():
123123
out["dependentSchemas"][k] = self.__process_data(v)
124124

125-
for keyword in ["if", "then", "else"]:
125+
for keyword in ["if", "then", "else", "not"]:
126126
if keyword in source:
127127
out[keyword] = self.__process_data(source[keyword])
128128

tests/fixtures/simple/file-not.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"name": {
5+
"type": "string"
6+
},
7+
"credit_card": {
8+
"type": "string"
9+
}
10+
},
11+
"oneOf": [
12+
{
13+
"not": {
14+
"properties": {
15+
"credit_card": {
16+
"pattern": "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"
17+
}
18+
}
19+
}
20+
},
21+
{
22+
"properties": {
23+
"address": {
24+
"$ref": "file-definitions.json#/definition/address",
25+
"title": "Must have an address with a credit card"
26+
}
27+
},
28+
"required": [
29+
"address"
30+
]
31+
}
32+
]
33+
}

tests/test_simple.py

+31
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,34 @@ def test_file_if_then_else():
221221
"title",
222222
"type",
223223
] == ctjs.get_keywords_used()
224+
225+
226+
def test_file_not():
227+
228+
input_filename = os.path.join(
229+
os.path.dirname(os.path.realpath(__file__)),
230+
"fixtures",
231+
"simple",
232+
"file-not.json",
233+
)
234+
235+
ctjs = CompileToJsonSchema(input_filename=input_filename)
236+
out = ctjs.get()
237+
238+
assert (
239+
out["oneOf"][1]["properties"]["address"]["title"]
240+
== "Must have an address with a credit card"
241+
)
242+
243+
assert ["object", "string"] == ctjs.get_types_used()
244+
assert [
245+
"$ref",
246+
"description",
247+
"not",
248+
"oneOf",
249+
"pattern",
250+
"properties",
251+
"required",
252+
"title",
253+
"type",
254+
] == ctjs.get_keywords_used()

0 commit comments

Comments
 (0)