Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Dict
from typing import List
from typing import Literal
from typing import Optional
from typing import Tuple
from typing import Union

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


def generate_operation_id(operation: Operation, http_op: str) -> str:
def generate_operation_id(
operation: Operation, http_op: str, path_name: Optional[str] = None
) -> str:
if operation.operationId is not None:
return common.normalize_symbol(operation.operationId)
elif path_name is not None:
return common.normalize_symbol(f"{http_op}_{path_name}")
else:
raise Exception(f"OperationId is not defined for {http_op}") # pragma: no cover
raise Exception(
f"OperationId is not defined for {http_op} of path_name {path_name} --> {operation.summary}"
) # pragma: no cover


def _generate_params(
Expand Down Expand Up @@ -267,7 +274,7 @@ def generate_service_operation(
op: Operation, path_name: str, async_type: bool
) -> ServiceOperation:
params = generate_params(op)
operation_id = generate_operation_id(op, http_operation)
operation_id = generate_operation_id(op, http_operation, path_name)
query_params = generate_query_params(op)
header_params = generate_header_params(op)
return_type = generate_return_type(op)
Expand Down
1 change: 0 additions & 1 deletion tests/regression/test_issue_17.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
from click.testing import CliRunner

from openapi_python_generator.__main__ import main
from openapi_python_generator.common import HTTPLibrary
from openapi_python_generator.generate_data import generate_data
from tests.conftest import test_data_folder
Expand Down
27 changes: 27 additions & 0 deletions tests/regression/test_issue_51.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest
from click.testing import CliRunner

from openapi_python_generator.common import HTTPLibrary
from openapi_python_generator.generate_data import generate_data
from tests.conftest import test_data_folder
from tests.conftest import test_result_path


@pytest.fixture
def runner() -> CliRunner:
"""Fixture for invoking command-line interfaces."""
return CliRunner()


@pytest.mark.parametrize(
"library",
[HTTPLibrary.httpx, HTTPLibrary.aiohttp, HTTPLibrary.requests],
)
def test_issue_11(runner: CliRunner, model_data_with_cleanup, library) -> None:
"""
https://github.com/MarcoMuellner/openapi-python-generator/issues/7
"""
assert (
generate_data(test_data_folder / "issue_51.json", test_result_path, library)
is None
)
Loading