forked from wcandillon/swagger-js-codegen
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
lib/expose.js | ||
lib/formatter.js | ||
lib/querier.js | ||
lib/splitter.js | ||
zz/ |
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,69 @@ | ||
const _ = require('lodash'); | ||
|
||
const specialKeys = ['Add', 'Create', 'Delete', 'Disable', 'Update']; | ||
|
||
/** | ||
* Get the required properties for the query | ||
* @param params {array} - array of the method parameters | ||
* @returns {object} - { parameters: {string}, questions: {string} } | ||
*/ | ||
function getProperties(params) { | ||
const parameters = []; | ||
const questions = []; | ||
params.forEach((param) => { | ||
if (param.in && param.in === 'path' || param.in === 'query') { | ||
parameters.push(param.name); | ||
} | ||
if (param.in && param.in === 'body') { | ||
const { '$ref': ref } = param.schema || {}; | ||
if (ref) { | ||
parameters.push(ref.split('/').slice(-1)[0]); | ||
} | ||
} | ||
questions.push('?'); | ||
}); | ||
return { | ||
parameters: parameters.join(', '), | ||
questions: questions.join(', '), | ||
} | ||
} | ||
|
||
/** | ||
* Create SQL query for the method | ||
* @param data {object} - object with definitions & methods | ||
* @returns {*} | ||
*/ | ||
function querier(data) { | ||
try { | ||
const mutable = _.cloneDeep(data); | ||
const { methods, definitions } = mutable; | ||
|
||
if (!(methods && methods.length > 0 && definitions && definitions.length > 0)) { | ||
return new Error('Methods and definitions should not be empty!'); | ||
} | ||
|
||
methods.forEach((method, m) => { | ||
let special = false; | ||
specialKeys.forEach((key) => { | ||
if (method.methodName.includes(key)) { | ||
special = true; | ||
} | ||
}); | ||
|
||
if (!special) { | ||
const { parameters, questions } = getProperties(method.parameters); | ||
mutable.methods[m].query = { | ||
content: `const results = await dal.query("SELECT FN_${method.methodName}(${questions})", [${parameters}], { redis: true });`, | ||
}; | ||
} else { | ||
|
||
} | ||
}); | ||
|
||
return mutable; | ||
} catch (err) { | ||
throw new Error(err.message || err); | ||
} | ||
} | ||
|
||
module.exports = querier; |
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