Commit 21dbf3e9 authored by Alex Quispe's avatar Alex Quispe

Mejoras y corrección de errores

parent ccaf6d88
Pipeline #2127 failed with stages
module.exports = {
ApidocGenerator : require('./src/class/ApidocGenerator'),
ApidocRequest : require('./src/class/ApidocRequest')
ApidocRequest : require('./src/class/ApidocRequest'),
Field : require('./src/class/FieldCreator'),
}
{
"name": "agetic-bpm-doc-generator",
"name": "doc-generator",
"version": "1.0.0",
"description": "Generador de Apidoc y Test de Integración para servicios web creados con express.",
"main": "index.js",
......@@ -12,10 +12,6 @@
"bin": {
"doc": "src/cli/doc.js"
},
"repository": {
"type": "git",
"url": "git@gitlab.geo.gob.bo:agetic/agetic-bpm-doc-generator.git"
},
"author": "Alex Quispe <wilmer.quispe@agetic.gob.bo>",
"license": "MIT",
"dependencies": {
......
......@@ -136,7 +136,7 @@ function _route (properties, onCreate) {
*/
function _example (obj) {
let result = ''
const example = JSON.stringify(_createData(obj, false), null, 2)
let example = JSON.stringify(_createData(obj, false), null, 2)
example.split('\n').forEach(line => {
result += `* ${line}\n`
})
......@@ -165,7 +165,7 @@ function _customExample (obj) {
* @return {String}
*/
function _header (route) {
let content = '\n/**\n'
let content = `\n/**\n`
content += `* @api {${route.method}} ${route.path} ${route.name}\n`
content += `* @apiName ${route.name}\n`
content += `* @apiGroup ${route.group}\n`
......@@ -248,6 +248,9 @@ function _createApidoc (fullprop, obj, apidocProperty, type) {
}
function _createApidocSwagger (fullprop, obj, apidocProperty, type, propName = '') {
if (!obj) {
return { type: 'object', properties: {}, example: null };
}
let apidoc = {}
if (Array.isArray(obj)) {
apidoc.type = 'array'
......@@ -397,9 +400,12 @@ function _normalizeValidate (field) {
* @return {Object}
*/
function _createData (obj, onlyRequired) {
if (!obj) {
return null
}
if (Array.isArray(obj)) {
const SOL = _createData(obj[0], onlyRequired)
if (Object.keys(SOL).length <= 0) return []
if (!SOL || Object.keys(SOL).length <= 0) return []
return [SOL]
}
const data = {}
......
......@@ -290,10 +290,11 @@ function _updateTHIS (model, obj, fullPath = '', baseModel) {
}
Object.keys(obj).forEach(prop => {
const OBJ = obj[prop]
const fullPath2 = `${fullPath ? `${fullPath}.` : ''}${prop}`
const fullPath2 = fullPath ? `${fullPath}.${prop}` : prop
if (_isTHIS(OBJ)) {
if (!model || !model.attributes[prop]) {
let msg = `El campo '${fullPath2}: THIS()' no es parte del modelo ${baseModel ? `'${baseModel.name}'` : `'${model ? model.name : 'null'}'`}.\n`
const modelName = baseModel ? `'${baseModel.name}'` : `'${model ? model.name : 'null'}'`
let msg = `El campo '${fullPath2}: THIS()' no es parte del modelo ${modelName}.\n`
throw new Error(msg)
}
delete OBJ._this
......@@ -332,7 +333,7 @@ function _validateGroup (obj, fullPath = '') {
if (_isField(OBJ)) {
return
}
const fullPath2 = `${fullPath ? `${fullPath}.` : ''}${prop}`
const fullPath2 = fullPath ? `${fullPath}.${prop}` : prop
if (_isTHIS(OBJ)) {
let msg = `El campo '${fullPath2}: THIS()' debe ser parte de un modelo.\n`
throw new Error(msg)
......@@ -494,7 +495,7 @@ function _toFieldGroup (obj, fullPath = '') {
if (obj) {
Object.keys(obj).forEach(prop => {
const OBJ = obj[prop]
const fullPath2 = `${fullPath ? `${fullPath}.` : ''}${prop}`
const fullPath2 = fullPath ? `${fullPath}.${prop}` : prop
if (typeof OBJ === 'object') {
RESULT[prop] = _toFieldGroup(OBJ, `${fullPath2}`)
return
......@@ -503,6 +504,7 @@ function _toFieldGroup (obj, fullPath = '') {
})
return RESULT
}
return null
}
function _getMaxItem (array) {
......
......@@ -16,7 +16,7 @@
<script id="template-sidenav" type="text/x-handlebars-template">
<nav id="scrollingNav">
<div class="sidenav-search">
<div class="link-to-swagger"><a href="../swagger">INICIO</a></div>
<div class="link-to-swagger"><a href="../swagger/index.html">SWAGGER</a></div>
<input class="form-control search" type="text" placeholder="{{__ "Buscar ..."}}">
<span class="search-reset">x</span>
</div>
......
......@@ -39,7 +39,7 @@
window.onload = function() {
// Build a system
const ui = SwaggerUIBundle({
url: `${window.location.href}swagger.json`,
url: `${window.location.href.replace('index.html', '')}swagger.json`,
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
......
test('[GROUP] [METHOD] PATH', async t => {
try {
const response = await ApidocGenerator.METHOD('PATH').generate()
// if (response.error) {
// t.falsy(response.error, 'La consulta no finalizó como se esperaba')
const response = await ApidocGenerator.METHOD('PATH').generate();
// if (response && response.error) {
// console.log(response.body);
// t.falsy('La consulta no finalizó como se esperaba')
// }
t.pass()
} catch (e) { console.log(e) }
})
t.pass(response);
} catch (e) { console.log(e); }
});
// <!-- [TEST DEFINITION] --!> //
const test = require('ava')
const test = require('ava');
const { ApidocGenerator, ApidocRequest } = require('agetic-bpm-doc-generator')
const { ApidocGenerator, ApidocRequest } = require('doc-generator');
test.before(async t => {
try {
ApidocRequest.init()
ApidocRequest.init();
ApidocGenerator.globalProperties({ group: 'GROUP' })
} catch (e) { console.log(e) }
})
ApidocGenerator.globalProperties({ group: 'GROUP' });
} catch (e) { console.log(e); }
});
// <!-- [TEST DEFINITION] --!> //
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment