Skip to content

Commit f6b5697

Browse files
author
smoghe-bw
committed
Revert "Align link and error schemas with BRTC spec"
This reverts commit a73a50e.
1 parent a73a50e commit f6b5697

8 files changed

Lines changed: 54 additions & 125 deletions

File tree

bandwidth.yml

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,13 +2320,6 @@ components:
23202320
type: string
23212321
href:
23222322
type: string
2323-
method:
2324-
type: string
2325-
enum:
2326-
- GET
2327-
- POST
2328-
- DELETE
2329-
description: The HTTP method to use when making the request.
23302323
errorObject:
23312324
type: object
23322325
properties:
@@ -6679,13 +6672,6 @@ components:
66796672
error:
66806673
type: object
66816674
properties:
6682-
id:
6683-
type: string
6684-
format: uuid
6685-
description: A unique identifier for the error.
6686-
type:
6687-
type: string
6688-
description: The type of error.
66896675
code:
66906676
type: integer
66916677
description:
@@ -6694,21 +6680,6 @@ components:
66946680
type: array
66956681
items:
66966682
$ref: '#/components/schemas/telephoneNumber'
6697-
source:
6698-
type: object
6699-
properties:
6700-
parameter:
6701-
type: string
6702-
description: The URI parameter that caused the error.
6703-
field:
6704-
type: string
6705-
description: The request body field that caused the error.
6706-
header:
6707-
type: string
6708-
description: The header that caused the error.
6709-
reference:
6710-
type: string
6711-
description: A reference to the source of the error.
67126683
telephoneNumber:
67136684
type: object
67146685
properties:

bandwidth/models/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
from bandwidth.models.latest_message_delivery_status_enum import LatestMessageDeliveryStatusEnum
9595
from bandwidth.models.line_type_enum import LineTypeEnum
9696
from bandwidth.models.link import Link
97-
from bandwidth.models.link_method_enum import LinkMethodEnum
9897
from bandwidth.models.link_schema import LinkSchema
9998
from bandwidth.models.links_object import LinksObject
10099
from bandwidth.models.list_endpoints_response import ListEndpointsResponse

bandwidth/models/error.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
2222
from typing import Any, ClassVar, Dict, List, Optional
23-
from bandwidth.models.error_source import ErrorSource
2423
from bandwidth.models.telephone_number import TelephoneNumber
2524
from typing import Optional, Set
2625
from typing_extensions import Self
@@ -29,14 +28,11 @@ class Error(BaseModel):
2928
"""
3029
Error
3130
""" # noqa: E501
32-
id: Optional[StrictStr] = Field(default=None, description="A unique identifier for the error.")
33-
type: Optional[StrictStr] = Field(default=None, description="The type of error.")
3431
code: Optional[StrictInt] = None
3532
description: Optional[StrictStr] = None
3633
telephone_numbers: Optional[List[TelephoneNumber]] = Field(default=None, alias="telephoneNumbers")
37-
source: Optional[ErrorSource] = None
3834
additional_properties: Dict[str, Any] = {}
39-
__properties: ClassVar[List[str]] = ["id", "type", "code", "description", "telephoneNumbers", "source"]
35+
__properties: ClassVar[List[str]] = ["code", "description", "telephoneNumbers"]
4036

4137
model_config = ConfigDict(
4238
populate_by_name=True,
@@ -86,9 +82,6 @@ def to_dict(self) -> Dict[str, Any]:
8682
if _item_telephone_numbers:
8783
_items.append(_item_telephone_numbers.to_dict())
8884
_dict['telephoneNumbers'] = _items
89-
# override the default output from pydantic by calling `to_dict()` of source
90-
if self.source:
91-
_dict['source'] = self.source.to_dict()
9285
# puts key-value pairs in additional_properties in the top level
9386
if self.additional_properties is not None:
9487
for _key, _value in self.additional_properties.items():
@@ -106,12 +99,9 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
10699
return cls.model_validate(obj)
107100

108101
_obj = cls.model_validate({
109-
"id": obj.get("id"),
110-
"type": obj.get("type"),
111102
"code": obj.get("code"),
112103
"description": obj.get("description"),
113-
"telephoneNumbers": [TelephoneNumber.from_dict(_item) for _item in obj["telephoneNumbers"]] if obj.get("telephoneNumbers") is not None else None,
114-
"source": ErrorSource.from_dict(obj["source"]) if obj.get("source") is not None else None
104+
"telephoneNumbers": [TelephoneNumber.from_dict(_item) for _item in obj["telephoneNumbers"]] if obj.get("telephoneNumbers") is not None else None
115105
})
116106
# store additional fields in additional_properties
117107
for _key in obj.keys():

bandwidth/models/link.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
import re # noqa: F401
1919
import json
2020

21-
from pydantic import BaseModel, ConfigDict, Field, StrictStr
21+
from pydantic import BaseModel, ConfigDict, StrictStr
2222
from typing import Any, ClassVar, Dict, List, Optional
23-
from bandwidth.models.link_method_enum import LinkMethodEnum
2423
from typing import Optional, Set
2524
from typing_extensions import Self
2625

@@ -30,9 +29,8 @@ class Link(BaseModel):
3029
""" # noqa: E501
3130
rel: Optional[StrictStr] = None
3231
href: Optional[StrictStr] = None
33-
method: Optional[LinkMethodEnum] = Field(default=None, description="The HTTP method to use when making the request.")
3432
additional_properties: Dict[str, Any] = {}
35-
__properties: ClassVar[List[str]] = ["rel", "href", "method"]
33+
__properties: ClassVar[List[str]] = ["rel", "href"]
3634

3735
model_config = ConfigDict(
3836
populate_by_name=True,
@@ -93,8 +91,7 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
9391

9492
_obj = cls.model_validate({
9593
"rel": obj.get("rel"),
96-
"href": obj.get("href"),
97-
"method": obj.get("method")
94+
"href": obj.get("href")
9895
})
9996
# store additional fields in additional_properties
10097
for _key in obj.keys():

bandwidth/models/link_method_enum.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

test/unit/models/test_error.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import unittest
1717

1818
from bandwidth.models.error import Error
19-
from bandwidth.models.error_source import ErrorSource
2019
from bandwidth.models.telephone_number import TelephoneNumber
2120

2221
class TestError(unittest.TestCase):
@@ -28,36 +27,35 @@ def setUp(self):
2827
def tearDown(self):
2928
pass
3029

31-
def make_instance(self) -> Error:
32-
"""Test Error"""
33-
return Error(
34-
id = '59512d87-7a92-4040-8e4a-78fb772019b9',
35-
type = 'resource.not_found',
36-
code = 404,
37-
description = 'The requested resource was not found.',
38-
telephone_numbers = [
39-
TelephoneNumber(
40-
telephone_number = '+15551234567', )
41-
],
42-
source = ErrorSource(
43-
parameter = 'accountId',
30+
def make_instance(self, include_optional) -> Error:
31+
"""Test Error
32+
include_optional is a boolean, when False only required
33+
params are included, when True both required and
34+
optional params are included """
35+
if include_optional:
36+
return Error(
37+
code = 56,
38+
description = '',
39+
telephone_numbers = [
40+
TelephoneNumber(
41+
telephone_number = '', )
42+
]
4443
)
44+
else:
45+
return Error(
4546
)
4647

4748
def testError(self):
4849
"""Test Error"""
49-
instance = self.make_instance()
50+
instance = self.make_instance(True)
5051
assert instance is not None
5152
assert isinstance(instance, Error)
52-
assert instance.id == '59512d87-7a92-4040-8e4a-78fb772019b9'
53-
assert instance.type == 'resource.not_found'
54-
assert instance.code == 404
55-
assert instance.description == 'The requested resource was not found.'
53+
assert instance.code == 56
54+
assert instance.description == ''
5655
assert isinstance(instance.telephone_numbers, list)
5756
assert len(instance.telephone_numbers) == 1
5857
assert isinstance(instance.telephone_numbers[0], TelephoneNumber)
59-
assert instance.source is not None
60-
assert instance.source.parameter == 'accountId'
58+
assert instance.telephone_numbers[0].telephone_number == ''
6159

6260
if __name__ == '__main__':
6361
unittest.main()

test/unit/models/test_error_source.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,25 @@ def setUp(self):
2626
def tearDown(self):
2727
pass
2828

29-
def make_instance(self) -> ErrorSource:
30-
"""Test ErrorSource"""
31-
return ErrorSource(
32-
parameter = 'parameter',
33-
var_field = 'var_field',
34-
header = 'header',
35-
reference = 'reference'
29+
def make_instance(self, include_optional) -> ErrorSource:
30+
"""Test ErrorSource
31+
include_optional is a boolean, when False only required
32+
params are included, when True both required and
33+
optional params are included """
34+
if include_optional:
35+
return ErrorSource(
36+
parameter = 'parameter',
37+
var_field = 'var_field',
38+
header = 'header',
39+
reference = 'reference'
40+
)
41+
else:
42+
return ErrorSource(
3643
)
3744

3845
def testErrorSource(self):
3946
"""Test ErrorSource"""
40-
instance = self.make_instance()
47+
instance = self.make_instance(True)
4148
assert instance is not None
4249
assert isinstance(instance, ErrorSource)
4350
assert instance.parameter == 'parameter'

test/unit/models/test_link.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,27 @@ def setUp(self):
2626
def tearDown(self):
2727
pass
2828

29-
def make_instance(self) -> Link:
30-
"""Test Link"""
31-
return Link(
32-
rel = 'self',
33-
href = 'https://api.bandwidth.com/v2/accounts/123/endpoints',
34-
method = 'GET'
29+
def make_instance(self, include_optional) -> Link:
30+
"""Test Link
31+
include_optional is a boolean, when False only required
32+
params are included, when True both required and
33+
optional params are included """
34+
if include_optional:
35+
return Link(
36+
rel = 'rel',
37+
href = 'href'
38+
)
39+
else:
40+
return Link(
3541
)
3642

3743
def testLink(self):
3844
"""Test Link"""
39-
instance = self.make_instance()
45+
instance = self.make_instance(True)
4046
assert instance is not None
4147
assert isinstance(instance, Link)
42-
assert instance.rel == 'self'
43-
assert instance.href == 'https://api.bandwidth.com/v2/accounts/123/endpoints'
44-
assert instance.method == 'GET'
48+
assert instance.rel == 'rel'
49+
assert instance.href == 'href'
4550

4651
if __name__ == '__main__':
4752
unittest.main()

0 commit comments

Comments
 (0)