Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Phara0h committed Feb 5, 2021
1 parent 31a3944 commit ab5c0ae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test.js
node_modules
.DS_Store
package-lock.json
46 changes: 27 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ var getVars = function (url, body, headers = [])

var urlVars = Array.from(url.variable.map(v => v.key.length > 0 ? v.key : null)).filter(v=>v);
if(urlVars.length > 0) {
//console.log(urlVars)
vars = [...vars, ...urlVars];
}

Expand Down Expand Up @@ -213,7 +214,7 @@ if(urlVars.length > 0) {
`
* @example
* body
* \`\`\`${body.options.raw.language}
* \`\`\`${body.options ? body.options.raw.language : ''}
* `
docs += body.raw.replace(/\n/g, '\n * ');
docs += '\n * ```';
Expand All @@ -236,7 +237,7 @@ var convertToOptions = function (request)
var body = request.body;
if(body) {
if(body.mode == 'raw') {
body = `body${body.options.raw.language == 'json' ? ',json:true' : ''}`
body = `body${body.options && body.options.raw.language == 'json' ? ',json:true' : ''}`
}
else if(body.mode == 'urlencoded') {
body = `form: {
Expand All @@ -261,13 +262,13 @@ var convertToOptions = function (request)
var setMethodName = function (n)
{
var mn = '' + n
return toCamel(mn.replace(/:/g, '').replace(/[ \/-]/g, '_').toLowerCase())
return toCamel(mn.replace(/[\:\'\)\(]/g, '').replace(/[ \/\-]/g, '_').toLowerCase())
}

var setClassName = function (n, parent)
{
var cn = (parent && parent != parentName ? parent+' ' : '') + n.charAt(0).toUpperCase() + n.slice(1);
var name = toCamel(cn.replace(/ /g, '_').toLowerCase())
var name = toCamel(cn.replace(/[\'\)\(]/g, '').replace(/ /g, '_').toLowerCase())
return name.charAt(0).toUpperCase() + name.slice(1);
}
const toCamel = (s) =>
Expand Down Expand Up @@ -339,21 +340,28 @@ class ${setClassName(name, parent)} {

if (!item[i].item)
{
getPathObject += `${setMethodName(item[i].name).toLowerCase()}:'${item[i].request.url.path.join('/')}',`
//console.log(item[i])
classFunctions += `
${getDocs(item[i].name,item[i].request.description ? item[i].request.description.content : '', item[i].request.url, item[i].request.body, item[i].request.header || [])}
static async ${setMethodName(item[i].name)}(${getVars(item[i].request.url, item[i].request.body, item[i].request.header || [])}) {
var options = ${convertToOptions(item[i].request)};
if(defaultOpts) {
options = Object.assign(options, defaultOpts);
}
if(opts) {
options = Object.assign(options, opts);
}
return await fasq.request(options)
}
`;
try {
getPathObject += `${setMethodName(item[i].name).toLowerCase()}:'${item[i].request.url.path.join('/')}',`
//console.log(item[i])
classFunctions += `
${getDocs(item[i].name,item[i].request.description ? item[i].request.description.content : '', item[i].request.url, item[i].request.body, item[i].request.header || [])}
static async ${setMethodName(item[i].name)}(${getVars(item[i].request.url, item[i].request.body, item[i].request.header || [])}) {
var options = ${convertToOptions(item[i].request)};
if(defaultOpts) {
options = Object.assign(options, defaultOpts);
}
if(opts) {
options = Object.assign(options, opts);
}
return await fasq.request(options)
}
`;
} catch (e) {

} finally {

}



}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"auto-changelog": "^1.16.1",
"fasquest": "^3.0.0",
"fasquest": "^3.0.2",
"postman-collection": "^3.5.1",
"prettier": "^2.0.5"
}
Expand Down

0 comments on commit ab5c0ae

Please sign in to comment.