Skip to content

Commit 26fb96f

Browse files
api-clients-generation-pipeline[bot]therveci.datadog-api-spec
authored
Change python API model (#351)
* Define API methods statically This moves the methods definition to classic methods on API classes, and refactor the code a bit to reduce duplication. * Regenerate client from commit 289b515 of spec repo Co-authored-by: Thomas Hervé <[email protected]> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 87ea660 commit 26fb96f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+11924
-13760
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.4.1.dev6",
7-
"regenerated": "2021-03-30 13:18:25.700382",
8-
"spec_repo_commit": "6bab119"
7+
"regenerated": "2021-03-30 15:15:15.278615",
8+
"spec_repo_commit": "289b515"
99
},
1010
"v2": {
1111
"apigentools_version": "1.4.1.dev6",
12-
"regenerated": "2021-03-30 13:19:05.062981",
13-
"spec_repo_commit": "6bab119"
12+
"regenerated": "2021-03-30 15:15:42.391195",
13+
"spec_repo_commit": "289b515"
1414
}
1515
}
1616
}

.generator/templates/api.mustache

Lines changed: 79 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -32,100 +32,7 @@ class {{classname}}(object):
3232
self.api_client = api_client
3333
{{#operation}}
3434

35-
def __{{operationId}}(
36-
self,
37-
{{#requiredParams}}
38-
{{^defaultValue}}
39-
{{paramName}},
40-
{{/defaultValue}}
41-
{{/requiredParams}}
42-
{{#requiredParams}}
43-
{{#defaultValue}}
44-
{{paramName}}={{{defaultValue}}},
45-
{{/defaultValue}}
46-
{{/requiredParams}}
47-
**kwargs
48-
):
49-
"""{{#summary}}{{{.}}}{{/summary}}{{^summary}}{{operationId}}{{/summary}} # noqa: E501
50-
51-
{{#notes}}
52-
{{{notes}}} # noqa: E501
53-
{{/notes}}
54-
This method makes a synchronous HTTP request by default. To make an
55-
asynchronous HTTP request, please pass async_req=True
56-
57-
>>> thread = api.{{operationId}}({{#requiredParams}}{{^defaultValue}}{{paramName}}, {{/defaultValue}}{{/requiredParams}}{{#requiredParams}}{{#defaultValue}}{{paramName}}={{{defaultValue}}}, {{/defaultValue}}{{/requiredParams}}async_req=True)
58-
>>> result = thread.get()
59-
60-
{{#requiredParams}}
61-
{{#-last}}
62-
Args:
63-
{{/-last}}
64-
{{/requiredParams}}
65-
{{#requiredParams}}
66-
{{^defaultValue}}
67-
{{paramName}} ({{dataType}}):{{#description}} {{{description}}}{{/description}}
68-
{{/defaultValue}}
69-
{{/requiredParams}}
70-
{{#requiredParams}}
71-
{{#defaultValue}}
72-
{{paramName}} ({{dataType}}):{{#description}} {{{description}}}.{{/description}} defaults to {{{defaultValue}}}, must be one of [{{{defaultValue}}}]
73-
{{/defaultValue}}
74-
{{/requiredParams}}
75-
76-
Keyword Args:{{#optionalParams}}
77-
{{paramName}} ({{dataType}}):{{#description}} {{{description}}}.{{/description}} [optional]{{#defaultValue}} if omitted the server will use the default value of {{{defaultValue}}}{{/defaultValue}}{{/optionalParams}}
78-
_return_http_data_only (bool): response data without head status
79-
code and headers. Default is True.
80-
_preload_content (bool): if False, the urllib3.HTTPResponse object
81-
will be returned without reading/decoding response data.
82-
Default is True.
83-
_request_timeout (float/tuple): timeout setting for this request. If one
84-
number provided, it will be total request timeout. It can also
85-
be a pair (tuple) of (connection, read) timeouts.
86-
Default is None.
87-
_check_input_type (bool): specifies if type checking
88-
should be done one the data sent to the server.
89-
Default is True.
90-
_check_return_type (bool): specifies if type checking
91-
should be done one the data received from the server.
92-
Default is True.
93-
_host_index (int/None): specifies the index of the server
94-
that we want to use.
95-
Default is read from the configuration.
96-
async_req (bool): execute request asynchronously
97-
98-
Returns:
99-
{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}
100-
If the method is called asynchronously, returns the request
101-
thread.
102-
"""
103-
kwargs['async_req'] = kwargs.get(
104-
'async_req', False
105-
)
106-
kwargs['_return_http_data_only'] = kwargs.get(
107-
'_return_http_data_only', True
108-
)
109-
kwargs['_preload_content'] = kwargs.get(
110-
'_preload_content', True
111-
)
112-
kwargs['_request_timeout'] = kwargs.get(
113-
'_request_timeout', None
114-
)
115-
kwargs['_check_input_type'] = kwargs.get(
116-
'_check_input_type', True
117-
)
118-
kwargs['_check_return_type'] = kwargs.get(
119-
'_check_return_type', True
120-
)
121-
kwargs['_host_index'] = kwargs.get('_host_index')
122-
{{#requiredParams}}
123-
kwargs['{{paramName}}'] = \
124-
{{paramName}}
125-
{{/requiredParams}}
126-
return self.call_with_http_info(**kwargs)
127-
128-
self.{{operationId}} = _Endpoint(
35+
self._{{operationId}}_endpoint = _Endpoint(
12936
settings={
13037
'response_type': {{#returnType}}({{{returnType}}},){{/returnType}}{{^returnType}}None{{/returnType}},
13138
{{#authMethods}}
@@ -299,8 +206,84 @@ class {{classname}}(object):
299206
'content_type': [],
300207
{{/hasConsumes}}
301208
},
302-
api_client=api_client,
303-
callable=__{{operationId}}
209+
api_client=api_client
304210
)
305211
{{/operation}}
212+
213+
{{#operation}}
214+
def {{operationId}}(
215+
self,
216+
{{#requiredParams}}
217+
{{^defaultValue}}
218+
{{paramName}},
219+
{{/defaultValue}}
220+
{{/requiredParams}}
221+
{{#requiredParams}}
222+
{{#defaultValue}}
223+
{{paramName}}={{{defaultValue}}},
224+
{{/defaultValue}}
225+
{{/requiredParams}}
226+
**kwargs
227+
):
228+
"""{{#summary}}{{{.}}}{{/summary}}{{^summary}}{{operationId}}{{/summary}} # noqa: E501
229+
230+
{{#notes}}
231+
{{{notes}}} # noqa: E501
232+
{{/notes}}
233+
This method makes a synchronous HTTP request by default. To make an
234+
asynchronous HTTP request, please pass async_req=True
235+
236+
>>> thread = api.{{operationId}}({{#requiredParams}}{{^defaultValue}}{{paramName}}, {{/defaultValue}}{{/requiredParams}}{{#requiredParams}}{{#defaultValue}}{{paramName}}={{{defaultValue}}}, {{/defaultValue}}{{/requiredParams}}async_req=True)
237+
>>> result = thread.get()
238+
239+
{{#requiredParams}}
240+
{{#-last}}
241+
Args:
242+
{{/-last}}
243+
{{/requiredParams}}
244+
{{#requiredParams}}
245+
{{^defaultValue}}
246+
{{paramName}} ({{dataType}}):{{#description}} {{{description}}}{{/description}}
247+
{{/defaultValue}}
248+
{{/requiredParams}}
249+
{{#requiredParams}}
250+
{{#defaultValue}}
251+
{{paramName}} ({{dataType}}):{{#description}} {{{description}}}.{{/description}} defaults to {{{defaultValue}}}, must be one of [{{{defaultValue}}}]
252+
{{/defaultValue}}
253+
{{/requiredParams}}
254+
255+
Keyword Args:{{#optionalParams}}
256+
{{paramName}} ({{dataType}}):{{#description}} {{{description}}}.{{/description}} [optional]{{#defaultValue}} if omitted the server will use the default value of {{{defaultValue}}}{{/defaultValue}}{{/optionalParams}}
257+
_return_http_data_only (bool): response data without head status
258+
code and headers. Default is True.
259+
_preload_content (bool): if False, the urllib3.HTTPResponse object
260+
will be returned without reading/decoding response data.
261+
Default is True.
262+
_request_timeout (float/tuple): timeout setting for this request. If one
263+
number provided, it will be total request timeout. It can also
264+
be a pair (tuple) of (connection, read) timeouts.
265+
Default is None.
266+
_check_input_type (bool): specifies if type checking
267+
should be done one the data sent to the server.
268+
Default is True.
269+
_check_return_type (bool): specifies if type checking
270+
should be done one the data received from the server.
271+
Default is True.
272+
_host_index (int/None): specifies the index of the server
273+
that we want to use.
274+
Default is read from the configuration.
275+
async_req (bool): execute request asynchronously
276+
277+
Returns:
278+
{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}
279+
If the method is called asynchronously, returns the request
280+
thread.
281+
"""
282+
kwargs = self._{{operationId}}_endpoint.default_arguments(kwargs)
283+
{{#requiredParams}}
284+
kwargs['{{paramName}}'] = \
285+
{{paramName}}
286+
{{/requiredParams}}
287+
return self._{{operationId}}_endpoint.call_with_http_info(**kwargs)
288+
{{/operation}}
306289
{{/operations}}

.generator/templates/api_client.mustache

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,18 @@ class Endpoint(object):
794794
"""
795795
return self.callable(self, *args, **kwargs)
796796

797+
def default_arguments(self, kwargs):
798+
"""Helper setting default arguments to call_with_http_info."""
799+
default_kwargs = kwargs.copy()
800+
default_kwargs['async_req'] = kwargs.get('async_req', False)
801+
default_kwargs['_return_http_data_only'] = kwargs.get('_return_http_data_only', True)
802+
default_kwargs['_preload_content'] = kwargs.get('_preload_content', True)
803+
default_kwargs['_request_timeout'] = kwargs.get('_request_timeout')
804+
default_kwargs['_check_input_type'] = kwargs.get('_check_input_type', True)
805+
default_kwargs['_check_return_type'] = kwargs.get('_check_return_type', True)
806+
default_kwargs['_host_index'] = kwargs.get('_host_index')
807+
return default_kwargs
808+
797809
def call_with_http_info(self, **kwargs):
798810

799811
is_unstable = self.api_client.configuration.unstable_operations.get(self.settings['operation_id'])

src/datadog_api_client/v1/api/authentication_api.py

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -32,53 +32,7 @@ def __init__(self, api_client=None):
3232
api_client = ApiClient()
3333
self.api_client = api_client
3434

35-
def __validate(self, **kwargs):
36-
"""Validate API key # noqa: E501
37-
38-
Check if the API key (not the APP key) is valid. If invalid, a 403 is returned. # noqa: E501
39-
This method makes a synchronous HTTP request by default. To make an
40-
asynchronous HTTP request, please pass async_req=True
41-
42-
>>> thread = api.validate(async_req=True)
43-
>>> result = thread.get()
44-
45-
46-
Keyword Args:
47-
_return_http_data_only (bool): response data without head status
48-
code and headers. Default is True.
49-
_preload_content (bool): if False, the urllib3.HTTPResponse object
50-
will be returned without reading/decoding response data.
51-
Default is True.
52-
_request_timeout (float/tuple): timeout setting for this request. If one
53-
number provided, it will be total request timeout. It can also
54-
be a pair (tuple) of (connection, read) timeouts.
55-
Default is None.
56-
_check_input_type (bool): specifies if type checking
57-
should be done one the data sent to the server.
58-
Default is True.
59-
_check_return_type (bool): specifies if type checking
60-
should be done one the data received from the server.
61-
Default is True.
62-
_host_index (int/None): specifies the index of the server
63-
that we want to use.
64-
Default is read from the configuration.
65-
async_req (bool): execute request asynchronously
66-
67-
Returns:
68-
AuthenticationValidationResponse
69-
If the method is called asynchronously, returns the request
70-
thread.
71-
"""
72-
kwargs["async_req"] = kwargs.get("async_req", False)
73-
kwargs["_return_http_data_only"] = kwargs.get("_return_http_data_only", True)
74-
kwargs["_preload_content"] = kwargs.get("_preload_content", True)
75-
kwargs["_request_timeout"] = kwargs.get("_request_timeout", None)
76-
kwargs["_check_input_type"] = kwargs.get("_check_input_type", True)
77-
kwargs["_check_return_type"] = kwargs.get("_check_return_type", True)
78-
kwargs["_host_index"] = kwargs.get("_host_index")
79-
return self.call_with_http_info(**kwargs)
80-
81-
self.validate = _Endpoint(
35+
self._validate_endpoint = _Endpoint(
8236
settings={
8337
"response_type": (AuthenticationValidationResponse,),
8438
"auth": ["apiKeyAuth"],
@@ -101,5 +55,44 @@ def __validate(self, **kwargs):
10155
"content_type": [],
10256
},
10357
api_client=api_client,
104-
callable=__validate,
10558
)
59+
60+
def validate(self, **kwargs):
61+
"""Validate API key # noqa: E501
62+
63+
Check if the API key (not the APP key) is valid. If invalid, a 403 is returned. # noqa: E501
64+
This method makes a synchronous HTTP request by default. To make an
65+
asynchronous HTTP request, please pass async_req=True
66+
67+
>>> thread = api.validate(async_req=True)
68+
>>> result = thread.get()
69+
70+
71+
Keyword Args:
72+
_return_http_data_only (bool): response data without head status
73+
code and headers. Default is True.
74+
_preload_content (bool): if False, the urllib3.HTTPResponse object
75+
will be returned without reading/decoding response data.
76+
Default is True.
77+
_request_timeout (float/tuple): timeout setting for this request. If one
78+
number provided, it will be total request timeout. It can also
79+
be a pair (tuple) of (connection, read) timeouts.
80+
Default is None.
81+
_check_input_type (bool): specifies if type checking
82+
should be done one the data sent to the server.
83+
Default is True.
84+
_check_return_type (bool): specifies if type checking
85+
should be done one the data received from the server.
86+
Default is True.
87+
_host_index (int/None): specifies the index of the server
88+
that we want to use.
89+
Default is read from the configuration.
90+
async_req (bool): execute request asynchronously
91+
92+
Returns:
93+
AuthenticationValidationResponse
94+
If the method is called asynchronously, returns the request
95+
thread.
96+
"""
97+
kwargs = self._validate_endpoint.default_arguments(kwargs)
98+
return self._validate_endpoint.call_with_http_info(**kwargs)

0 commit comments

Comments
 (0)