Commit d3252fb4 authored by Alex Quispe's avatar Alex Quispe
Browse files

Corrección de errores y actualización de ejemplos.

parent 2a38d0e4
......@@ -15,7 +15,7 @@ class ApidocGenerator {
}
static async create (filesName) {
console.log(' Construyendo apidoc ...\n')
console.log(' Construyendo apidoc ...')
if (util.isDir(ApidocGenerator.BUILD_PATH)) util.rmdir(ApidocGenerator.BUILD_PATH)
const outputRoutesPath = path.resolve(ApidocGenerator.BUILD_PATH, 'routes')
......@@ -26,6 +26,7 @@ class ApidocGenerator {
for (let i in filesName) {
const fileName = filesName[i]
const filePath = path.resolve(ApidocGenerator.SRC_PATH, fileName)
console.log(`\n Procesando archivo "src/${fileName}.js" ...\n`)
const dirname = path.dirname(filePath)
const outputDirPath = path.resolve(ApidocGenerator.BUILD_PATH, `routes/${fileName}`)
if(util.isDir(outputDirPath)) util.rmdir(outputDirPath)
......@@ -41,7 +42,7 @@ class ApidocGenerator {
await _build()
}
console.log('\n Apidoc generado exitosamente :)\n')
console.log('\n \x1b[32minfo:\x1b[0m Apidoc generado exitosamente :)\n')
}
static get (routePath) { return ApidocGenerator._createRoute('get', routePath) }
......@@ -113,10 +114,21 @@ class ApidocGenerator {
let swaggerContent = this._getSwaggerContent()
const apiRouter = ApidocCreator.router(route => {
apidocContent += route.apidoc
// APIDOC JS
const newBlock = route.apidoc
const newRouteKey = newBlock.split('\n')[2]
if (apidocContent.includes(newRouteKey)) {
console.log(` \x1b[33m${_.padEnd(`[${route.method}]`, 9)} ${route.path} - ${route.group} (${route.name}) \u2715 Ya ha sido documentado\x1b[0m`)
} else {
apidocContent += newBlock
console.log(` ${_.padEnd(`[${this.route.method}]`, 9)} ${this.route.path} - ${this.route.group} (${this.route.name}) \u2713`)
}
// SWAGER
swaggerContent.paths[route.apidocSwagger.path] = swaggerContent.paths[route.apidocSwagger.path] || {}
if (swaggerContent.paths[route.apidocSwagger.path][route.apidocSwagger.method]) {
console.log(`\n \x1b[33mAdvertencia:\x1b[0m El servicio [${this.route.method}] ${this.route.path} (${this.route.name}) ya ha sido documentado`)
// console.log(` \x1b[33m${_.padEnd(`[${this.route.method}]`, 9)} ${this.route.path} - ${this.route.group} (${this.route.name}) \u2715 Ya ha sido documentado en SWAGGER\x1b[0m`)
return
}
swaggerContent.paths[route.apidocSwagger.path][route.apidocSwagger.method] = route.apidocSwagger.content
})
......@@ -125,7 +137,6 @@ class ApidocGenerator {
this._generateApidocJS(apidocContent)
this._generateSwagger(swaggerContent)
console.log(` ${ApidocGenerator.OUTPUT_TEMP_PATH.replace(process.cwd(), '')} - ${this.route.group} (${this.route.name}) \u2713`)
return this.route.outputData
}
......@@ -259,13 +270,21 @@ function _request (method, uri, body, headers) {
}
async function _build () {
console.log('\n Uniendo ficheros (apidoc.js, swagger.json) ...\n')
// APIDOC JS
const filePath1 = path.resolve(ApidocGenerator.BUILD_PATH, `apidoc.js`)
if(util.isFile(filePath1)) { util.removeFile(filePath1) }
let content = ''
util.find(ApidocGenerator.BUILD_PATH, '.js', (info) => {
content += util.readFile(info.filePath)
const newBlock = util.readFile(info.filePath)
const newRouteKey = newBlock.split('\n')[2]
if (content.includes(newRouteKey)) {
console.log(`\n \x1b[33mAdvertencia:\x1b[0m El servicio "${newRouteKey.substr(7)}" ya ha sido documentado. (ignorado)`)
return
}
content += newBlock
})
util.writeFile(filePath1, content)
......@@ -287,7 +306,7 @@ async function _build () {
content2.paths[routePath] = content2.paths[routePath] || {}
Object.keys(contentToAdd.paths[routePath]).forEach(routeMethod => {
if (content2.paths[routePath][routeMethod]) {
console.log(`\n \x1b[33mAdvertencia:\x1b[0m El servicio [${routeMethod}] ${routePath} (${content2.paths[routePath][routeMethod].name}) ya ha sido documentado`)
const group = content2.paths[routePath][routeMethod].tags.toString()
return
}
content2.paths[routePath][routeMethod] = contentToAdd.paths[routePath][[routeMethod]]
......
const ApiGen = require('../../../')
module.exports = async () => {
await ApiGen.post('/api/v1/users').data({body:{name:'John',user:'admin',pass:'123'}}).key('Admin').generate('GRUPO 2')
await ApiGen.post('/api/v1/users').data({body:{name:'Smith',user:'user',pass:'123'}}).key('User').generate('GRUPO 2')
}
......@@ -7,9 +7,6 @@ module.exports = async () => {
await ApiGen.get('/api/v1/users').name('Devuelve una lista de usuarios').generate('GRUPO 1')
await ApiGen.get('/api/v1/users').name('Listar usuarios').generate('GRUPO 1')
await ApiGen.post('/api/v1/users').data({body:{name:'John',user:'admin',pass:'123'}}).key('Admin').generate('GRUPO 2')
await ApiGen.post('/api/v1/users').data({body:{name:'Smith',user:'user',pass:'123'}}).key('User').generate('GRUPO 2')
await ApiGen.get('/documentando/solo/la/ruta').request(false).generate('GRUPO 3')
const DATA = [
......
Supports Markdown
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