Skip to content

Commit b5fc4d1

Browse files
Merge pull request #54 from MarcoMuellner/51-openapi-python-generator-exits-prematurely-with-exception-operationid-is-not-defined-for-get
feat: Using operation and path name for operation id if no operation …
2 parents f79bae1 + 24a9504 commit b5fc4d1

File tree

4 files changed

+517
-4
lines changed

4 files changed

+517
-4
lines changed

src/openapi_python_generator/language_converters/python/service_generator.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Dict
33
from typing import List
44
from typing import Literal
5+
from typing import Optional
56
from typing import Tuple
67
from typing import Union
78

@@ -154,11 +155,17 @@ def _generate_params_from_content(content: Union[Reference, Schema]):
154155
return params + default_params
155156

156157

157-
def generate_operation_id(operation: Operation, http_op: str) -> str:
158+
def generate_operation_id(
159+
operation: Operation, http_op: str, path_name: Optional[str] = None
160+
) -> str:
158161
if operation.operationId is not None:
159162
return common.normalize_symbol(operation.operationId)
163+
elif path_name is not None:
164+
return common.normalize_symbol(f"{http_op}_{path_name}")
160165
else:
161-
raise Exception(f"OperationId is not defined for {http_op}") # pragma: no cover
166+
raise Exception(
167+
f"OperationId is not defined for {http_op} of path_name {path_name} --> {operation.summary}"
168+
) # pragma: no cover
162169

163170

164171
def _generate_params(
@@ -267,7 +274,7 @@ def generate_service_operation(
267274
op: Operation, path_name: str, async_type: bool
268275
) -> ServiceOperation:
269276
params = generate_params(op)
270-
operation_id = generate_operation_id(op, http_operation)
277+
operation_id = generate_operation_id(op, http_operation, path_name)
271278
query_params = generate_query_params(op)
272279
header_params = generate_header_params(op)
273280
return_type = generate_return_type(op)

tests/regression/test_issue_17.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22
from click.testing import CliRunner
33

4-
from openapi_python_generator.__main__ import main
54
from openapi_python_generator.common import HTTPLibrary
65
from openapi_python_generator.generate_data import generate_data
76
from tests.conftest import test_data_folder

tests/regression/test_issue_51.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import pytest
2+
from click.testing import CliRunner
3+
4+
from openapi_python_generator.common import HTTPLibrary
5+
from openapi_python_generator.generate_data import generate_data
6+
from tests.conftest import test_data_folder
7+
from tests.conftest import test_result_path
8+
9+
10+
@pytest.fixture
11+
def runner() -> CliRunner:
12+
"""Fixture for invoking command-line interfaces."""
13+
return CliRunner()
14+
15+
16+
@pytest.mark.parametrize(
17+
"library",
18+
[HTTPLibrary.httpx, HTTPLibrary.aiohttp, HTTPLibrary.requests],
19+
)
20+
def test_issue_11(runner: CliRunner, model_data_with_cleanup, library) -> None:
21+
"""
22+
https://github.com/MarcoMuellner/openapi-python-generator/issues/7
23+
"""
24+
assert (
25+
generate_data(test_data_folder / "issue_51.json", test_result_path, library)
26+
is None
27+
)

0 commit comments

Comments
 (0)