-
Notifications
You must be signed in to change notification settings - Fork 350
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
fix: mock issue resolve for similar templated requests #2564
Conversation
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "@stoplight/prism-http", | |||
"version": "5.8.2", | |||
"version": "5.8.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this required? just check if it gets incremented bu build system during release or deployment ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. we need to change the version as per the change.
if (endpointParts[i] === requestParts[i]) { | ||
score++; | ||
} else if (isTemplated(endpointParts[i])) { | ||
score += 0.5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the purpose of this score += 0.5; ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added score to differentiate match weightage. When templated path is found, 0.5 score is added to it and if path is not templated and it is matching with request, then score is incremented by 1. So non-template path will have more weightage compare to templated path while performing sorting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes are good to go ahead
Addresses STOP-448
Summary
We observe that the issue is occurring in mock server when OAS is having similar templated requests as below example. Request was getting mapped with wrong endpoint and mock server was returning 400 error code.
Consider following API endpoints defined in project spec.
we can find two paths here -
If we call search Api from mock server our request will be encoded to "/SMARTBEAR/payments/search". here "SMARTBEAR" is initgPtyIdOrgId. And if call is made to payment API, request will be encoded to - SMARTBEAR/payments/paytm123. Here SMARTBEAR is initgPtyIdOrgId and paytm123 is paymentId. But if you compare the both requests looks similar.
There is matchPath function in prism-http which is handling request and endpoint mapping functionality and for above scenario it is returning two endpoint objects for search API. Ideally it should return single object array. And make-payment API is placed before search Api in spec, make-Api object will be the first item in array and matchPath is using first item from array to call mock Api.
To solve this, I created the sorting function in http-spec where all these endpoints will be sorted on the basis their match with request path. In case we get multiple matched endpoints for any request, this sorting will make sure that first endpoint in array is close match to request.
Checklist
Screenshots
If applicable, add screenshots or gifs to help demonstrate the changes. If not applicable, remove this screenshots
section before creating the PR.
Additional context
Add any other context about the pull request here. Remove this section if there is no additional context.