flask-restplus icon indicating copy to clipboard operation
flask-restplus copied to clipboard

Support dot notation in model field names

Open SteadBytes opened this issue 5 years ago • 3 comments

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'}

SteadBytes avatar Mar 08 '19 07:03 SteadBytes

Coverage Status

Coverage increased (+0.005%) to 96.85% when pulling b30acdc1f89a14bfd82647031b04440c0e5d089f on SteadBytes:field-key-dot-escape into a8f35823fe40b2c7385632a2ad6b35b26467402c on noirbizarre:master.

coveralls avatar Mar 08 '19 08:03 coveralls

Would be a nice feature!

dstrigl avatar Mar 26 '19 14:03 dstrigl

Any plans when if and when this feature will be implemented/merged?

dstrigl avatar Jan 09 '20 12:01 dstrigl