Skip to content

Commit

Permalink
Fix a bug for # field (#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
koxudaxi authored Sep 30, 2021
1 parent 2329203 commit c015850
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion datamodel_code_generator/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def get_valid_name(
if not name:
name = self.empty_field_name
if name[0] == '#':
name = name[1:]
name = name[1:] or self.empty_field_name
# TODO: when first character is a number
name = re.sub(r'\W', '_', name)
if name[0].isnumeric():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ class SpecialField(BaseModel):
class_: Optional[int] = Field(None, alias='class')
class_s: Optional[int] = Field(None, alias="class's")
class_s_1: Optional[str] = Field(None, alias='class-s')
_: Optional[str] = Field(None, alias='#')
3 changes: 3 additions & 0 deletions tests/data/jsonschema/special_field_name.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
},
"class-s": {
"type": "string"
},
"#": {
"type": "string"
}
}
}

0 comments on commit c015850

Please sign in to comment.