Skip to content

Commit 386a238

Browse files
Generate authorization
1 parent 875e273 commit 386a238

25 files changed

Lines changed: 189 additions & 87 deletions

services/authorization/oas_commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0e64886dd0847341800d7191ed193b75413be998
1+
98c11e0ee4834ddaaa474eccc437d234e6276a70

services/authorization/src/stackit/authorization/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/authorization/src/stackit/authorization/models/add_custom_role_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, field_validator
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Annotated, Self
2324

2425
from stackit.authorization.models.role import Role
@@ -37,19 +38,26 @@ class AddCustomRoleResponse(BaseModel):
3738
@field_validator("resource_id")
3839
def resource_id_validate_regular_expression(cls, value):
3940
"""Validates the regular expression"""
41+
if not isinstance(value, str):
42+
value = str(value)
43+
4044
if not re.match(r"^([a-zA-Z0-9\/_|\-=+@.]{1,})$", value):
4145
raise ValueError(r"must validate the regular expression /^([a-zA-Z0-9\/_|\-=+@.]{1,})$/")
4246
return value
4347

4448
@field_validator("resource_type")
4549
def resource_type_validate_regular_expression(cls, value):
4650
"""Validates the regular expression"""
51+
if not isinstance(value, str):
52+
value = str(value)
53+
4754
if not re.match(r"^[a-z](?:-?[a-z]){1,63}$", value):
4855
raise ValueError(r"must validate the regular expression /^[a-z](?:-?[a-z]){1,63}$/")
4956
return value
5057

5158
model_config = ConfigDict(
52-
populate_by_name=True,
59+
validate_by_name=True,
60+
validate_by_alias=True,
5361
validate_assignment=True,
5462
protected_namespaces=(),
5563
)
@@ -60,8 +68,7 @@ def to_str(self) -> str:
6068

6169
def to_json(self) -> str:
6270
"""Returns the JSON representation of the model using alias"""
63-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
64-
return json.dumps(self.to_dict())
71+
return json.dumps(to_jsonable_python(self.to_dict()))
6572

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

services/authorization/src/stackit/authorization/models/add_members_payload.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.authorization.models.member import Member
@@ -36,12 +37,16 @@ class AddMembersPayload(BaseModel):
3637
@field_validator("resource_type")
3738
def resource_type_validate_regular_expression(cls, value):
3839
"""Validates the regular expression"""
40+
if not isinstance(value, str):
41+
value = str(value)
42+
3943
if not re.match(r"^[a-z](?:-?[a-z]){1,63}$", value):
4044
raise ValueError(r"must validate the regular expression /^[a-z](?:-?[a-z]){1,63}$/")
4145
return value
4246

4347
model_config = ConfigDict(
44-
populate_by_name=True,
48+
validate_by_name=True,
49+
validate_by_alias=True,
4550
validate_assignment=True,
4651
protected_namespaces=(),
4752
)
@@ -52,8 +57,7 @@ def to_str(self) -> str:
5257

5358
def to_json(self) -> str:
5459
"""Returns the JSON representation of the model using alias"""
55-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
56-
return json.dumps(self.to_dict())
60+
return json.dumps(to_jsonable_python(self.to_dict()))
5761

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

services/authorization/src/stackit/authorization/models/add_role_payload.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.authorization.models.permission_request import PermissionRequest
@@ -37,12 +38,16 @@ class AddRolePayload(BaseModel):
3738
@field_validator("name")
3839
def name_validate_regular_expression(cls, value):
3940
"""Validates the regular expression"""
41+
if not isinstance(value, str):
42+
value = str(value)
43+
4044
if not re.match(r"^[a-z](?:[-.]?[a-z]){1,63}$", value):
4145
raise ValueError(r"must validate the regular expression /^[a-z](?:[-.]?[a-z]){1,63}$/")
4246
return value
4347

4448
model_config = ConfigDict(
45-
populate_by_name=True,
49+
validate_by_name=True,
50+
validate_by_alias=True,
4651
validate_assignment=True,
4752
protected_namespaces=(),
4853
)
@@ -53,8 +58,7 @@ def to_str(self) -> str:
5358

5459
def to_json(self) -> str:
5560
"""Returns the JSON representation of the model using alias"""
56-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
57-
return json.dumps(self.to_dict())
61+
return json.dumps(to_jsonable_python(self.to_dict()))
5862

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

services/authorization/src/stackit/authorization/models/delete_role_response.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 Self
2223

2324
from stackit.authorization.models.zookie import Zookie
@@ -32,7 +33,8 @@ class DeleteRoleResponse(BaseModel):
3233
__properties: ClassVar[List[str]] = ["writtenAt"]
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/authorization/src/stackit/authorization/models/error_response.py

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

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

2526

@@ -49,7 +50,8 @@ def time_stamp_change_year_zero_to_one(cls, value):
4950
return value
5051

5152
model_config = ConfigDict(
52-
populate_by_name=True,
53+
validate_by_name=True,
54+
validate_by_alias=True,
5355
validate_assignment=True,
5456
protected_namespaces=(),
5557
)
@@ -60,8 +62,7 @@ def to_str(self) -> str:
6062

6163
def to_json(self) -> str:
6264
"""Returns the JSON representation of the model using alias"""
63-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
64-
return json.dumps(self.to_dict())
65+
return json.dumps(to_jsonable_python(self.to_dict()))
6566

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

services/authorization/src/stackit/authorization/models/existing_permission.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

@@ -34,12 +35,16 @@ class ExistingPermission(BaseModel):
3435
@field_validator("name")
3536
def name_validate_regular_expression(cls, value):
3637
"""Validates the regular expression"""
38+
if not isinstance(value, str):
39+
value = str(value)
40+
3741
if not re.match(r"^[a-z](?:[-.]?[a-z]){1,63}$", value):
3842
raise ValueError(r"must validate the regular expression /^[a-z](?:[-.]?[a-z]){1,63}$/")
3943
return value
4044

4145
model_config = ConfigDict(
42-
populate_by_name=True,
46+
validate_by_name=True,
47+
validate_by_alias=True,
4348
validate_assignment=True,
4449
protected_namespaces=(),
4550
)
@@ -50,8 +55,7 @@ def to_str(self) -> str:
5055

5156
def to_json(self) -> str:
5257
"""Returns the JSON representation of the model using alias"""
53-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
54-
return json.dumps(self.to_dict())
58+
return json.dumps(to_jsonable_python(self.to_dict()))
5559

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

services/authorization/src/stackit/authorization/models/get_role_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, field_validator
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Annotated, Self
2324

2425
from stackit.authorization.models.role import Role
@@ -37,19 +38,26 @@ class GetRoleResponse(BaseModel):
3738
@field_validator("resource_id")
3839
def resource_id_validate_regular_expression(cls, value):
3940
"""Validates the regular expression"""
41+
if not isinstance(value, str):
42+
value = str(value)
43+
4044
if not re.match(r"^([a-zA-Z0-9\/_|\-=+@.]{1,})$", value):
4145
raise ValueError(r"must validate the regular expression /^([a-zA-Z0-9\/_|\-=+@.]{1,})$/")
4246
return value
4347

4448
@field_validator("resource_type")
4549
def resource_type_validate_regular_expression(cls, value):
4650
"""Validates the regular expression"""
51+
if not isinstance(value, str):
52+
value = str(value)
53+
4754
if not re.match(r"^[a-z](?:-?[a-z]){1,63}$", value):
4855
raise ValueError(r"must validate the regular expression /^[a-z](?:-?[a-z]){1,63}$/")
4956
return value
5057

5158
model_config = ConfigDict(
52-
populate_by_name=True,
59+
validate_by_name=True,
60+
validate_by_alias=True,
5361
validate_assignment=True,
5462
protected_namespaces=(),
5563
)
@@ -60,8 +68,7 @@ def to_str(self) -> str:
6068

6169
def to_json(self) -> str:
6270
"""Returns the JSON representation of the model using alias"""
63-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
64-
return json.dumps(self.to_dict())
71+
return json.dumps(to_jsonable_python(self.to_dict()))
6572

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

services/authorization/src/stackit/authorization/models/list_members_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, field_validator
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Annotated, Self
2324

2425
from stackit.authorization.models.member import Member
@@ -37,19 +38,26 @@ class ListMembersResponse(BaseModel):
3738
@field_validator("resource_id")
3839
def resource_id_validate_regular_expression(cls, value):
3940
"""Validates the regular expression"""
41+
if not isinstance(value, str):
42+
value = str(value)
43+
4044
if not re.match(r"^([a-zA-Z0-9\/_|\-=+@.]{1,})$", value):
4145
raise ValueError(r"must validate the regular expression /^([a-zA-Z0-9\/_|\-=+@.]{1,})$/")
4246
return value
4347

4448
@field_validator("resource_type")
4549
def resource_type_validate_regular_expression(cls, value):
4650
"""Validates the regular expression"""
51+
if not isinstance(value, str):
52+
value = str(value)
53+
4754
if not re.match(r"^[a-z](?:-?[a-z]){1,63}$", value):
4855
raise ValueError(r"must validate the regular expression /^[a-z](?:-?[a-z]){1,63}$/")
4956
return value
5057

5158
model_config = ConfigDict(
52-
populate_by_name=True,
59+
validate_by_name=True,
60+
validate_by_alias=True,
5361
validate_assignment=True,
5462
protected_namespaces=(),
5563
)
@@ -60,8 +68,7 @@ def to_str(self) -> str:
6068

6169
def to_json(self) -> str:
6270
"""Returns the JSON representation of the model using alias"""
63-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
64-
return json.dumps(self.to_dict())
71+
return json.dumps(to_jsonable_python(self.to_dict()))
6572

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

0 commit comments

Comments
 (0)