Skip to content

Commit dedf6ba

Browse files
committed
- Hotfix for param ordering in call
1 parent e46e525 commit dedf6ba

File tree

6 files changed

+30
-18
lines changed

6 files changed

+30
-18
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "openapi-python-generator"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
description = "Openapi Python Generator"
55
authors = ["Marco Müllner <[email protected]>"]
66
license = "MIT"

src/openapi_python_generator/language_converters/python/service_generator.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,46 @@ def generate_body_param(operation: Operation) -> Union[str, None]:
3434
return "data"
3535

3636

37-
def generate_params(operation: Operation) -> List[str]:
37+
def generate_params(operation: Operation) -> str:
3838
def _generate_params_from_content(content: Union[Reference, Schema]):
3939
if isinstance(content, Reference):
4040
return f"data : {content.ref.split('/')[-1]}"
4141
else:
4242
return f"data : {type_converter(content, True).converted_type}"
4343

4444
if operation.parameters is None and operation.requestBody is None:
45-
return []
45+
return ""
4646

47-
params = []
47+
params = ""
48+
default_params = ""
4849
if operation.parameters is not None:
4950
for param in operation.parameters:
5051
if not isinstance(param, Parameter):
5152
continue
53+
converted_result = ""
54+
required = False
5255

5356
if isinstance(param.param_schema, Schema):
54-
params.append(
57+
converted_result = (
5558
f"{param.name} : {type_converter(param.param_schema, param.required).converted_type}"
5659
+ ("" if param.required else " = None")
5760
)
61+
required = param.required
5862
elif isinstance(param.param_schema, Reference):
59-
params.append(
63+
converted_result = (
6064
f"{param.name} : {param.param_schema.ref.split('/')[-1] }"
6165
+ (
6266
""
6367
if isinstance(param, Reference) or param.required
6468
else " = None"
6569
)
6670
)
71+
required = isinstance(param, Reference) or param.required
72+
73+
if required:
74+
params += f"{converted_result}, "
75+
else:
76+
default_params += f"{converted_result}, "
6777

6878
if operation.requestBody is not None:
6979
if (
@@ -76,15 +86,17 @@ def _generate_params_from_content(content: Union[Reference, Schema]):
7686
isinstance(content.media_type_schema, Schema)
7787
or isinstance(content.media_type_schema, Reference)
7888
):
79-
params.append(_generate_params_from_content(content.media_type_schema))
89+
params += (
90+
f"{_generate_params_from_content(content.media_type_schema)}, "
91+
)
8092
else:
8193
raise Exception(f"Unsupported media type schema for {str(operation)}")
8294
else:
8395
raise Exception(
8496
f"Unsupported request body type: {type(operation.requestBody)}"
8597
)
8698

87-
return params
99+
return params + default_params
88100

89101

90102
def generate_operation_id(operation: Operation, http_op: str) -> str:

src/openapi_python_generator/language_converters/python/templates/httpx.jinja2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% if async_client %}async {% endif %}def {{ operation_id }}({{ params | join(',') }}) -> {% if return_type.type is none or return_type.type.converted_type is none %}None{% else %}{{ return_type.type.converted_type}}{% endif %}:
1+
{% if async_client %}async {% endif %}def {{ operation_id }}({{ params }}) -> {% if return_type.type is none or return_type.type.converted_type is none %}None{% else %}{{ return_type.type.converted_type}}{% endif %}:
22
base_path = APIConfig.base_path
33
path = f'{{ path_name }}'
44
headers = {

src/openapi_python_generator/language_converters/python/templates/requests.jinja2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def {{ operation_id }}({{ params | join(',') }}) -> {% if return_type.type is none or return_type.type.converted_type is none %}None{% else %}{{ return_type.type.converted_type}}{% endif %}:
1+
def {{ operation_id }}({{ params }}) -> {% if return_type.type is none or return_type.type.converted_type is none %}None{% else %}{{ return_type.type.converted_type}}{% endif %}:
22
base_path = APIConfig.base_path
33
path = f'{{ path_name }}'
44
headers = {

src/openapi_python_generator/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class OpReturnType(BaseModel):
2929

3030

3131
class ServiceOperation(BaseModel):
32-
params: List[str]
32+
params: str
3333
operation_id: str
3434
query_params: List[str]
3535
return_type: OpReturnType

tests/test_service_generator.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_generate_body_param(test_openapi_operation, expected_result):
5858
@pytest.mark.parametrize(
5959
"test_openapi_operation, expected_result",
6060
[
61-
(Operation(parameters=None, requestBody=None), []),
61+
(Operation(parameters=None, requestBody=None), ""),
6262
(
6363
Operation(
6464
parameters=[
@@ -71,7 +71,7 @@ def test_generate_body_param(test_openapi_operation, expected_result):
7171
],
7272
requestBody=None,
7373
),
74-
["test : TestModel"],
74+
"test : TestModel, ",
7575
),
7676
(
7777
Operation(
@@ -84,7 +84,7 @@ def test_generate_body_param(test_openapi_operation, expected_result):
8484
)
8585
],
8686
),
87-
["test2 : Optional[str] = None"],
87+
"test2 : Optional[str] = None, ",
8888
),
8989
(
9090
Operation(
@@ -103,7 +103,7 @@ def test_generate_body_param(test_openapi_operation, expected_result):
103103
),
104104
],
105105
),
106-
["test : TestModel", "test2 : Optional[str] = None"],
106+
"test : TestModel, test2 : Optional[str] = None, ",
107107
),
108108
(
109109
Operation(
@@ -131,7 +131,7 @@ def test_generate_body_param(test_openapi_operation, expected_result):
131131
}
132132
),
133133
),
134-
["test : TestModel", "test2 : str", "data : TestModel"],
134+
"test : TestModel, test2 : str, data : TestModel, ",
135135
),
136136
(
137137
Operation(
@@ -159,7 +159,7 @@ def test_generate_body_param(test_openapi_operation, expected_result):
159159
}
160160
),
161161
),
162-
["test : TestModel", "test2 : str", "data : TestModel"],
162+
"test : TestModel, test2 : str, data : TestModel, ",
163163
),
164164
(
165165
Operation(
@@ -185,7 +185,7 @@ def test_generate_body_param(test_openapi_operation, expected_result):
185185
}
186186
),
187187
),
188-
["test : TestModel", "test2 : str", "data : str"],
188+
"test : TestModel, test2 : str, data : str, ",
189189
),
190190
(
191191
Operation(

0 commit comments

Comments
 (0)