@@ -2611,11 +2611,15 @@ module.exports = {
2611
2611
matchedPath ,
2612
2612
matchedPathJsonPath ,
2613
2613
schemaPathItems = schema . paths ,
2614
+ pathToMatchServer ,
2614
2615
filteredPathItemsArray = [ ] ;
2615
2616
2616
2617
// Return no matches for invalid url (if unable to decode parsed url)
2617
2618
try {
2618
2619
pathToMatch = decodeURI ( parsedUrl . pathname ) ;
2620
+ if ( ! _ . isNil ( parsedUrl . hash ) ) {
2621
+ pathToMatch += parsedUrl . hash ;
2622
+ }
2619
2623
}
2620
2624
catch ( e ) {
2621
2625
console . warn (
@@ -2654,9 +2658,16 @@ module.exports = {
2654
2658
}
2655
2659
return accumulator ;
2656
2660
} , [ ] ) ;
2657
-
2661
+ let schemaMatchResult = { match : false } ;
2658
2662
// check if path and pathToMatch match (non-null)
2659
- let schemaMatchResult = this . getPostmanUrlSchemaMatchScore ( pathToMatch , path , options ) ;
2663
+ // check in explicit (local defined) servers
2664
+ if ( pathItemObject [ method . toLowerCase ( ) ] . servers ) {
2665
+ pathToMatchServer = this . handleExplicitServersPathToMatch ( pathToMatch , path ) ;
2666
+ schemaMatchResult = this . getPostmanUrlSchemaMatchScore ( pathToMatchServer , path , options ) ;
2667
+ }
2668
+ else {
2669
+ schemaMatchResult = this . getPostmanUrlSchemaMatchScore ( pathToMatch , path , options ) ;
2670
+ }
2660
2671
if ( ! schemaMatchResult . match ) {
2661
2672
// there was no reasonable match b/w the postman path and this schema path
2662
2673
return true ;
@@ -4465,6 +4476,32 @@ module.exports = {
4465
4476
} ) ;
4466
4477
} ,
4467
4478
4479
+ /**
4480
+ * Takes in the postman path and the schema path
4481
+ * takes from the path the number of segments present in the schema path
4482
+ * and returns the last segments from the path to match in an string format
4483
+ *
4484
+ * @param {string } pathToMatch - parsed path (exclude host and params) from the Postman request
4485
+ * @param {string } schemaPath - schema path from the OAS spec (exclude servers object)
4486
+ * @returns {string } only the selected segments from the pathToMatch
4487
+ */
4488
+ handleExplicitServersPathToMatch : function ( pathToMatch , schemaPath ) {
4489
+ let pathTMatchSlice ,
4490
+ schemaPathArr = _ . reject ( schemaPath . split ( '/' ) , ( segment ) => {
4491
+ return segment === '' ;
4492
+ } ) ,
4493
+ schemaPathSegments = schemaPathArr . length ,
4494
+ pathToMatchArr = _ . reject ( pathToMatch . split ( '/' ) , ( segment ) => {
4495
+ return segment === '' ;
4496
+ } ) ,
4497
+ pathToMatchSegments = pathToMatchArr . length ;
4498
+ if ( pathToMatchSegments < schemaPathSegments ) {
4499
+ return pathToMatch ;
4500
+ }
4501
+ pathTMatchSlice = pathToMatchArr . slice ( pathToMatchArr . length - schemaPathSegments , pathToMatchArr . length ) ;
4502
+ return pathTMatchSlice . join ( '/' ) ;
4503
+ } ,
4504
+
4468
4505
/**
4469
4506
* @param {string } postmanPath - parsed path (exclude host and params) from the Postman request
4470
4507
* @param {string } schemaPath - schema path from the OAS spec (exclude servers object)
0 commit comments