Started working on swagger docs

pull/1/head
Piero Toffanin 2016-09-14 19:02:44 -04:00
rodzic 3c2e431d2f
commit 3958b8a543
6 zmienionych plików z 118 dodań i 66 usunięć

Wyświetl plik

@ -0,0 +1,47 @@
/*
Node-OpenDroneMap Node.js App and REST API to access OpenDroneMap.
Copyright (C) 2016 Node-OpenDroneMap Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
let swaggerJSDoc = require('swagger-jsdoc');
let fs = require('fs');
let options = {
swaggerDefinition: {
info: {
title: 'Node-OpenDroneMap',
version: '0.1.0',
license: {
name: 'GPLv3',
url: 'http://www.gnu.org/licenses/'
},
contact: {
name: 'Piero Toffanin',
url: 'https://www.masseranolabs.com',
email: 'pt@masseranolabs.com'
}
},
consumes: ["application/json"],
produces: ["application/json", "application/zip"],
basePath: "/",
schemes: ["http"]
},
apis: ['../index.js'], // Path to the API docs
};
// Initialize swagger-jsdoc -> returns validated swagger spec in json format
let swaggerSpec = swaggerJSDoc(options);
fs.writeFileSync('swagger.json', JSON.stringify(swaggerSpec));

Wyświetl plik

@ -0,0 +1 @@
{"info":{"title":"Node-OpenDroneMap","version":"0.1.0","license":{"name":"GPLv3","url":"http://www.gnu.org/licenses/"},"contact":{"name":"Piero Toffanin","url":"https://www.masseranolabs.com","email":"pt@masseranolabs.com"}},"consumes":["application/json"],"produces":["application/json"],"basePath":"/","schemes":["http"],"swagger":"2.0","paths":{"/task/cancel":{"post":{"description":"Cancels a task","parameters":[{"name":"uuid","in":"body","description":"UUID of the task to cancel","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Command Received","schema":{"$ref":"#/definitions/Response"}}}}}},"definitions":{"Response":{"type":"object","required":["success"],"properties":{"success":{"type":"boolean"},"error":{"type":"string","description":"Error message if an error occured"}}}},"responses":{},"parameters":{},"securityDefinitions":{},"tags":[]}

Wyświetl plik

@ -1,22 +0,0 @@
var swaggerJSDoc = require('swagger-jsdoc');
var jsonfile = require('jsonfile');
var options = {
swaggerDefinition: {
info: {
title: 'Node-OpenDroneMap', // Title (required)
version: '0.1.0', // Version (required)
},
},
apis: ['./index.js'], // Path to the API docs
};
// Initialize swagger-jsdoc -> returns validated swagger spec in json format
var swaggerSpec = swaggerJSDoc(options);
var file = 'swagger-api.json';
jsonfile.writeFile(file, swaggerSpec, function (err) {
console.error(err);
process.exit(1);
});

Wyświetl plik

@ -158,33 +158,89 @@ let uuidCheck = (req, res, next) => {
else next();
};
/** @swagger
* definition:
* Response:
* type: object
* required:
* - success
* properties:
* success:
* type: boolean
* error:
* type: string
* description: Error message if an error occured
*/
let successHandler = res => {
return err => {
if (!err) res.json({success: true});
else res.json({error: err.message});
else res.json({success: false, error: err.message});
};
};
/**
* @swagger
* /task/cancel/{uuidCheck}:
* get:
* description: Cancels a task
* parameters:
* - uuidCheck: uuid of the task to cancel
* responses:
* 200:
* description: Task cancelled
*/
/** @swagger
* /task/cancel:
* post:
* description: Cancels a task (stops its execution, or prevents it from being executed)
* parameters:
* -
* name: uuid
* in: body
* description: UUID of the task to cancel
* required: true
* schema:
* type: string
* responses:
* 200:
* description: Command Received
* schema:
* $ref: "#/definitions/Response"
*/
app.post('/task/cancel', uuidCheck, (req, res) => {
taskManager.cancel(req.body.uuid, successHandler(res));
taskManager.cancel(req.body.uuid, e(res));
});
/** @swagger
* /task/remove:
* post:
* description: Removes a task and deletes all of its assets
* parameters:
* -
* name: uuid
* in: body
* description: UUID of the task to cancel
* required: true
* schema:
* type: string
* responses:
* 200:
* description: Command Received
* schema:
* $ref: "#/definitions/Response"
*/
app.post('/task/remove', uuidCheck, (req, res) => {
taskManager.remove(req.body.uuid, successHandler(res));
});
/** @swagger
* /task/restart:
* post:
* description: Restarts a task that was previously canceled or that had failed to process
* parameters:
* -
* name: uuid
* in: body
* description: UUID of the task to cancel
* required: true
* schema:
* type: string
* responses:
* 200:
* description: Command Received
* schema:
* $ref: "#/definitions/Response"
*/
app.post('/task/restart', uuidCheck, (req, res) => {
taskManager.restart(req.body.uuid, successHandler(res));
});

Wyświetl plik

@ -24,7 +24,6 @@
"async": "^2.0.0-rc.6",
"body-parser": "^1.15.2",
"express": "^4.14.0",
"jsonfile": "^2.3.1",
"minimist": "^1.2.0",
"morgan": "^1.7.0",
"multer": "^1.1.0",

Wyświetl plik

@ -1,29 +0,0 @@
{
"info": {
"title": "Node-OpenDroneMap",
"version": "0.1.0"
},
"swagger": "2.0",
"paths": {
"/task/cancel/{uuidCheck}": {
"get": {
"description": "Cancels a task",
"parameters": [
{
"uuidCheck": "uuid of the task to cancel"
}
],
"responses": {
"200": {
"description": "Task cancelled"
}
}
}
}
},
"definitions": {},
"responses": {},
"parameters": {},
"securityDefinitions": {},
"tags": []
}