Skip to content

Commit

Permalink
Fixed problems, if a name starts with a underscore (#120)
Browse files Browse the repository at this point in the history
Co-authored-by: Julian David Rath <[email protected]>
  • Loading branch information
julian-r and julian-r authored Apr 22, 2020
1 parent 6055368 commit 7604341
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion datamodel_code_generator/parser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ def get_singular_name(name: str) -> str:


def snake_to_upper_camel(word: str) -> str:
return ''.join(x[0].upper() + x[1:] for x in word.split('_'))
prefix = ''
if word.startswith('_'):
prefix = '_'
word = word[1:]

return prefix + ''.join(x[0].upper() + x[1:] for x in word.split('_'))


def dump_templates(templates: Union[DataModel, List[DataModel]]) -> str:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from datamodel_code_generator.parser.base import snake_to_upper_camel


def test_snake_to_upper_camel_underscore():
"""In case a name starts with a underline, we should keep it."""
assert snake_to_upper_camel('_hello') == '_Hello'

0 comments on commit 7604341

Please sign in to comment.