Skip to content

Commit 32dbd11

Browse files
committed
Can process dependentSchemas keyword
1 parent 21e2d90 commit 32dbd11

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010

1111
- Cache results of processing. Repeated calls to get methods will be faster.
1212
- Added audit functionality. Thanks to Duncan and https://github.com/OpenDataServices/json-schema-auditor
13+
- Can process dependentSchemas keyword
1314

1415
### Removed
1516

compiletojsonschema/compiletojsonschema.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ def __process_data(self, source):
116116
for idx, data in enumerate(list(source["allOf"])):
117117
out["allOf"][idx] = self.__process_data(source["allOf"][idx])
118118

119+
if "dependentSchemas" in source and isinstance(
120+
source["dependentSchemas"], dict
121+
):
122+
for k, v in source["dependentSchemas"].items():
123+
out["dependentSchemas"][k] = self.__process_data(v)
124+
119125
if "codelist" in source and (
120126
"openCodelist" not in source or not source["openCodelist"]
121127
):
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"credit_card": {
5+
"type": "number"
6+
}
7+
},
8+
"dependentSchemas": {
9+
"credit_card": {
10+
"$ref": "file-definitions.json#/definition/address",
11+
"title": "Credit card number (with optional address elements)"
12+
}
13+
}
14+
}

tests/test_simple.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,31 @@ def test_file_list_allof():
160160
def test_passing_empty_schema_is_ok():
161161
ctjs = CompileToJsonSchema(input_schema={})
162162
assert "{}" == ctjs.get_as_string()
163+
164+
165+
def test_file_dependentSchemas():
166+
167+
input_filename = os.path.join(
168+
os.path.dirname(os.path.realpath(__file__)),
169+
"fixtures",
170+
"simple",
171+
"file-dependentSchemas.json",
172+
)
173+
174+
ctjs = CompileToJsonSchema(input_filename=input_filename)
175+
out = ctjs.get()
176+
177+
assert (
178+
out["dependentSchemas"]["credit_card"]["title"]
179+
== "Credit card number (with optional address elements)"
180+
)
181+
182+
assert ["number", "object", "string"] == ctjs.get_types_used()
183+
assert [
184+
"$ref",
185+
"dependentSchemas",
186+
"description",
187+
"properties",
188+
"title",
189+
"type",
190+
] == ctjs.get_keywords_used()

0 commit comments

Comments
 (0)