Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for reading in a schema that contains $ref #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion singer/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'additionalProperties',
'anyOf',
'patternProperties',
'definitions',
]


Expand All @@ -36,7 +37,7 @@ def __init__(self, type=None, format=None, properties=None, items=None,
selected=None, inclusion=None, description=None, minimum=None,
maximum=None, exclusiveMinimum=None, exclusiveMaximum=None,
multipleOf=None, maxLength=None, minLength=None, additionalProperties=None,
anyOf=None, patternProperties=None):
anyOf=None, patternProperties=None, definitions=None, ref=None):

self.type = type
self.properties = properties
Expand All @@ -55,6 +56,8 @@ def __init__(self, type=None, format=None, properties=None, items=None,
self.format = format
self.additionalProperties = additionalProperties
self.patternProperties = patternProperties
self.definitions = definitions
self.ref = ref

def __str__(self):
return json.dumps(self.to_dict())
Expand All @@ -71,6 +74,9 @@ def to_dict(self):
'''Return the raw JSON Schema as a (possibly nested) dict.'''
result = {}

if self.ref is not None:
result['$ref'] = self.ref

if self.properties is not None:
result['properties'] = {
k: v.to_dict()
Expand All @@ -97,6 +103,10 @@ def from_dict(cls, data, **schema_defaults):
kwargs = schema_defaults.copy()
properties = data.get('properties')
items = data.get('items')
ref = data.get('$ref')

if ref is not None:
kwargs['ref'] = ref

if properties is not None:
kwargs['properties'] = {
Expand All @@ -105,6 +115,7 @@ def from_dict(cls, data, **schema_defaults):
}
if items is not None:
kwargs['items'] = Schema.from_dict(items, **schema_defaults)

for key in STANDARD_KEYS:
if key in data:
kwargs[key] = data[key]
Expand Down