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

Conversation

RobbeSneyders
Copy link
Member

When the same operation was being resolved multiple times (eg. in different middleware), a new mock operation_id was generated every time, breaking routing for these mocked operations.

connexion.middleware.abstract.MissingOperation: Encountered unknown operation_id

This PR keeps track of the generated operation_ids and returns a previously generated id if the same operation is resolved.

CC: @julienschuermans

@coveralls
Copy link

Coverage Status

coverage: 94.39% (-0.02%) from 94.408%
when pulling 4803cf1 on bugfix/mock-operation-id
into 3450a60 on main.

Copy link
Member

@Ruwann Ruwann left a comment

Choose a reason for hiding this comment

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

Thanks, left a minor (optional) comment.

Can we add a test for this? Doubting whether it is overkill to do this for the benefit we'll get from a test for the mock resolver but if only for the resolver, a test should be that hard to add?

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?

@RobbeSneyders
Copy link
Member Author

Looking into adding a test makes me doubt if this is the right way to resolve this issue.

We are creating a new SwaggerOperation / OpenAPIOperation in every middleware (code), which might not be ideal. I'll check if we could handle this differently when I find the time and update this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants