Skip to content

Commit 6e4b76b

Browse files
Generate certificates
1 parent 875e273 commit 6e4b76b

10 files changed

Lines changed: 72 additions & 42 deletions

File tree

services/certificates/oas_commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
87a3ad63dec0a953ff5c6072ad9a15fddd8ec5f8
1+
0867dbbb09a8032415dc6debe18bc392bd58ba42

services/certificates/src/stackit/certificates/api_client.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class ApiClient:
6666
"date": datetime.date,
6767
"datetime": datetime.datetime,
6868
"decimal": decimal.Decimal,
69+
"UUID": uuid.UUID,
6970
"object": object,
7071
}
7172
_pool = None
@@ -265,7 +266,7 @@ def response_deserialize(
265266
response_text = None
266267
return_data = None
267268
try:
268-
if response_type == "bytearray":
269+
if response_type in ("bytearray", "bytes"):
269270
return_data = response_data.data
270271
elif response_type == "file":
271272
return_data = self.__deserialize_file(response_data)
@@ -326,25 +327,20 @@ def sanitize_for_serialization(self, obj):
326327
return obj.isoformat()
327328
elif isinstance(obj, decimal.Decimal):
328329
return str(obj)
329-
330330
elif isinstance(obj, dict):
331-
obj_dict = obj
331+
return {key: self.sanitize_for_serialization(val) for key, val in obj.items()}
332+
333+
# Convert model obj to dict except
334+
# attributes `openapi_types`, `attribute_map`
335+
# and attributes which value is not None.
336+
# Convert attribute name to json key in
337+
# model definition for request.
338+
if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")):
339+
obj_dict = obj.to_dict()
332340
else:
333-
# Convert model obj to dict except
334-
# attributes `openapi_types`, `attribute_map`
335-
# and attributes which value is not None.
336-
# Convert attribute name to json key in
337-
# model definition for request.
338-
if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")): # noqa: B009
339-
obj_dict = obj.to_dict()
340-
else:
341-
obj_dict = obj.__dict__
342-
343-
if isinstance(obj_dict, list):
344-
# here we handle instances that can either be a list or something else, and only became a real list by calling to_dict() # noqa: E501
345-
return self.sanitize_for_serialization(obj_dict)
341+
obj_dict = obj.__dict__
346342

347-
return {key: self.sanitize_for_serialization(val) for key, val in obj_dict.items()}
343+
return self.sanitize_for_serialization(obj_dict)
348344

349345
def deserialize(self, response_text: str, response_type: str, content_type: Optional[str]):
350346
"""Deserializes response into an object.
@@ -417,6 +413,8 @@ def __deserialize(self, data, klass):
417413
return self.__deserialize_datetime(data)
418414
elif klass is decimal.Decimal:
419415
return decimal.Decimal(data)
416+
elif klass is uuid.UUID:
417+
return uuid.UUID(data)
420418
elif issubclass(klass, Enum):
421419
return self.__deserialize_enum(data, klass)
422420
else:

services/certificates/src/stackit/certificates/models/certificates_quota.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from typing import Any, ClassVar, Dict, List, Optional, Set
1919

2020
from pydantic import BaseModel, ConfigDict, Field
21+
from pydantic_core import to_jsonable_python
2122
from typing_extensions import Annotated, Self
2223

2324

@@ -35,7 +36,8 @@ class CertificatesQuota(BaseModel):
3536
__properties: ClassVar[List[str]] = ["limit", "usage"]
3637

3738
model_config = ConfigDict(
38-
populate_by_name=True,
39+
validate_by_name=True,
40+
validate_by_alias=True,
3941
validate_assignment=True,
4042
protected_namespaces=(),
4143
)
@@ -46,8 +48,7 @@ def to_str(self) -> str:
4648

4749
def to_json(self) -> str:
4850
"""Returns the JSON representation of the model using alias"""
49-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
50-
return json.dumps(self.to_dict())
51+
return json.dumps(to_jsonable_python(self.to_dict()))
5152

5253
@classmethod
5354
def from_json(cls, json_str: str) -> Optional[Self]:

services/certificates/src/stackit/certificates/models/create_certificate_payload.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from uuid import UUID
2121

2222
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
23+
from pydantic_core import to_jsonable_python
2324
from typing_extensions import Annotated, Self
2425

2526

@@ -45,6 +46,9 @@ def name_validate_regular_expression(cls, value):
4546
if value is None:
4647
return value
4748

49+
if not isinstance(value, str):
50+
value = str(value)
51+
4852
if not re.match(r"^[0-9a-z](?:(?:[0-9a-z]|-){0,61}[0-9a-z])?$", value):
4953
raise ValueError(r"must validate the regular expression /^[0-9a-z](?:(?:[0-9a-z]|-){0,61}[0-9a-z])?$/")
5054
return value
@@ -55,6 +59,9 @@ def project_id_validate_regular_expression(cls, value):
5559
if value is None:
5660
return value
5761

62+
if not isinstance(value, str):
63+
value = str(value)
64+
5865
if not re.match(r"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", value):
5966
raise ValueError(
6067
r"must validate the regular expression /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/"
@@ -67,12 +74,16 @@ def region_validate_regular_expression(cls, value):
6774
if value is None:
6875
return value
6976

77+
if not isinstance(value, str):
78+
value = str(value)
79+
7080
if not re.match(r"^[a-z]{2,4}[0-9]{2}$", value):
7181
raise ValueError(r"must validate the regular expression /^[a-z]{2,4}[0-9]{2}$/")
7282
return value
7383

7484
model_config = ConfigDict(
75-
populate_by_name=True,
85+
validate_by_name=True,
86+
validate_by_alias=True,
7687
validate_assignment=True,
7788
protected_namespaces=(),
7889
)
@@ -83,8 +94,7 @@ def to_str(self) -> str:
8394

8495
def to_json(self) -> str:
8596
"""Returns the JSON representation of the model using alias"""
86-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
87-
return json.dumps(self.to_dict())
97+
return json.dumps(to_jsonable_python(self.to_dict()))
8898

8999
@classmethod
90100
def from_json(cls, json_str: str) -> Optional[Self]:

services/certificates/src/stackit/certificates/models/get_certificate_response.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Any, ClassVar, Dict, List, Optional, Set
2020

2121
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Annotated, Self
2324

2425

@@ -41,6 +42,9 @@ def id_validate_regular_expression(cls, value):
4142
if value is None:
4243
return value
4344

45+
if not isinstance(value, str):
46+
value = str(value)
47+
4448
if not re.match(r"^[0-9a-z](?:(?:[0-9a-z]|-){0,251}[0-9a-z])?$", value):
4549
raise ValueError(r"must validate the regular expression /^[0-9a-z](?:(?:[0-9a-z]|-){0,251}[0-9a-z])?$/")
4650
return value
@@ -51,12 +55,16 @@ def name_validate_regular_expression(cls, value):
5155
if value is None:
5256
return value
5357

58+
if not isinstance(value, str):
59+
value = str(value)
60+
5461
if not re.match(r"^[0-9a-z](?:(?:[0-9a-z]|-){0,251}[0-9a-z])?$", value):
5562
raise ValueError(r"must validate the regular expression /^[0-9a-z](?:(?:[0-9a-z]|-){0,251}[0-9a-z])?$/")
5663
return value
5764

5865
model_config = ConfigDict(
59-
populate_by_name=True,
66+
validate_by_name=True,
67+
validate_by_alias=True,
6068
validate_assignment=True,
6169
protected_namespaces=(),
6270
)
@@ -67,8 +75,7 @@ def to_str(self) -> str:
6775

6876
def to_json(self) -> str:
6977
"""Returns the JSON representation of the model using alias"""
70-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
71-
return json.dumps(self.to_dict())
78+
return json.dumps(to_jsonable_python(self.to_dict()))
7279

7380
@classmethod
7481
def from_json(cls, json_str: str) -> Optional[Self]:

services/certificates/src/stackit/certificates/models/get_quota_response.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from uuid import UUID
2121

2222
from pydantic import BaseModel, ConfigDict, Field, field_validator
23+
from pydantic_core import to_jsonable_python
2324
from typing_extensions import Annotated, Self
2425

2526
from stackit.certificates.models.quotas import Quotas
@@ -41,6 +42,9 @@ def project_id_validate_regular_expression(cls, value):
4142
if value is None:
4243
return value
4344

45+
if not isinstance(value, str):
46+
value = str(value)
47+
4448
if not re.match(r"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", value):
4549
raise ValueError(
4650
r"must validate the regular expression /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/"
@@ -53,12 +57,16 @@ def region_validate_regular_expression(cls, value):
5357
if value is None:
5458
return value
5559

60+
if not isinstance(value, str):
61+
value = str(value)
62+
5663
if not re.match(r"^[a-z]{2,4}[0-9]{2}$", value):
5764
raise ValueError(r"must validate the regular expression /^[a-z]{2,4}[0-9]{2}$/")
5865
return value
5966

6067
model_config = ConfigDict(
61-
populate_by_name=True,
68+
validate_by_name=True,
69+
validate_by_alias=True,
6270
validate_assignment=True,
6371
protected_namespaces=(),
6472
)
@@ -69,8 +77,7 @@ def to_str(self) -> str:
6977

7078
def to_json(self) -> str:
7179
"""Returns the JSON representation of the model using alias"""
72-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
73-
return json.dumps(self.to_dict())
80+
return json.dumps(to_jsonable_python(self.to_dict()))
7481

7582
@classmethod
7683
def from_json(cls, json_str: str) -> Optional[Self]:

services/certificates/src/stackit/certificates/models/google_protobuf_any.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from typing import Any, ClassVar, Dict, List, Optional, Set
1919

2020
from pydantic import BaseModel, ConfigDict, Field, StrictStr
21+
from pydantic_core import to_jsonable_python
2122
from typing_extensions import Self
2223

2324

@@ -31,7 +32,8 @@ class GoogleProtobufAny(BaseModel):
3132
__properties: ClassVar[List[str]] = ["@type"]
3233

3334
model_config = ConfigDict(
34-
populate_by_name=True,
35+
validate_by_name=True,
36+
validate_by_alias=True,
3537
validate_assignment=True,
3638
protected_namespaces=(),
3739
)
@@ -42,8 +44,7 @@ def to_str(self) -> str:
4244

4345
def to_json(self) -> str:
4446
"""Returns the JSON representation of the model using alias"""
45-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
46-
return json.dumps(self.to_dict())
47+
return json.dumps(to_jsonable_python(self.to_dict()))
4748

4849
@classmethod
4950
def from_json(cls, json_str: str) -> Optional[Self]:

services/certificates/src/stackit/certificates/models/list_certificates_response.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Any, ClassVar, Dict, List, Optional, Set
2020

2121
from pydantic import BaseModel, ConfigDict, Field, field_validator
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Annotated, Self
2324

2425
from stackit.certificates.models.get_certificate_response import GetCertificateResponse
@@ -43,12 +44,16 @@ def next_page_id_validate_regular_expression(cls, value):
4344
if value is None:
4445
return value
4546

47+
if not isinstance(value, str):
48+
value = str(value)
49+
4650
if not re.match(r"^[0-9a-z](?:(?:[0-9a-z]|-){0,61}[0-9a-z])?$", value):
4751
raise ValueError(r"must validate the regular expression /^[0-9a-z](?:(?:[0-9a-z]|-){0,61}[0-9a-z])?$/")
4852
return value
4953

5054
model_config = ConfigDict(
51-
populate_by_name=True,
55+
validate_by_name=True,
56+
validate_by_alias=True,
5257
validate_assignment=True,
5358
protected_namespaces=(),
5459
)
@@ -59,8 +64,7 @@ def to_str(self) -> str:
5964

6065
def to_json(self) -> str:
6166
"""Returns the JSON representation of the model using alias"""
62-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
63-
return json.dumps(self.to_dict())
67+
return json.dumps(to_jsonable_python(self.to_dict()))
6468

6569
@classmethod
6670
def from_json(cls, json_str: str) -> Optional[Self]:

services/certificates/src/stackit/certificates/models/quotas.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from typing import Any, ClassVar, Dict, List, Optional, Set
1919

2020
from pydantic import BaseModel, ConfigDict
21+
from pydantic_core import to_jsonable_python
2122
from typing_extensions import Self
2223

2324
from stackit.certificates.models.certificates_quota import CertificatesQuota
@@ -32,7 +33,8 @@ class Quotas(BaseModel):
3233
__properties: ClassVar[List[str]] = ["certificates"]
3334

3435
model_config = ConfigDict(
35-
populate_by_name=True,
36+
validate_by_name=True,
37+
validate_by_alias=True,
3638
validate_assignment=True,
3739
protected_namespaces=(),
3840
)
@@ -43,8 +45,7 @@ def to_str(self) -> str:
4345

4446
def to_json(self) -> str:
4547
"""Returns the JSON representation of the model using alias"""
46-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
47-
return json.dumps(self.to_dict())
48+
return json.dumps(to_jsonable_python(self.to_dict()))
4849

4950
@classmethod
5051
def from_json(cls, json_str: str) -> Optional[Self]:

services/certificates/src/stackit/certificates/models/status.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from typing import Any, ClassVar, Dict, List, Optional, Set
1919

2020
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
21+
from pydantic_core import to_jsonable_python
2122
from typing_extensions import Self
2223

2324
from stackit.certificates.models.google_protobuf_any import GoogleProtobufAny
@@ -43,7 +44,8 @@ class Status(BaseModel):
4344
__properties: ClassVar[List[str]] = ["code", "details", "message"]
4445

4546
model_config = ConfigDict(
46-
populate_by_name=True,
47+
validate_by_name=True,
48+
validate_by_alias=True,
4749
validate_assignment=True,
4850
protected_namespaces=(),
4951
)
@@ -54,8 +56,7 @@ def to_str(self) -> str:
5456

5557
def to_json(self) -> str:
5658
"""Returns the JSON representation of the model using alias"""
57-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
58-
return json.dumps(self.to_dict())
59+
return json.dumps(to_jsonable_python(self.to_dict()))
5960

6061
@classmethod
6162
def from_json(cls, json_str: str) -> Optional[Self]:

0 commit comments

Comments
 (0)