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

Added support for Marker descriptions #1

Merged
merged 1 commit into from
Mar 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added support for Marker descriptions
svisser committed Mar 10, 2018
commit 4ed9c27ecdf5cd7dfd733e41ec353049f01c1d14
11 changes: 11 additions & 0 deletions tests/test_lib.py
Original file line number Diff line number Diff line change
@@ -82,3 +82,14 @@ def test_dict():
vol.Required('age'): vol.All(vol.Coerce(int), vol.Range(min=18)),
vol.Optional('hobby', default='not specified'): str
}))


def test_marker_description():
assert [{
'name': 'name',
'type': 'string',
'description': 'Description of name',
'required': True,
}] == convert(vol.Schema({
vol.Required('name', description='Description of name'): str,
}))
4 changes: 4 additions & 0 deletions voluptuous_serialize/__init__.py
Original file line number Diff line number Diff line change
@@ -21,13 +21,17 @@ def convert(schema):
val = []

for key, value in schema.items():
description = None
if isinstance(key, vol.Marker):
pkey = key.schema
description = key.description
else:
pkey = key

pval = convert(value)
pval['name'] = pkey
if description is not None:
pval['description'] = description

if isinstance(key, (vol.Required, vol.Optional)):
pval[key.__class__.__name__.lower()] = True