Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/oih-gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ async function oihGen() {
connectorName: options.name,
outputDir: options.output,
snapshot: options.snapshot,
rateLimit: options.rateLimit,
paginationConfig: {
pageTokenOption: {
fieldName: options.paginationTokenFieldName,
Expand Down
4 changes: 3 additions & 1 deletion lib/do-generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const generate = require("./generate");
* @param {string} paginationConfig.strategy.nextCursorPath
* @param {object} paginationConfig.pageTokenOption
* @param {string} paginationConfig.pageTokenOption.fieldName
* @param {number} rateLimit
* @returns {Promise<*>}
*/
module.exports = async function doGenerate({ swaggerUrl, outputDir, connectorName, snapshot, paginationConfig }) {
module.exports = async function doGenerate({ swaggerUrl, outputDir, connectorName, snapshot, paginationConfig, rateLimit }) {
const downloadedSpecFile = path.join(outputDir, "openapi-original.json");
const validatedSpecFile = path.join(outputDir, "openapi-validated.json");
const generatePath = path.join(outputDir, connectorName);
Expand Down Expand Up @@ -46,6 +47,7 @@ module.exports = async function doGenerate({ swaggerUrl, outputDir, connectorNam
swaggerUrl: swaggerUrl,
snapshot: snapshot || "",
paginationConfig,
rateLimit: rateLimit || -1
});

console.log("\x1b[32m", "Successfully generated. Connector has been saved in output directory:", generatePath);
Expand Down
3 changes: 2 additions & 1 deletion lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = async function generate({
snapshot,
paginationConfig,
suffixServiceNameToTitle = false,
rateLimit = -1,
}) {
let api = await SwaggerParser.parse(inputFile);
if (!api.components) {
Expand All @@ -51,7 +52,7 @@ module.exports = async function generate({
fse.removeSync(libDir);
}

let componentJson = await getComponentJson(apiTitle, api, swaggerUrl, this);
let componentJson = await getComponentJson(apiTitle, api, swaggerUrl, rateLimit, this);
let existingNames = {};

// generate actions
Expand Down
5 changes: 3 additions & 2 deletions lib/utils/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async function output(filename, text, data, outputDir) {
if (data) {
text = _.template(text, {})(data);
} else if (typeof text !== "string") {
if(text.additionalProperties){
if (text.additionalProperties) {
text.properties = Object.assign({}, text.properties, text.additionalProperties);
delete text.additionalProperties;
}
Expand All @@ -80,14 +80,15 @@ async function output(filename, text, data, outputDir) {
//console.log('Writing file %s', filename);
return await fse.outputFile(path.join(outputDir, filename), text);
}
async function getComponentJson(apiTitle, api, swaggerUrl) {
async function getComponentJson(apiTitle, api, swaggerUrl, rateLimit) {
const textDescription = toText(api.info.description);

const componentJson = Object.assign(JSON.parse(templates.componentTemplate), {
title: apiTitle,
description: textDescription,
docsUrl: (api.externalDocs && api.externalDocs.url) || "",
url: swaggerUrl,
rateLimit: parseInt(rateLimit),
});

await addCredentials(componentJson, api);
Expand Down
3 changes: 2 additions & 1 deletion templates/component.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"description": "",
"docsUrl": "",
"url": "",
"rateLimit": -1,
"envVars": {},
"credentials": {},
"triggers": {},
"actions": {}
}
}
2 changes: 1 addition & 1 deletion templates/lib/actions/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async function processAction(msg, cfg, snapshot, incomingMessageHeaders, tokenDa
const resp = await executeCall.call(this, callParams);

// Wait for rate limit if specified
const rateLimit = cfg.nodeSettings && cfg.nodeSettings.rateLimit ? parseInt(cfg.nodeSettings.rateLimit) : 6100;
const rateLimit = cfg.nodeSettings && cfg.nodeSettings.rateLimit ? parseInt(cfg.nodeSettings.rateLimit) : (Number.isInteger(componentJson.rateLimit) ? componentJson.rateLimit : 0);
if (rateLimit > 0) {
this.logger.info(`Waiting for rate limit: ${rateLimit} ms`);
await new Promise(resolve => setTimeout(resolve, rateLimit));
Expand Down
2 changes: 1 addition & 1 deletion templates/lib/triggers/trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async function processTrigger(msg, cfg, snapshot, incomingMessageHeaders, tokenD
const { body, headers } = await executeCall.call(this, callParams);

// Wait for rate limit if specified
const rateLimit = cfg.nodeSettings && cfg.nodeSettings.rateLimit ? parseInt(cfg.nodeSettings.rateLimit) : 6100;
const rateLimit = cfg.nodeSettings && cfg.nodeSettings.rateLimit ? parseInt(cfg.nodeSettings.rateLimit) : (Number.isInteger(componentJson.rateLimit) ? componentJson.rateLimit : 0);
if (rateLimit > 0) {
this.logger.info(`Waiting for rate limit: ${rateLimit} ms`);
await new Promise(resolve => setTimeout(resolve, rateLimit));
Expand Down
2 changes: 1 addition & 1 deletion templates/lib/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const executeSwaggerCall = async function (callParams) {
retries: 5,
factor: 2,
minTimeout: 5000,
maxTimeout: 6000,
maxTimeout: 20000,
randomize: true,
});
return new Promise((resolve, reject) => {
Expand Down