Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't regenerate operation_id in MockResolver #1999

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions connexion/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MockResolver(Resolver):
def __init__(self, mock_all):
super().__init__()
self.mock_all = mock_all
self._resolved_operations = {}
self._operation_id_counter = 1

def resolve(self, operation):
Expand All @@ -23,10 +24,15 @@ def resolve(self, operation):
:type operation: connexion.operations.AbstractOperation
"""
operation_id = self.resolve_operation_id(operation)
if not operation_id:
# just generate an unique operation ID
operation_id = f"mock-{self._operation_id_counter}"
self._operation_id_counter += 1
if operation_id is None:
operation_ref = operation.path + operation.method
if operation_ref in self._resolved_operations:
operation_id = self._resolved_operations.get(operation_ref)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this branch, we know it exists, so we should be able to directly use access by key?

else:
# just generate an unique operation ID
operation_id = f"mock-{self._operation_id_counter}"
self._resolved_operations[operation_ref] = operation_id
self._operation_id_counter += 1

mock_func = functools.partial(self.mock_operation, operation=operation)
if self.mock_all:
Expand Down
Loading