flask-restplus
flask-restplus copied to clipboard
Support dot notation in model field names
Issue #598
Implements a new dot_escape
kwarg to fields.Raw
to support '.' characters within a field name without using as a nesting separator.
Current behaviour:
>>> data = {"my.dot.field": 1234}
>>> model = {"my.dot.field: fields.Integer}
>>> marshal(data, model)
{"my.dot.field:": None}
New behaviour:
>>> data = {"my.dot.field": 1234}
>>> model = {"my\.dot\.field: fields.Integer(dot_escape=True)}
>>> marshal(data, model)
{"my.dot.field:": 1234}
>>> data = {"my.dot": {"field": 1234}}
>>> model = {"my\.dot.field: fields.Integer(dot_escape=True)}
>>> marshal(data, model)
{"my.dot.field:": 1234}
>>> data = {
'address.country': 'UK',
'address.postcode': 'CO1',
'user.name': {
'first': 'John',
'last': 'Smith',
}
}
>>> model = {
'address\.country': fields.String(dot_escape=True),
'address\.postcode': fields.String(dot_escape=True),
'user\.name.first': fields.String(dot_escape=True),
'user\.name.last': fields.String(dot_escape=True),
}
>>> marshal(data, model)
{'address.country': 'UK',
'address.postcode': 'CO1',
'user.name.first': 'John',
'user.name.last': 'Smith'}
Coverage increased (+0.005%) to 96.85% when pulling b30acdc1f89a14bfd82647031b04440c0e5d089f on SteadBytes:field-key-dot-escape into a8f35823fe40b2c7385632a2ad6b35b26467402c on noirbizarre:master.
Would be a nice feature!
Any plans when if and when this feature will be implemented/merged?