djangorestframework-camel-case
djangorestframework-camel-case copied to clipboard
Setting to preserve _leadingUnderscores
Hi folks, in my API I have some keys with _leading_underscores
, for example:
{
'_str': 'String',
'_timestamp': 1234567890,
'firstValue': '...',
'secondValue: '...'
}
I want to preserve these leading _
's, but camelize the other fields.
I am thinking about a PR that adds a setting PRESERVE_LEADING_UNDERSCORE
, which would allow camelize_re
in utils.py
to be [a-z0-9]_[a-z0-9]
instead of [a-z0-9]?_[a-z0-9]
- note the changed '?'.
This would probably involve changing camelize_re
from being a constant to being generated by a utils.py
function, perhaps get_camelize_re()
.
Thoughts?
I would like to add my vote +1
to this idea.
Until this is not added, a workaround is to override camelize_re
regex. Adding the following code to the settings file works
import re
from djangorestframework_camel_case import util
util.camelize_re = re.compile(r"[a-z0-9]_[a-z0-9]")