mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
[Issue#18] - Consistent parsing of all template variables
This commit is contained in:
23
lib/util.js
23
lib/util.js
@@ -89,23 +89,14 @@ module.exports = {
|
||||
* @returns {string} string after replacing /{pet}/ with /:pet/
|
||||
*/
|
||||
fixPathVariablesInUrl: function (url) {
|
||||
/*
|
||||
The first .replace:
|
||||
Handling path templating in request url if any
|
||||
only replace /{pet}<end-of-string> or /{pet}/
|
||||
https://regex101.com/r/Yqm2As/2
|
||||
|
||||
The second .replace:
|
||||
we also need to replace the scheme variables
|
||||
{scheme}://api.com
|
||||
needs to become
|
||||
{{scheme}}://api.com
|
||||
and scheme is already set as a collection variable
|
||||
*/
|
||||
|
||||
// All complicated logic removed
|
||||
// This simply replaces all instances of {text} with {{text}}
|
||||
// text cannot have any of these 3 chars: /{}
|
||||
// and {text} cannot be followed by a }
|
||||
// {{text}} will not be converted
|
||||
// https://regex101.com/r/9N1520/1
|
||||
return url
|
||||
.replace(/\/\{([a-zA-Z0-9\-\_]+)\}(\/|$)/g, '/:$1$2')
|
||||
.replace(/^\{([a-zA-Z0-9\-\_]+)\}\:/, '{{$1}}:');
|
||||
.replace(/(\{[^\/\{\}]+\})(?!\})/g, '{$1}');
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user