From 8797fc6bc112b508593a932f75c56722c8194f71 Mon Sep 17 00:00:00 2001 From: fiqare-secmotic Date: Fri, 15 Nov 2019 12:30:33 +0100 Subject: [PATCH 1/8] Rule 1: Variables should not be shadowed --- lib/bindings/AMQPBinding.js | 30 +++++++++++++-------------- lib/bindings/HTTPBindings.js | 12 +++++------ lib/bindings/MQTTBinding.js | 12 +++++------ lib/commonBindings.js | 20 +++++++++--------- lib/iotaUtils.js | 4 ++-- lib/transportSelector.js | 8 ++++---- lib/ulParser.js | 40 +++++++++++++++++++----------------- 7 files changed, 64 insertions(+), 62 deletions(-) diff --git a/lib/bindings/AMQPBinding.js b/lib/bindings/AMQPBinding.js index 850bed09..7c00918f 100644 --- a/lib/bindings/AMQPBinding.js +++ b/lib/bindings/AMQPBinding.js @@ -146,7 +146,7 @@ function start(callback) { config.getLogger().info(context, 'Starting AMQP binding'); - function createConnection(callback) { + function createConnection(callbackcreateConnection) { config.getLogger().info(context, 'creating connnection'); if (isConnecting) { return; @@ -161,12 +161,12 @@ function start(callback) { config.getLogger().error(context, err.message); if (numRetried <= retries) { numRetried++; - return setTimeout(createConnection, retryTime * 1000, callback); + return setTimeout(createConnection, retryTime * 1000, callbackcreateConnection); } } else { - conn.on('error', function(err) { - if (err.message !== 'Connection closing') { - config.getLogger().error(context, err.message); + conn.on('error', function(errConn) { + if (errConn.message !== 'Connection closing') { + config.getLogger().error(context, errConn.message); } }); conn.on('close', function() { @@ -183,15 +183,15 @@ function start(callback) { }); config.getLogger().info(context, 'connected'); amqpConn = conn; - if (callback) { - callback(); + if (callbackcreateConnection) { + callbackcreateConnection(); } } } ); } - function createChannel(callback) { + function createChannel(callbackcreateChannel) { config.getLogger().debug(context, 'channel creating'); amqpConn.createChannel(function(err, ch) { if (err) { @@ -199,27 +199,27 @@ function start(callback) { } config.getLogger().debug(context, 'channel created'); amqpChannel = ch; - callback(); + callbackcreateChannel(); }); } - function assertExchange(callback) { + function assertExchange(callbackassertExchange) { if (amqpChannel) { config.getLogger().debug(context, 'asserting exchange'); amqpChannel.assertExchange(exchange, 'topic', {}); config.getLogger().debug(context, 'exchange asserted'); - callback(); + callbackassertExchange(); } } - function assertQueue(callback) { + function assertQueue(callbackassertQueue) { config.getLogger().debug(context, 'asserting queues'); amqpChannel.assertQueue(queue, { exclusive: false }, function() { - amqpChannel.assertQueue(queue + '_commands', { exclusive: false }, callback); + amqpChannel.assertQueue(queue + '_commands', { exclusive: false }, callbackassertQueue); }); } - function createListener(queueObj, callback) { + function createListener(queueObj, callbackcreateListener) { config.getLogger().debug(context, 'creating listeners'); amqpChannel.bindQueue(queue, exchange, '.*.*.attrs.#'); amqpChannel.consume(queue, queueListener, { noAck: true }); @@ -228,7 +228,7 @@ function start(callback) { amqpChannel.bindQueue(queue + '_commands', exchange, '.*.*.cmdexe'); amqpChannel.consume(queue + '_commands', queueListener, { noAck: true }); config.getLogger().debug(context, 'subscribed to command queue'); - callback(); + callbackcreateListener(); } async.waterfall([createConnection, createChannel, assertExchange, assertQueue, createListener], function(error) { diff --git a/lib/bindings/HTTPBindings.js b/lib/bindings/HTTPBindings.js index 46a39ff2..99a72eee 100644 --- a/lib/bindings/HTTPBindings.js +++ b/lib/bindings/HTTPBindings.js @@ -339,8 +339,8 @@ function generateCommandExecution(apiKey, device, attribute) { */ function commandHandler(device, attributes, callback) { utils.getEffectiveApiKey(device.service, device.subservice, function(error, apiKey) { - async.series(attributes.map(generateCommandExecution.bind(null, apiKey, device)), function(error) { - if (error) { + async.series(attributes.map(generateCommandExecution.bind(null, apiKey, device)), function(errorAsync) { + if (errorAsync) { // prettier-ignore config.getLogger().error(context, 'COMMANDS-004: Error handling incoming command for device [%s]', device.id); @@ -348,11 +348,11 @@ function commandHandler(device, attributes, callback) { utils.updateCommand( apiKey, device, - error.message, - error.command, + errorAsync.message, + errorAsync.command, constants.COMMAND_STATUS_ERROR, - function(error) { - if (error) { + function(errorUpdateCommand) { + if (errorUpdateCommand) { // prettier-ignore config.getLogger().error( context, diff --git a/lib/bindings/MQTTBinding.js b/lib/bindings/MQTTBinding.js index 89012186..32a18350 100644 --- a/lib/bindings/MQTTBinding.js +++ b/lib/bindings/MQTTBinding.js @@ -58,19 +58,19 @@ function generateTopics(callback) { function recreateSubscriptions(callback) { config.getLogger().debug(context, 'Recreating global subscriptions'); - function subscribeToTopics(topics, callback) { + function subscribeToTopics(topics, callbackSubscribeToTopics) { config.getLogger().debug('Subscribing to topics: %j', topics); mqttClient.subscribe(topics, null, function(error) { if (error) { iotAgentLib.alarms.raise(constants.MQTTB_ALARM, error); config.getLogger().error(context, ' GLOBAL-001: Error subscribing to topics: %s', error); - callback(error); + callbackSubscribeToTopics(error); } else { iotAgentLib.alarms.release(constants.MQTTB_ALARM); config.getLogger().debug('Successfully subscribed to the following topics:\n%j\n', topics); - if (callback) { - callback(null); + if (callbackSubscribeToTopics) { + callbackSubscribeToTopics(null); } } }); @@ -83,10 +83,10 @@ function recreateSubscriptions(callback) { * Unsubscribe the MQTT Client for all the topics of all the devices of all the services. */ function unsubscribeAll(callback) { - function unsubscribeFromTopics(topics, callback) { + function unsubscribeFromTopics(topics, callbackUnsubscribeFromTopics) { mqttClient.unsubscribe(topics, null); - callback(); + callbackUnsubscribeFromTopics(); } async.waterfall([generateTopics, unsubscribeFromTopics], callback); diff --git a/lib/commonBindings.js b/lib/commonBindings.js index 60007162..0a45399c 100644 --- a/lib/commonBindings.js +++ b/lib/commonBindings.js @@ -250,20 +250,20 @@ function messageHandler(topic, message, protocol) { messageStr = message.toString(), parsedMessage; - function processMessageForDevice(device, apiKey, topicInformation) { + function processMessageForDevice(device, apiKeyProcessMessage, topicInformationProcessMessage) { iotAgentLib.alarms.release(constants.MQTTB_ALARM); if ( - topicInformation[3] === constants.CONFIGURATION_SUFIX && - topicInformation[4] === constants.CONFIGURATION_COMMAND_SUFIX && + topicInformationProcessMessage[3] === constants.CONFIGURATION_SUFIX && + topicInformationProcessMessage[4] === constants.CONFIGURATION_COMMAND_SUFIX && message ) { parsedMessage = ulParser.parseConfigurationRequest(messageStr); - manageConfigurationRequest(apiKey, deviceId, device, parsedMessage); - } else if (topicInformation[3] === constants.CONFIGURATION_COMMAND_UPDATE) { + manageConfigurationRequest(apiKeyProcessMessage, deviceId, device, parsedMessage); + } else if (topicInformationProcessMessage[3] === constants.CONFIGURATION_COMMAND_UPDATE) { var commandObj = ulParser.result(message.toString()); utils.updateCommand( - apiKey, + apiKeyProcessMessage, device, commandObj.result, commandObj.command, @@ -272,10 +272,10 @@ function messageHandler(topic, message, protocol) { config.getLogger().debug('Command updated with result: %s', error); } ); - } else if (topicInformation[4]) { - singleMeasure(apiKey, topicInformation[4], device, message); - } else if (topicInformation[3] === constants.MEASURES_SUFIX) { - multipleMeasures(apiKey, device, message.toString()); + } else if (topicInformationProcessMessage[4]) { + singleMeasure(apiKeyProcessMessage, topicInformationProcessMessage[4], device, message); + } else if (topicInformationProcessMessage[3] === constants.MEASURES_SUFIX) { + multipleMeasures(apiKeyProcessMessage, device, message.toString()); } else { config.getLogger().error( context, diff --git a/lib/iotaUtils.js b/lib/iotaUtils.js index 54735e95..4ed458b5 100644 --- a/lib/iotaUtils.js +++ b/lib/iotaUtils.js @@ -87,8 +87,8 @@ function findOrCreate(deviceId, transport, group, callback) { newDevice.timestamp = group.timestamp; } - iotAgentLib.register(newDevice, function(error, device) { - callback(error, device, group); + iotAgentLib.register(newDevice, function(errorRegister, deviceRegister) { + callback(errorRegister, deviceRegister, group); }); } else { callback(error); diff --git a/lib/transportSelector.js b/lib/transportSelector.js index 4d443a62..094244ca 100644 --- a/lib/transportSelector.js +++ b/lib/transportSelector.js @@ -35,8 +35,8 @@ var path = require('path'), * @param {Object} newConfig Configuration object to start the bindings */ function startTransportBindings(newConfig, callback) { - function invokeBinding(binding, callback) { - binding.start(callback); + function invokeBinding(binding, callbackInvokeBinding) { + binding.start(callbackInvokeBinding); } var bindings = fs.readdirSync(path.join(__dirname, './bindings')); @@ -52,8 +52,8 @@ function startTransportBindings(newConfig, callback) { * Stop all the transport protocol bindings of the agent. */ function stopTransportBindings(callback) { - function invokeBinding(binding, callback) { - binding.stop(callback); + function invokeBinding(binding, callbackInvokeBinding) { + binding.stop(callbackInvokeBinding); } async.map(transportBindings, invokeBinding, callback); diff --git a/lib/ulParser.js b/lib/ulParser.js index b58fba9c..1f72692c 100644 --- a/lib/ulParser.js +++ b/lib/ulParser.js @@ -124,7 +124,7 @@ function command(payload) { var fields = payload.split('|'), deviceData, dataSection, - result = {}; + results = {}; if (fields.length < 1 || fields[0].indexOf('@') < 0) { throw new errors.ParseError('Parsing command:' + payload); @@ -132,18 +132,18 @@ function command(payload) { deviceData = fields[0].split('@'); - result.deviceId = deviceData[0]; - result.command = deviceData[1]; + results.deviceId = deviceData[0]; + results.command = deviceData[1]; dataSection = fields.splice(1); if (dataSection.length === 1 && dataSection[0].indexOf('=') < 0) { - result.value = dataSection[0]; + results.value = dataSection[0]; } else { - result.params = dataSection.reduce(addAttribute('='), {}); + results.params = dataSection.reduce(addAttribute('='), {}); } - return result; + return results; } function parseCommand(group) { @@ -158,18 +158,20 @@ function parseCommand(group) { * @return {Object} Object representing the information in the group. */ function parseGroup(group) { - var numberOfBars; + var numberOfBars, groupValueParse; - if (group[0] === '|') { - group = group.substr(1); + groupValueParse = group; + + if (groupValueParse[0] === '|') { + groupValueParse = groupValueParse.substr(1); } - numberOfBars = group.match(/\|/g); + numberOfBars = groupValueParse.match(/\|/g); - if (group.indexOf('@') > 0) { - return parseCommand(group); + if (groupValueParse.indexOf('@') > 0) { + return parseCommand(groupValueParse); } else { - return parseMeasure(group, numberOfBars); + return parseMeasure(groupValueParse, numberOfBars); } } @@ -181,7 +183,7 @@ function parseGroup(group) { * @return {Array} Array containing an object per measure group */ function parse(payload) { - var groups, result; + var groups, results; if (!payload) { throw new errors.ParseError('Empty payload parsing Ultraligh 2.0'); @@ -189,12 +191,12 @@ function parse(payload) { try { groups = payload.split('#'); - result = groups.map(parseGroup); + results = groups.map(parseGroup); } catch (e) { throw new errors.ParseError('Unknown error parsing Ultralight 2.0: %s', e); } - return result; + return results; } function parseConfigurationRequest(payload) { @@ -243,15 +245,15 @@ function result(payload) { * @param {Object} attributes Object containing the command parameters as attributes of the object. * @return {String} String with the codified command. */ -function createCommandPayload(device, command, attributes) { +function createCommandPayload(device, commandPayLoad, attributes) { function addAttributes(current, key) { return current + '|' + key + '=' + attributes[key]; } if (typeof attributes === 'object') { - return Object.keys(attributes).reduce(addAttributes, device.id + '@' + command); + return Object.keys(attributes).reduce(addAttributes, device.id + '@' + commandPayLoad); } else { - return device.id + '@' + command + '|' + attributes; + return device.id + '@' + commandPayLoad + '|' + attributes; } } From ab160db2ad190a2f30a5e47dacaab7cbfc88c8e7 Mon Sep 17 00:00:00 2001 From: fiqare-secmotic Date: Fri, 15 Nov 2019 12:45:27 +0100 Subject: [PATCH 2/8] Rule 2: Unused function parameters should be removed --- lib/bindings/HTTPBindings.js | 6 +++--- lib/bindings/MQTTBinding.js | 2 +- lib/commonBindings.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/bindings/HTTPBindings.js b/lib/bindings/HTTPBindings.js index 99a72eee..ec7dbc90 100644 --- a/lib/bindings/HTTPBindings.js +++ b/lib/bindings/HTTPBindings.js @@ -44,7 +44,7 @@ var http = require('http'), }, transport = 'HTTP'; -function handleError(error, req, res, next) { +function handleError(error, req, res) { var code = 500; config.getLogger().debug(context, 'Error [%s] handing request: %s', error.name, error.message); @@ -135,7 +135,7 @@ function checkMandatoryParams(queryPayload) { * This middleware checks whether there is any polling command pending to be sent to the device. If there is some, * add the command information to the return payload. Otherwise it returns an empty payload. */ -function returnCommands(req, res, next) { +function returnCommands(req, res) { function updateCommandStatus(device, commandList) { var updates, cleanCommands; @@ -159,7 +159,7 @@ function returnCommands(req, res, next) { updates = commandList.map(createCommandUpdate); cleanCommands = commandList.map(cleanCommand); - async.parallel(updates.concat(cleanCommands), function(error, results) { + async.parallel(updates.concat(cleanCommands), function(error) { if (error) { // prettier-ignore config.getLogger().error( diff --git a/lib/bindings/MQTTBinding.js b/lib/bindings/MQTTBinding.js index 32a18350..c913e81b 100644 --- a/lib/bindings/MQTTBinding.js +++ b/lib/bindings/MQTTBinding.js @@ -252,7 +252,7 @@ function start(callback) { } }); mqttClient.on('message', commonBindings.mqttMessageHandler); - mqttClient.on('connect', function(ack) { + mqttClient.on('connect', function() { config.getLogger().info(context, 'MQTT Client connected'); recreateSubscriptions(); }); diff --git a/lib/commonBindings.js b/lib/commonBindings.js index 0a45399c..a7bc5c6a 100644 --- a/lib/commonBindings.js +++ b/lib/commonBindings.js @@ -115,7 +115,7 @@ function manageConfigurationRequest(apiKey, deviceId, device, objMessage) { * @param {Number} index Index of the group in the array. * @return {Array} Updated array of functions. */ -function processMeasureGroup(device, apikey, previous, current, index) { +function processMeasureGroup(device, apikey, previous, current) { var values = []; if (current.command) { From 54b8be17304aaa78095daa56dfff377ec5004096 Mon Sep 17 00:00:00 2001 From: fiqare-secmotic Date: Fri, 15 Nov 2019 12:58:50 +0100 Subject: [PATCH 3/8] Rule 3: Function parameters, caught exceptions and foreach variables should not be reassigned --- lib/ulParser.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/ulParser.js b/lib/ulParser.js index 1f72692c..17b8e411 100644 --- a/lib/ulParser.js +++ b/lib/ulParser.js @@ -81,14 +81,16 @@ function chunk(list, size) { } function parseMeasure(group, numberOfBars) { - var attributes, timestamp, returnValue; + var attributes, timestamp, returnValue, groupValue; + + groupValue = group; if (numberOfBars && numberOfBars.length % 2 === 0) { - timestamp = group.substr(0, group.indexOf('|')); - group = group.substr(group.indexOf('|') + 1); + timestamp = groupValue.substr(0, group.indexOf('|')); + groupValue = groupValue.substr(groupValue.indexOf('|') + 1); } - attributes = group.split('|'); + attributes = groupValue.split('|'); if ( !attributes || @@ -96,7 +98,7 @@ function parseMeasure(group, numberOfBars) { attributes.length % 2 !== 0 || attributes.filter(_.isEmpty).length > 0 ) { - throw new errors.ParseError('Parsing group:' + group); + throw new errors.ParseError('Parsing group:' + groupValue); } else { returnValue = chunk(attributes, 2).reduce(addAttributePair, {}); @@ -158,20 +160,20 @@ function parseCommand(group) { * @return {Object} Object representing the information in the group. */ function parseGroup(group) { - var numberOfBars, groupValueParse; + var numberOfBars, groupValue; - groupValueParse = group; + groupValue = group; - if (groupValueParse[0] === '|') { - groupValueParse = groupValueParse.substr(1); + if (groupValue[0] === '|') { + groupValue = groupValue.substr(1); } - numberOfBars = groupValueParse.match(/\|/g); + numberOfBars = groupValue.match(/\|/g); - if (groupValueParse.indexOf('@') > 0) { - return parseCommand(groupValueParse); + if (groupValue.indexOf('@') > 0) { + return parseCommand(groupValue); } else { - return parseMeasure(groupValueParse, numberOfBars); + return parseMeasure(groupValue, numberOfBars); } } From 422864787c91b8d5406ac229d03b6059098af59c Mon Sep 17 00:00:00 2001 From: fiqare-secmotic Date: Fri, 15 Nov 2019 13:08:24 +0100 Subject: [PATCH 4/8] Rule 4: if.. else if constructs should end with else clauses --- lib/iotaUtils.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/iotaUtils.js b/lib/iotaUtils.js index 4ed458b5..de656624 100644 --- a/lib/iotaUtils.js +++ b/lib/iotaUtils.js @@ -148,6 +148,8 @@ function mergeDeviceWithConfiguration(deviceData, configuration, callback) { deviceData[fields[i]] = configuration[confField]; } else if (!deviceData[fields[i]] && (!configuration || !configuration[confField])) { deviceData[fields[i]] = defaults[i]; + } else { + config.getLogger().error(context, 'There is no possible merge'); } if (deviceData[fields[i]] && ['active', 'lazy', 'commands'].indexOf(fields[i]) >= 0) { From 27893f567439ba70461f43c9c68727582c04c8f7 Mon Sep 17 00:00:00 2001 From: fiqare-secmotic Date: Fri, 15 Nov 2019 13:44:18 +0100 Subject: [PATCH 5/8] Swagger documetation --- lib/bindings/HTTPBindings.js | 105 +++++++++++++++++++++++++++++++++++ package.json | 2 + 2 files changed, 107 insertions(+) diff --git a/lib/bindings/HTTPBindings.js b/lib/bindings/HTTPBindings.js index ec7dbc90..3742d82c 100644 --- a/lib/bindings/HTTPBindings.js +++ b/lib/bindings/HTTPBindings.js @@ -42,6 +42,8 @@ var http = require('http'), context = { op: 'IOTAUL.HTTP.Binding' }, + swaggerUi = require('swagger-ui-express'), + swaggerJSDoc = require('swagger-jsdoc'), transport = 'HTTP'; function handleError(error, req, res) { @@ -406,11 +408,71 @@ function start(callback) { router: express.Router() }; + var options = { + // line 27 + swaggerDefinition: { + info: { + title: 'IoT Agent UL2 - HTTP', // Title (required) + version: '1.0.0', // Version (required) + description: 'This documentation explains the POST and GET requests to the route /iot/d' // Description (not required) + } + }, + apis: ['./lib/bindings/*'] // Path to the API docs + }; + var swaggerSpec = swaggerJSDoc(options); + + // ... + httpBindingServer.app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec)); // line 45 + config.getLogger().info(context, 'HTTP Binding listening on port [%s]', config.getConfig().http.port); httpBindingServer.app.set('port', config.getConfig().http.port); httpBindingServer.app.set('host', config.getConfig().http.host || '0.0.0.0'); + /** + * @swagger + * + * /iot/d: + * get: + * tags: + * - "iot/d" + * summary: "Report new measures" + * description: "A device can report new measures to the IoT Platform using an HTTP GET request to the /iot/d path" + * consumes: + * - "application/json" + * produces: + * - "application/json" + * parameters: + * - in: "query" + * name: "i" + * description: "Device ID" + * type: string + * required: true + * - in: "query" + * name: "k" + * description: "API Key for the service the device is registered on" + * type: string + * required: true + * - in: "query" + * name: "d" + * description: "Ultralight 2.0 payload. Payloads for GET requests should not contain multiple measure groups" + * type: string + * required: true + * - in: "query" + * name: "t" + * description: "Timestamp of the measure" + * type: timestamp + * required: false + * responses: + * 200: + * description: "The new measure has been registered " + * 404: + * description: 'No device was found with "device_name"' + * DEVICE_GROUP_NOT_FOUND: + * description: "Could not find device group" + * PARSE_ERROR: + * description: 'There was a syntax error in the Ultralight request: Unknown error parsing Ultralight 2.0: "syntax_error"' + */ httpBindingServer.router.get( config.getConfig().iota.defaultResource || constants.HTTP_MEASURE_PATH, checkMandatoryParams(true), @@ -420,6 +482,49 @@ function start(callback) { returnCommands ); + /** + * @swagger + * + * /iot/d: + * post: + * tags: + * - "iot/d" + * summary: "Registrer a new measure" + * description: "This request add a new measure to the datebase." + * operationId: "addDevices" + * consumes: + * - text/plain + * parameters: + * - in: query + * name: "i" + * description: "Device ID" + * type: string + * required: true + * - in: query + * name: "k" + * description: "API key. Service identification." + * type: string + * required: true + * - in: query + * name: "t" + * description: "Date and time of register" + * type: timestamp + * required: false + * - in: body + * name: "Sensors" + * description: 'Sensors Measurements. The different sensor values ​​are sent in IoT Agent format. For example: "c|1"' + * type: string + * required: true + * responses: + * 200: + * description: "Report new measures to the IoT Platform" + * 404: + * description: 'DEVICE_NOT_FOUND - No device was found with "device_name"' + * DEVICE_GROUP_NOT_FOUND: + * description: "Could not find device group" + * PARSE_ERROR: + * description: 'There was a syntax error in the Ultralight request: Unknown error parsing Ultralight 2.0: "syntax_error"' + */ httpBindingServer.router.post( config.getConfig().iota.defaultResource || constants.HTTP_MEASURE_PATH, addDefaultHeader, diff --git a/package.json b/package.json index f114f278..c2b71d1f 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,8 @@ "logops": "2.1.0", "mqtt": "2.18.8", "request": "2.88.0", + "swagger-jsdoc": "^3.4.0", + "swagger-ui-express": "^4.1.2", "underscore": "1.9.1" }, "devDependencies": { From ae332e4140da7b85466fa200df05590a2ad82805 Mon Sep 17 00:00:00 2001 From: fiqare-secmotic Date: Thu, 21 Nov 2019 10:39:01 +0100 Subject: [PATCH 6/8] travis test --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c376d392..1379ea7b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,8 @@ addons: branches: only: - - master + - secmotic_fiQare + - secmotic_fiQare_swagger services: - rabbitmq From 8e9399f89258c3455655fd22b1792c3cb6f7ddd5 Mon Sep 17 00:00:00 2001 From: fiqare-secmotic Date: Thu, 21 Nov 2019 11:02:10 +0100 Subject: [PATCH 7/8] Lint script with swagger --- lib/bindings/HTTPBindings.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/bindings/HTTPBindings.js b/lib/bindings/HTTPBindings.js index 3742d82c..34c82e10 100644 --- a/lib/bindings/HTTPBindings.js +++ b/lib/bindings/HTTPBindings.js @@ -409,20 +409,18 @@ function start(callback) { }; var options = { - // line 27 swaggerDefinition: { info: { - title: 'IoT Agent UL2 - HTTP', // Title (required) - version: '1.0.0', // Version (required) - description: 'This documentation explains the POST and GET requests to the route /iot/d' // Description (not required) + title: 'IoT Agent UL2 - HTTP', + version: '1.0.1', + description: 'This documentation explains the requests to the route /iot/d' } }, - apis: ['./lib/bindings/*'] // Path to the API docs + apis: ['./lib/bindings/*'] }; var swaggerSpec = swaggerJSDoc(options); - // ... - httpBindingServer.app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec)); // line 45 + httpBindingServer.app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec)); config.getLogger().info(context, 'HTTP Binding listening on port [%s]', config.getConfig().http.port); @@ -437,7 +435,7 @@ function start(callback) { * tags: * - "iot/d" * summary: "Report new measures" - * description: "A device can report new measures to the IoT Platform using an HTTP GET request to the /iot/d path" + * description: "A device can report new measures to the IoT Platform" * consumes: * - "application/json" * produces: @@ -455,7 +453,7 @@ function start(callback) { * required: true * - in: "query" * name: "d" - * description: "Ultralight 2.0 payload. Payloads for GET requests should not contain multiple measure groups" + * description: "Ultralight 2.0 payload" * type: string * required: true * - in: "query" @@ -471,7 +469,7 @@ function start(callback) { * DEVICE_GROUP_NOT_FOUND: * description: "Could not find device group" * PARSE_ERROR: - * description: 'There was a syntax error in the Ultralight request: Unknown error parsing Ultralight 2.0: "syntax_error"' + * description: 'There was a syntax error in the Ultralight request' */ httpBindingServer.router.get( config.getConfig().iota.defaultResource || constants.HTTP_MEASURE_PATH, @@ -512,7 +510,7 @@ function start(callback) { * required: false * - in: body * name: "Sensors" - * description: 'Sensors Measurements. The different sensor values ​​are sent in IoT Agent format. For example: "c|1"' + * description: 'Sensors Measurements' * type: string * required: true * responses: @@ -523,7 +521,7 @@ function start(callback) { * DEVICE_GROUP_NOT_FOUND: * description: "Could not find device group" * PARSE_ERROR: - * description: 'There was a syntax error in the Ultralight request: Unknown error parsing Ultralight 2.0: "syntax_error"' + * description: 'There was a syntax error in the Ultralight request.' */ httpBindingServer.router.post( config.getConfig().iota.defaultResource || constants.HTTP_MEASURE_PATH, From e19d6b8729984f76bedc9b2c602377decc793b31 Mon Sep 17 00:00:00 2001 From: fiqare-secmotic Date: Thu, 21 Nov 2019 11:59:03 +0100 Subject: [PATCH 8/8] travis test --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1379ea7b..c376d392 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,7 @@ addons: branches: only: - - secmotic_fiQare - - secmotic_fiQare_swagger + - master services: - rabbitmq