diff --git a/.changeset/normalize_special_characters.md b/.changeset/normalize_special_characters.md new file mode 100644 index 000000000..3ed01da0c --- /dev/null +++ b/.changeset/normalize_special_characters.md @@ -0,0 +1,9 @@ +--- +default: patch +--- + +# Normalize Special Characters + +#1285 by @MatteoGisondi + +Fixes #1284 diff --git a/openapi_python_client/utils.py b/openapi_python_client/utils.py index 15e8c9eec..32b1ca375 100644 --- a/openapi_python_client/utils.py +++ b/openapi_python_client/utils.py @@ -6,6 +6,8 @@ from keyword import iskeyword from typing import Any +from unidecode import unidecode + from .config import Config DELIMITERS = r"\. _-" @@ -44,8 +46,8 @@ def __deepcopy__(self, _: Any) -> ClassName: def sanitize(value: str) -> str: - """Removes every character that isn't 0-9, A-Z, a-z, or a known delimiter""" - return re.sub(rf"[^\w{DELIMITERS}]+", "", value) + """Removes every character that isn't 0-9, A-Z, a-z, or a known delimiter and normalizes it to convert special characters""" + return unidecode(re.sub(rf"[^\w{DELIMITERS}]+", "", value)) def split_words(value: str) -> list[str]: diff --git a/pdm.lock b/pdm.lock index 8e38ab3ea..3f4716d27 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev"] strategy = ["inherit_metadata"] lock_version = "4.5.0" -content_hash = "sha256:aadc8a7c11176fc4fef967f0e34f059a3555abcd6626bd0a0b13b898db522860" +content_hash = "sha256:5fddcaa7019da1947400e02aa57616546ecdee371680ccb7a791f1e2fdf2c368" [[metadata.targets]] requires_python = "~=3.9" @@ -1016,3 +1016,14 @@ files = [ {file = "typing_inspection-0.4.1-py3-none-any.whl", hash = "sha256:389055682238f53b04f7badcb49b989835495a96700ced5dab2d8feae4b26f51"}, {file = "typing_inspection-0.4.1.tar.gz", hash = "sha256:6ae134cc0203c33377d43188d4064e9b357dba58cff3185f22924610e70a9d28"}, ] + +[[package]] +name = "unidecode" +version = "1.4.0" +requires_python = ">=3.7" +summary = "ASCII transliterations of Unicode text" +groups = ["default"] +files = [ + {file = "Unidecode-1.4.0-py3-none-any.whl", hash = "sha256:c3c7606c27503ad8d501270406e345ddb480a7b5f38827eafe4fa82a137f0021"}, + {file = "Unidecode-1.4.0.tar.gz", hash = "sha256:ce35985008338b676573023acc382d62c264f307c8f7963733405add37ea2b23"}, +] diff --git a/pyproject.toml b/pyproject.toml index 4f0774df7..faf659a20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ dependencies = [ "ruamel.yaml>=0.18.6,<0.19.0", "ruff>=0.2,<0.13", "typing-extensions>=4.8.0,<5.0.0", + "unidecode>=1.4.0", ] name = "openapi-python-client" version = "0.25.2"