Skip to content

Commit d05309e

Browse files
committed
Fixes the ambiguous schema validation issue as well (and reformats some stuff)
1 parent 2db32d7 commit d05309e

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

cli/client_gen/annotation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
"""Utilities for converting OpenAPI schema pieces to Python type annotations."""
77

8+
89
def spec_type_to_py_type(s_type: str, s_format: Optional[str]) -> str:
910
"""Converts an OpenAPI type+format to a Python type string"""
1011
s_mapping = {
@@ -15,7 +16,7 @@ def spec_type_to_py_type(s_type: str, s_format: Optional[str]) -> str:
1516
(
1617
'string',
1718
'byte',
18-
): 'Annotated[str, \'base64\']',
19+
): "Annotated[str, 'base64']",
1920
(
2021
'string',
2122
'date-time',

test/test_client_methods.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,14 @@ def request_matcher(request: requests.PreparedRequest):
6767
'items': [
6868
{'id': 1, 'display_name': 'User 1'},
6969
{'id': 2, 'display_name': 'User 2'},
70-
{'id': 3, 'display_name': 'User 3'}
70+
{'id': 3, 'display_name': 'User 3'},
7171
],
72-
'cursor': 'next_page_cursor'
72+
'cursor': 'next_page_cursor',
7373
}
7474
elif cursor == 'next_page_cursor':
7575
# Second page: 2 users, no next cursor
7676
response_data = {
77-
'items': [
78-
{'id': 4, 'display_name': 'User 4'},
79-
{'id': 5, 'display_name': 'User 5'}
80-
]
77+
'items': [{'id': 4, 'display_name': 'User 4'}, {'id': 5, 'display_name': 'User 5'}]
8178
}
8279
else:
8380
# No more pages
@@ -120,12 +117,6 @@ def test_request_conformance(self, openapi_stub):
120117
# Construct a DialpadClient with a fake API key.
121118
dp = DialpadClient('123')
122119

123-
skip = set(
124-
[
125-
('FaxLinesResource', 'assign'),
126-
]
127-
)
128-
129120
# Iterate through the attributes on the client object to find the API resource accessors.
130121
for a in dir(dp):
131122
resource_instance = getattr(dp, a)
@@ -151,21 +142,17 @@ def test_request_conformance(self, openapi_stub):
151142
if not callable(resource_method):
152143
continue
153144

154-
if (resource_instance.__class__.__name__, method_attr) in skip:
155-
logger.info(
156-
'Skipping %s.%s as it is explicitly excluded from this test',
157-
resource_instance.__class__.__name__,
158-
method_attr,
159-
)
160-
continue
161-
162145
# Generate fake kwargs for the resource method.
163146
faked_kwargs = generate_faked_kwargs(resource_method)
164147
if (resource_instance.__class__.__name__, method_attr) == ('NumbersResource', 'swap'):
165148
# The openapi validator doesn't like that swap_details can be valid under multiple
166149
# OneOf schemas...
167150
faked_kwargs['request_body'].pop('swap_details', None)
168151

152+
if (resource_instance.__class__.__name__, method_attr) == ('FaxLinesResource', 'assign'):
153+
# The openapi validator doesn't like it if "line" could be valid under multiple schemas.
154+
faked_kwargs['request_body']['line'] = {'type': 'toll-free'}
155+
169156
logger.info(
170157
'Testing resource method %s.%s with faked kwargs: %s',
171158
resource_instance.__class__.__name__,

0 commit comments

Comments
 (0)