Skip to content

Commit

Permalink
Merge pull request #1163 from sbrunner/backport/1161-to-master
Browse files Browse the repository at this point in the history
[Backport master] Fix name when a definition used tow times
  • Loading branch information
sbrunner authored Sep 27, 2024
2 parents fdd9790 + e610b43 commit 58d7b7e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 1 addition & 2 deletions jsonschema_gentypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,6 @@ def get_name(
name = normalize(name)

prefix = "" if has_title else "_"
rand = str(random.randint(0, 9999)) if name != "Root" else "" # nosec
if upper:
# Upper case
name = name.upper()
Expand All @@ -732,7 +731,7 @@ def get_name(
if not get_name.__dict__.get("names"):
get_name.__dict__["names"] = set()
elif output in get_name.__dict__["names"]:
output += rand
output += str(random.randint(0, 9999)) # nosec
get_name.__dict__["names"].add(output)
return output

Expand Down
2 changes: 2 additions & 0 deletions jsonschema_gentypes/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def process_config(config: configuration.Configuration, files: list[str]) -> Non
python_version = sys.version_info[:3]

for gen in config["generate"]:
if jsonschema_gentypes.get_name.__dict__.get("names"):
del jsonschema_gentypes.get_name.__dict__["names"]
source = gen["source"]
if files and source not in files:
continue
Expand Down

0 comments on commit 58d7b7e

Please sign in to comment.