This repository has been archived by the owner on Dec 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: var replacer first implementation
- Loading branch information
Showing
7 changed files
with
439 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const Mustache = require('mustache') | ||
|
||
/** | ||
* Rewrite escapedValue() function to not delete undefined variables | ||
*/ | ||
Mustache.Writer.prototype.escapedValue = function escapedValue (token, context, config) { | ||
const value = context.lookup(token[1]) || `{{${token[1]}}}` | ||
return String(value) | ||
} | ||
|
||
function replacePostmanVariables (collectionString) { | ||
const postmanJson = JSON.parse(collectionString) | ||
const { variable } = postmanJson | ||
const context = variable.reduce((obj, { key, value }) => { | ||
obj[key] = value | ||
return obj | ||
}, {}) | ||
return Mustache.render(collectionString, context) | ||
} | ||
|
||
module.exports = replacePostmanVariables |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
{ | ||
"info": { | ||
"_postman_id": "747abd37-e913-4bf8-a7e7-01730737b973", | ||
"name": "Variables", | ||
"description": "Mi super test collection from postman", | ||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" | ||
}, | ||
"item": [ | ||
{ | ||
"name": "Create new User", | ||
"request": { | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\n \"example\": \"field\",\n \"other\": {\n \"data1\": \"yes\",\n \"service\": \"{{service}}\"\n }\n}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "{{server}}/users", | ||
"host": [ | ||
"{{server}}" | ||
], | ||
"path": [ | ||
"users" | ||
] | ||
}, | ||
"description": "Create a new user into your amazing API" | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "Create Post", | ||
"request": { | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "formdata", | ||
"formdata": [ | ||
{ | ||
"key": "company", | ||
"value": "{{company}}", | ||
"type": "text" | ||
}, | ||
{ | ||
"key": "text", | ||
"value": "This is an example text", | ||
"type": "text" | ||
}, | ||
{ | ||
"key": "auditor", | ||
"value": "{{auditor}}", | ||
"type": "text" | ||
} | ||
], | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "{{server}}/post", | ||
"host": [ | ||
"{{server}}" | ||
], | ||
"path": [ | ||
"post" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "Consult User data", | ||
"request": { | ||
"method": "GET", | ||
"header": [ | ||
{ | ||
"key": "X-Company", | ||
"value": "{{company}}", | ||
"type": "text" | ||
}, | ||
{ | ||
"key": "", | ||
"value": "", | ||
"type": "text", | ||
"disabled": true | ||
} | ||
], | ||
"url": { | ||
"raw": "{{server}}/users/{{user_id}}?company={{company}}", | ||
"host": [ | ||
"{{server}}" | ||
], | ||
"path": [ | ||
"users", | ||
"{{user_id}}" | ||
], | ||
"query": [ | ||
{ | ||
"key": "company", | ||
"value": "{{company}}" | ||
} | ||
] | ||
}, | ||
"description": "Get one user instance data" | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "Get a list of user", | ||
"request": { | ||
"method": "GET", | ||
"header": [], | ||
"url": { | ||
"raw": "{{server}}/users?size={{page-size}}&company={{company}}", | ||
"host": [ | ||
"{{server}}" | ||
], | ||
"path": [ | ||
"users" | ||
], | ||
"query": [ | ||
{ | ||
"key": "size", | ||
"value": "{{page-size}}", | ||
"description": "size of the list" | ||
}, | ||
{ | ||
"key": "company", | ||
"value": "{{company}}", | ||
"description": "company for filter users" | ||
} | ||
] | ||
}, | ||
"description": "Get a list of users" | ||
}, | ||
"response": [] | ||
} | ||
], | ||
"event": [ | ||
{ | ||
"listen": "prerequest", | ||
"script": { | ||
"type": "text/javascript", | ||
"exec": [ | ||
"" | ||
] | ||
} | ||
}, | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"type": "text/javascript", | ||
"exec": [ | ||
"" | ||
] | ||
} | ||
} | ||
], | ||
"variable": [ | ||
{ | ||
"key": "version", | ||
"value": "1.1.0" | ||
}, | ||
{ | ||
"key": "server", | ||
"value": "https://api.io" | ||
}, | ||
{ | ||
"key": "page-size", | ||
"value": "10" | ||
}, | ||
{ | ||
"key": "company", | ||
"value": "ServicesLTD" | ||
}, | ||
{ | ||
"key": "auditor", | ||
"value": "IHA" | ||
}, | ||
{ | ||
"key": "service", | ||
"value": "s23434" | ||
} | ||
] | ||
} |
Oops, something went wrong.