openapi-python-generator 2.0.1.dev1758361866__py3-none-any.whl → 2.0.1.dev1758565728__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,8 +49,10 @@ def normalize_symbol(symbol: str) -> str:
49
49
  :param symbol: name of the identifier
50
50
  :return: normalized identifier name
51
51
  """
52
- symbol = symbol.replace("-", "_")
52
+ symbol = symbol.replace("-", "_").replace(" ", "_")
53
53
  normalized_symbol = _symbol_ascii_strip_re.sub("", symbol)
54
54
  if normalized_symbol in keyword.kwlist:
55
55
  normalized_symbol = normalized_symbol + "_"
56
+ if len(normalized_symbol) > 0 and normalized_symbol[0].isnumeric():
57
+ normalized_symbol = "_" + normalized_symbol
56
58
  return normalized_symbol
@@ -16,7 +16,7 @@ TEMPLATE_PATH = Path(__file__).parent / "templates"
16
16
 
17
17
  def create_jinja_env():
18
18
  custom_template_path = common.get_custom_template_path()
19
- return Environment(
19
+ environment = Environment(
20
20
  loader=(
21
21
  ChoiceLoader(
22
22
  [
@@ -30,3 +30,7 @@ def create_jinja_env():
30
30
  autoescape=True,
31
31
  trim_blocks=True,
32
32
  )
33
+
34
+ environment.filters["normalize_symbol"] = common.normalize_symbol
35
+
36
+ return environment
@@ -1,5 +1,4 @@
1
1
  import itertools
2
- import re
3
2
  from typing import List, Optional, Union
4
3
 
5
4
  import click
@@ -414,10 +413,8 @@ def generate_models(
414
413
  name = common.normalize_symbol(schema_name)
415
414
  if schema_or_reference.enum is not None:
416
415
  value_dict = schema_or_reference.model_dump()
417
- regex = re.compile(r"[\s\/=\*\+]+")
418
416
  value_dict["enum"] = [
419
- re.sub(regex, "_", i) if isinstance(i, str) else f"value_{i}"
420
- for i in value_dict["enum"]
417
+ (common.normalize_symbol(str(i)).upper(), i) for i in value_dict["enum"]
421
418
  ]
422
419
  m = Model(
423
420
  file_name=name,
@@ -1,9 +1,11 @@
1
1
  from enum import Enum
2
2
 
3
3
  class {{ name }}(str, Enum):
4
- {% for enumItem in enum %}
4
+ {% for enumItemIdent, enumItem in enum %}
5
5
 
6
6
  {% if enumItem is string %}
7
- {{ enumItem.upper() }} = '{{ enumItem }}'{% else %}
8
- value_{{ enumItem }} = {{ enumItem }}{% endif %}
7
+ {{ enumItemIdent }} = '{{ enumItem }}'
8
+ {% else %}
9
+ {{ enumItemIdent }} = {{ enumItem }}
10
+ {% endif %}
9
11
  {% endfor %}
@@ -20,5 +20,5 @@ class {{ schema_name }}(BaseModel):
20
20
  """
21
21
  {% for property in properties %}
22
22
 
23
- {{ property.name | replace("@","") | replace("-","_") }} : {{ property.type.converted_type | safe }} = Field(alias="{{ property.name }}" {% if not property.required %}, default = {{ property.default }} {% endif %})
23
+ {{ property.name | normalize_symbol }} : {{ property.type.converted_type | safe }} = Field(alias="{{ property.name }}" {% if not property.required %}, default = {{ property.default }} {% endif %})
24
24
  {% endfor %}
@@ -24,5 +24,5 @@ class {{ schema_name }}(BaseModel):
24
24
  }
25
25
  {% for property in properties %}
26
26
 
27
- {{ property.name | replace("@","") | replace("-","_") }} : {{ property.type.converted_type | safe }} = Field(validation_alias="{{ property.name }}" {% if not property.required %}, default = {{ property.default }} {% endif %})
28
- {% endfor %}
27
+ {{ property.name | normalize_symbol }} : {{ property.type.converted_type | safe }} = Field(validation_alias="{{ property.name }}" {% if not property.required %}, default = {{ property.default }} {% endif %})
28
+ {% endfor %}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openapi-python-generator
3
- Version: 2.0.1.dev1758361866
3
+ Version: 2.0.1.dev1758565728
4
4
  Summary: Openapi Python Generator
5
5
  Home-page: https://github.com/MarcoMuellner/openapi-python-generator
6
6
  License: MIT
@@ -5,18 +5,18 @@ openapi_python_generator/generate_data.py,sha256=Av7nXE6BvsE9eHWF6eOBhPCZWWC9pi-
5
5
  openapi_python_generator/language_converters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  openapi_python_generator/language_converters/python/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  openapi_python_generator/language_converters/python/api_config_generator.py,sha256=obbYMFguKp2Pp97YoPd2NKE4n7gBDupbDIyyuynIW6Q,1020
8
- openapi_python_generator/language_converters/python/common.py,sha256=DJkX9AKTLkrSm3NVNw4KMVObP0B9w4r63UXKI_pc61w,1474
8
+ openapi_python_generator/language_converters/python/common.py,sha256=gZHNhVC4OwGBlmr3h9Ffz3iILO1ykva9CrqhBfeYQXU,1616
9
9
  openapi_python_generator/language_converters/python/generator.py,sha256=BpgALeKsNgqSvQNQPoM8x1LYG9BmvA687eNdtvPO6UM,1681
10
- openapi_python_generator/language_converters/python/jinja_config.py,sha256=cdEFrFTSLu2D0tKg3ZN1kQPsFkFIrb9QAo8susH3Vz8,940
11
- openapi_python_generator/language_converters/python/model_generator.py,sha256=BHNqkcqvcu8GoyG9vWC61NYmPQH86fr10CTxCKsI2lU,19519
10
+ openapi_python_generator/language_converters/python/jinja_config.py,sha256=FuNhGkJqBNaal_jkkirZqgzZOkiMImi-863mnG55n08,1042
11
+ openapi_python_generator/language_converters/python/model_generator.py,sha256=8PURrVr7h5OvCYjxCHNPc4qFh1vGE1uEVRK6DGsDPrY,19428
12
12
  openapi_python_generator/language_converters/python/service_generator.py,sha256=38pyA53vOjd173WwCF5Bp3OhCkmOSKaBjCC2WhGiG4A,18547
13
13
  openapi_python_generator/language_converters/python/templates/aiohttp.jinja2,sha256=Ym3-KX8JH9-V75GqkfcXVgh7rnqlkOQU5DLaNd1Wma0,2135
14
14
  openapi_python_generator/language_converters/python/templates/apiconfig.jinja2,sha256=bvYMJV6YB2NZLLcqwozISdS86XLH8J6D8o3ZpfgJCjc,1256
15
15
  openapi_python_generator/language_converters/python/templates/apiconfig_pydantic_2.jinja2,sha256=_MzcHYEq9aoqSUEhZ-5SLbO80zgBeJnx5d7q3Q_usSo,1319
16
- openapi_python_generator/language_converters/python/templates/enum.jinja2,sha256=9R9Nv1g8GykflCWm9HgxCmSWvIJ9FTNkXlXOZSBaZvw,242
16
+ openapi_python_generator/language_converters/python/templates/enum.jinja2,sha256=7dewyMLifUTe9xjCTE62deuncPiNkp7eGkIaY-IWsLo,263
17
17
  openapi_python_generator/language_converters/python/templates/httpx.jinja2,sha256=mg4QjPOAJwQY9BSxOsY1MRkvnaeU8_nbxTRCSGGU0Bk,2300
18
- openapi_python_generator/language_converters/python/templates/models.jinja2,sha256=5nKSOjbqGkK91wTR6AaSFQMDW0P4hR6fV-7oaVCPfwc,810
19
- openapi_python_generator/language_converters/python/templates/models_pydantic_2.jinja2,sha256=-cX_OvwItvrDVk9dssgZ2BowMFMNu3YfKEcA9XU0_bM,916
18
+ openapi_python_generator/language_converters/python/templates/models.jinja2,sha256=Azr7dIvdq0p1DAd5Xm1Q-gJ-irWX9jMi-X7Ru44rISg,792
19
+ openapi_python_generator/language_converters/python/templates/models_pydantic_2.jinja2,sha256=81biZZAwsgFT3v0bYiQYr5n4XFII3myZ7WC6vS_f_pw,899
20
20
  openapi_python_generator/language_converters/python/templates/requests.jinja2,sha256=8R3S5M26vQol-rXHuNVYuG4qc_skC9-G8x-6AZlqTXg,2043
21
21
  openapi_python_generator/language_converters/python/templates/service.jinja2,sha256=tt0Iu_JLaAlMPU73KTM7yntQjnkdvve53ShjgAGcmqY,213
22
22
  openapi_python_generator/models.py,sha256=uWkWofLHT9ELVoYcmLIfvBUeIo723V-EJ5_YWWateI4,2174
@@ -25,8 +25,8 @@ openapi_python_generator/parsers/openapi_30.py,sha256=YLA5_rIv_wkV2dyQp7M1_87170
25
25
  openapi_python_generator/parsers/openapi_31.py,sha256=c3YpAp6wg6PijM1YScHJgivFk6DLhAP_N6pnTLyRUck,1912
26
26
  openapi_python_generator/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  openapi_python_generator/version_detector.py,sha256=Cn7iG6_EnBdmjGmefJQ1cIBzbT28F0BeCEpoqksBGyQ,2142
28
- openapi_python_generator-2.0.1.dev1758361866.dist-info/METADATA,sha256=o_-8h8Cz5R33y51fWLZ2DX_UEA1azAPdPhdPPkYN1Ms,5441
29
- openapi_python_generator-2.0.1.dev1758361866.dist-info/LICENSE,sha256=0myanGwJ2vUOZN12aN95o0My6XEysnnVlbKikYw3pHg,1070
30
- openapi_python_generator-2.0.1.dev1758361866.dist-info/entry_points.txt,sha256=hqE8T8yX5Pkeb2g__7yQrEazkBPwNgTbEHmoOkaYh80,83
31
- openapi_python_generator-2.0.1.dev1758361866.dist-info/WHEEL,sha256=vVCvjcmxuUltf8cYhJ0sJMRDLr1XsPuxEId8YDzbyCY,88
32
- openapi_python_generator-2.0.1.dev1758361866.dist-info/RECORD,,
28
+ openapi_python_generator-2.0.1.dev1758565728.dist-info/METADATA,sha256=ZgoPtKLtcDR0G7Y0PkJZTg7pMjSiZjrpzI3QHDtuQT8,5441
29
+ openapi_python_generator-2.0.1.dev1758565728.dist-info/LICENSE,sha256=0myanGwJ2vUOZN12aN95o0My6XEysnnVlbKikYw3pHg,1070
30
+ openapi_python_generator-2.0.1.dev1758565728.dist-info/entry_points.txt,sha256=hqE8T8yX5Pkeb2g__7yQrEazkBPwNgTbEHmoOkaYh80,83
31
+ openapi_python_generator-2.0.1.dev1758565728.dist-info/WHEEL,sha256=vVCvjcmxuUltf8cYhJ0sJMRDLr1XsPuxEId8YDzbyCY,88
32
+ openapi_python_generator-2.0.1.dev1758565728.dist-info/RECORD,,