Skip to content

Commit

Permalink
take items into account in stack
Browse files Browse the repository at this point in the history
  • Loading branch information
christophevg committed Mar 5, 2021
1 parent a045fbb commit 935fd3a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion schema_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.15"
__version__ = "0.0.16"
2 changes: 1 addition & 1 deletion schema_tools/schema/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def to_dict(self, deref=False, prefix=None, stack=None):
if stack is None: stack = []
out = super().to_dict(deref=deref, prefix=prefix, stack=stack)
if isinstance(self.items, Schema):
out["items"] = self.items.to_dict(deref=deref, prefix=prefix, stack=stack)
out["items"] = self.items.to_dict(deref=deref, prefix=prefix, stack=stack+["items"])
else:
out["items"] = self.items
return out
Expand Down
3 changes: 3 additions & 0 deletions tests/schemas/product.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
},
"cost": {
"$ref" : "file:tests/schemas/money.json"
},
"subproduct" : {
"$ref" : "#"
}
}
}
4 changes: 2 additions & 2 deletions tests/test_deref_to_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ def test_deref_to_dict(asset):
items = d["properties"]["lines"]["items"]
assert items["properties"]["type"]["$ref"] == "#/definitions/type"
assert items["properties"]["price"]["properties"]["taxed"]["$ref"] == \
"#/properties/lines/properties/price/definitions/taxed"
"#/properties/lines/items/properties/price/definitions/taxed"


# simple included type and 2nd-level dereferenced definition
product = items["properties"]["product"]
assert product["properties"]["id"]["type"] == "string"
assert product["properties"]["cost"]["properties"]["taxed"]["$ref"] == \
"#/properties/lines/properties/product/properties/cost/definitions/taxed"
"#/properties/lines/items/properties/product/properties/cost/definitions/taxed"

def test_ensure_derereferenced_schemas_drop_local_ids(asset):
original_file = asset("invoice.json")
Expand Down

0 comments on commit 935fd3a

Please sign in to comment.