Skip to content

Commit a51d02a

Browse files
authored
[Python] Fix #5126 operations with req enums of length one (#5129)
* Updates ap.mustache for python-experimental, adds test test_test_endpoint_enums_length_one * Removes sortParamsByRequiredFlag from python-experimental * Removes duplicate params from docstring
1 parent 3922607 commit a51d02a

17 files changed

Lines changed: 2691 additions & 2011 deletions

File tree

docs/generators/python-experimental.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ sidebar_label: python-experimental
1212
|packageUrl|python package URL.| |null|
1313
|packageVersion|python package version.| |1.0.0|
1414
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
15-
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
1615
|useNose|use the nose test framework| |false|
1716

1817
## IMPORT MAPPING

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ public PythonClientExperimentalCodegen() {
9797
modelTestTemplateFiles.remove("model_test.mustache", ".py");
9898
modelTestTemplateFiles.put("python-experimental/model_test.mustache", ".py");
9999

100+
// this generator does not use SORT_PARAMS_BY_REQUIRED_FLAG
101+
// this generator uses the following order for endpoint paramters and model properties
102+
// required params/props with no enum of length one
103+
// required params/props with enum of length one (which is used to set a default value as a python named arg value)
104+
// optional params/props with **kwargs in python
105+
cliOptions.remove(4);
106+
100107
generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata)
101108
.stability(Stability.EXPERIMENTAL)
102109
.build();

modules/openapi-generator/src/main/resources/python/python-experimental/api.mustache

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -45,48 +45,72 @@ class {{classname}}(object):
4545
self.api_client = api_client
4646
{{#operation}}
4747

48-
def __{{operationId}}(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs): # noqa: E501
48+
def __{{operationId}}(
49+
self,
50+
{{#requiredParams}}
51+
{{^defaultValue}}
52+
{{paramName}},
53+
{{/defaultValue}}
54+
{{/requiredParams}}
55+
{{#requiredParams}}
56+
{{#defaultValue}}
57+
{{paramName}}={{{defaultValue}}},
58+
{{/defaultValue}}
59+
{{/requiredParams}}
60+
**kwargs
61+
):
4962
"""{{#summary}}{{{.}}}{{/summary}}{{^summary}}{{operationId}}{{/summary}} # noqa: E501
5063

5164
{{#notes}}
5265
{{{notes}}} # noqa: E501
5366
{{/notes}}
5467
This method makes a synchronous HTTP request by default. To make an
5568
asynchronous HTTP request, please pass async_req=True
56-
{{#sortParamsByRequiredFlag}}
57-
>>> thread = api.{{operationId}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}async_req=True)
58-
{{/sortParamsByRequiredFlag}}
59-
{{^sortParamsByRequiredFlag}}
60-
>>> thread = api.{{operationId}}({{#allParams}}{{#required}}{{paramName}}={{paramName}}_value, {{/required}}{{/allParams}}async_req=True)
61-
{{/sortParamsByRequiredFlag}}
69+
>>> thread = api.{{operationId}}({{#requiredParams}}{{^defaultValue}}{{paramName}}, {{/defaultValue}}{{/requiredParams}}{{#requiredParams}}{{#defaultValue}}{{paramName}}={{{defaultValue}}}, {{/defaultValue}}{{/requiredParams}}async_req=True)
6270
>>> result = thread.get()
6371

64-
:param async_req bool: execute request asynchronously
65-
Default is False.
66-
{{#allParams}}
67-
:param {{dataType}} {{paramName}}:{{#description}} {{{description}}}{{/description}}{{#required}} (required){{/required}}{{#optional}}(optional){{/optional}}
68-
{{/allParams}}
69-
:param _return_http_data_only: response data without head status
70-
code and headers. Default is True.
71-
:param _preload_content: if False, the urllib3.HTTPResponse object
72-
will be returned without reading/decoding response data.
73-
Default is True.
74-
:param _request_timeout: timeout setting for this request. If one
75-
number provided, it will be total request timeout. It can also
76-
be a pair (tuple) of (connection, read) timeouts.
77-
Default is None.
78-
:param _check_input_type: boolean specifying if type checking
79-
should be done one the data sent to the server.
80-
Default is True.
81-
:param _check_return_type: boolean specifying if type checking
82-
should be done one the data received from the server.
83-
Default is True.
84-
:param _host_index: integer specifying the index of the server
85-
that we want to use.
86-
Default is 0.
87-
:return: {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}
88-
If the method is called asynchronously, returns the request
89-
thread.
72+
{{#requiredParams}}
73+
{{^hasMore}}
74+
Args:
75+
{{/hasMore}}
76+
{{/requiredParams}}
77+
{{#requiredParams}}
78+
{{^defaultValue}}
79+
{{paramName}} ({{dataType}}):{{#description}} {{description}}{{/description}}
80+
{{/defaultValue}}
81+
{{/requiredParams}}
82+
{{#requiredParams}}
83+
{{#defaultValue}}
84+
{{paramName}} ({{dataType}}):{{#description}} {{description}}.{{/description}} defaults to {{{defaultValue}}}, must be one of [{{{defaultValue}}}]
85+
{{/defaultValue}}
86+
{{/requiredParams}}
87+
88+
Keyword Args:{{#optionalParams}}
89+
{{paramName}} ({{dataType}}):{{#description}} {{description}}.{{/description}} [optional]{{#defaultValue}} if omitted the server will use the default value of {{{defaultValue}}}{{/defaultValue}}{{/optionalParams}}
90+
_return_http_data_only (bool): response data without head status
91+
code and headers. Default is True.
92+
_preload_content (bool): if False, the urllib3.HTTPResponse object
93+
will be returned without reading/decoding response data.
94+
Default is True.
95+
_request_timeout (float/tuple): timeout setting for this request. If one
96+
number provided, it will be total request timeout. It can also
97+
be a pair (tuple) of (connection, read) timeouts.
98+
Default is None.
99+
_check_input_type (bool): specifies if type checking
100+
should be done one the data sent to the server.
101+
Default is True.
102+
_check_return_type (bool): specifies if type checking
103+
should be done one the data received from the server.
104+
Default is True.
105+
_host_index (int): specifies the index of the server
106+
that we want to use.
107+
Default is 0.
108+
async_req (bool): execute request asynchronously
109+
110+
Returns:
111+
{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}
112+
If the method is called asynchronously, returns the request
113+
thread.
90114
"""
91115
kwargs['async_req'] = kwargs.get(
92116
'async_req', False

samples/client/petstore/python-experimental/petstore_api/api/another_fake_api.py

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ def __init__(self, api_client=None):
4949
api_client = ApiClient()
5050
self.api_client = api_client
5151

52-
def __call_123_test_special_tags(self, body, **kwargs): # noqa: E501
52+
def __call_123_test_special_tags(
53+
self,
54+
body,
55+
**kwargs
56+
):
5357
"""To test special tags # noqa: E501
5458
5559
To test special tags and operation ID starting with number # noqa: E501
@@ -58,30 +62,34 @@ def __call_123_test_special_tags(self, body, **kwargs): # noqa: E501
5862
>>> thread = api.call_123_test_special_tags(body, async_req=True)
5963
>>> result = thread.get()
6064
61-
:param async_req bool: execute request asynchronously
62-
Default is False.
63-
:param client.Client body: client model (required)
64-
:param _return_http_data_only: response data without head status
65-
code and headers. Default is True.
66-
:param _preload_content: if False, the urllib3.HTTPResponse object
67-
will be returned without reading/decoding response data.
68-
Default is True.
69-
:param _request_timeout: timeout setting for this request. If one
70-
number provided, it will be total request timeout. It can also
71-
be a pair (tuple) of (connection, read) timeouts.
72-
Default is None.
73-
:param _check_input_type: boolean specifying if type checking
74-
should be done one the data sent to the server.
75-
Default is True.
76-
:param _check_return_type: boolean specifying if type checking
77-
should be done one the data received from the server.
78-
Default is True.
79-
:param _host_index: integer specifying the index of the server
80-
that we want to use.
81-
Default is 0.
82-
:return: client.Client
83-
If the method is called asynchronously, returns the request
84-
thread.
65+
Args:
66+
body (client.Client): client model
67+
68+
Keyword Args:
69+
_return_http_data_only (bool): response data without head status
70+
code and headers. Default is True.
71+
_preload_content (bool): if False, the urllib3.HTTPResponse object
72+
will be returned without reading/decoding response data.
73+
Default is True.
74+
_request_timeout (float/tuple): timeout setting for this request. If one
75+
number provided, it will be total request timeout. It can also
76+
be a pair (tuple) of (connection, read) timeouts.
77+
Default is None.
78+
_check_input_type (bool): specifies if type checking
79+
should be done one the data sent to the server.
80+
Default is True.
81+
_check_return_type (bool): specifies if type checking
82+
should be done one the data received from the server.
83+
Default is True.
84+
_host_index (int): specifies the index of the server
85+
that we want to use.
86+
Default is 0.
87+
async_req (bool): execute request asynchronously
88+
89+
Returns:
90+
client.Client
91+
If the method is called asynchronously, returns the request
92+
thread.
8593
"""
8694
kwargs['async_req'] = kwargs.get(
8795
'async_req', False

0 commit comments

Comments
 (0)