Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Common functions required for app and documenter (#15)
* Common repo functions for documenter integration * Added postman-collection in dependencies * Updated common functions to incorporate pre-package script * Updated pre-package.js, changed syntax_mode for golang, powershell, ruby and remove require statement from functions * Included homepage urls for respective codegens and added it to the languages.js pre-package script to be accessible by common functions * Updated repository test
- Loading branch information
Showing
with
598 additions
and 20 deletions.
- +1 −1 .eslintrc
- +74 −0 .npmignore
- 0 codegens/.gitkeep
- +1 −1 codegens/curl/package.json
- +2 −2 codegens/golang/package.json
- +1 −0 codegens/js-fetch/package.json
- +1 −1 codegens/js-jquery/package.json
- +1 −0 codegens/nodejs-native/package.json
- +1 −1 codegens/php-curl/package.json
- +4 −4 codegens/powershell-restmethod/package.json
- +1 −1 codegens/python-requests/package.json
- +3 −2 codegens/ruby/package.json
- +1 −1 codegens/swift/package.json
- +1 −1 index.js
- +21 −0 lib/assets/languageLabels.json
- +118 −0 lib/index.js
- +5 −0 npm/deepinstall.sh
- +40 −0 npm/pre-package.js
- +314 −0 package-lock.json
- +7 −4 package.json
- +1 −1 test/system/repository.test.js
@@ -0,0 +1,74 @@ | ||
### NPM Specific: Disregard recursive project files | ||
### =============================================== | ||
/.editorconfig | ||
/.gitmodules | ||
/test | ||
|
||
### Borrowed from .gitignore | ||
### ======================== | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Prevent IDE stuff | ||
.idea | ||
.vscode | ||
*.sublime-* | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
.coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
out/ |
Empty file.
@@ -1 +1 @@ | ||
|
||
module.exports = require('./lib'); |
@@ -0,0 +1,21 @@ | ||
{ | ||
"bash": "bash", | ||
"curl": "cURL", | ||
"javascript": "JavaScript", | ||
"http": "HTTP", | ||
"python": "Python", | ||
"ruby": "Ruby", | ||
"java": "Java", | ||
"c": "C", | ||
"php": "PHP", | ||
"objective-c": "Objective-C", | ||
"perl": "Perl", | ||
"go": "Go", | ||
"swift": "Swift", | ||
"typescript": "TypeScript", | ||
"powershell": "Powershell", | ||
"csharp": "C#", | ||
"nodejs": "NodeJs", | ||
"ocaml": "OCaml", | ||
"shell": "Shell" | ||
} |
@@ -0,0 +1,118 @@ | ||
var sdk = require('postman-collection'), | ||
labelList = require('./assets/languageLabels.json'), | ||
languageMap = require('./assets/languages.js'); | ||
|
||
module.exports = { | ||
/** | ||
* Gets the options specific to a given language. | ||
* | ||
* @param {Object} language - language key provided by getLanguageList function | ||
* @param {Array} variant - variant key provided by getLanguageList function | ||
* @param {Function} callback - callback function with arguments (error, object) | ||
*/ | ||
getOptions (language, variant, callback) { | ||
var validCodegen = languageMap.filter((codegen) => { | ||
var lang = codegen.lang.trim(), | ||
currentVariant = codegen.variant.trim(); | ||
return language === lang.toLowerCase() && variant.toLowerCase() === currentVariant.toLowerCase(); | ||
}); | ||
|
||
validCodegen.forEach((codegen) => { | ||
main = codegen.main; | ||
if (typeof main.getOptions !== 'function') { | ||
return callback('Codegen~getOptions: getOptions is not a function'); | ||
} | ||
if (!main.getOptions) { | ||
return callback('Codegen~convert: Could not find condegen corresponding to provided language, variant pair'); | ||
} | ||
|
||
return callback(null, main.getOptions()); | ||
}); | ||
}, | ||
|
||
/** | ||
* Returns an object of supported languages | ||
* | ||
*/ | ||
getLanguageList () { | ||
var langMap = {}, | ||
supportedLanguages = []; | ||
languageMap.forEach((codegen) => { | ||
var lang = codegen.lang.trim(), | ||
syntax_mode = codegen.syntax_mode.trim(), | ||
variant = codegen.variant.trim(); | ||
lang = lang.toLowerCase(); | ||
if (!langMap[lang]) { | ||
langMap[lang] = { | ||
key: lang, | ||
label: labelList[lang] ? labelList[lang] : lang, | ||
syntax_mode: syntax_mode.toLowerCase(), | ||
variants: [ | ||
{ | ||
key: variant | ||
} | ||
] | ||
}; | ||
} | ||
else { | ||
langMap[lang].variants.push({ | ||
key: variant | ||
}); | ||
} | ||
}); | ||
|
||
supportedLanguages = Object.keys(langMap).map(function (lang) { | ||
return langMap[lang]; | ||
}); | ||
|
||
return supportedLanguages; | ||
}, | ||
|
||
/** | ||
* Converts a request to a preferred language snippet | ||
* | ||
* @param {Object} language - language key provided by getLanguageList function | ||
* @param {Array} variant - variant key provided by getLanguageList function | ||
* @param {String} request - valid postman request | ||
* @param {Object} [options] - contains convert level options | ||
* @param {Number} [options.indentType] - indentation based on tab or spaces | ||
* @param {Number} [options.indentCount] - count/frequency of indentType | ||
* @param {Number} [options.requestTimeout] : time in milli-seconds after which request will bail out | ||
* @param {Boolean} [options.requestBodyTrim] : whether to trim request body fields | ||
* @param {Boolean} [options.addCacheHeader] : whether to add cache-control header to postman SDK-request | ||
* @param {Boolean} [options.followRedirect] : whether to allow redirects of a request | ||
* @param {Function} callback - callback function with arguments (error, string) | ||
*/ | ||
convert (language, variant, request, options, callback) { | ||
var convert, main; | ||
|
||
if (!sdk.Request.isRequest(request)) { | ||
return callback('Codegen~convert: Invalid request'); | ||
} | ||
|
||
languageMap.forEach((codegen) => { | ||
var lang = codegen.lang.trim(), | ||
currentVariant = codegen.variant.trim(); | ||
if (language.toLowerCase() === lang.toLowerCase() && variant.toLowerCase() === currentVariant.toLowerCase()) { | ||
main = codegen.main; | ||
convert = main.convert; | ||
|
||
if (typeof convert !== 'function') { | ||
return callback('Codegen~convert: Convert is not a function'); | ||
} | ||
} | ||
}); | ||
if (!convert) { | ||
return callback('Codegen~convert: Could not find condegen corresponding to provided language, variant pair'); | ||
} | ||
|
||
|
||
convert(request, options, function (err, snippet) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
|
||
return callback(null, snippet); | ||
}); | ||
} | ||
}; |
Oops, something went wrong.