Revan
Revan

Reputation: 315

YAMLSemanticError: Implicit map keys need to be on a single line at line 1, column 1: trying to create Swagger Documentation

This is my first timeimplementing Swagger. I need guidance. I am trying to implement swagger in my REST api, Iam getting this Error

PS D:\node_apps\testpdfgenerate> node index.js
Not all input has been taken into account at your final specification.
Here's the report:


 YAMLSemanticError: Implicit map keys need to be on a single line at line 1, column 1:

/api/v1/listallstaff/:email
^^^^^^^^^^^^^^^^^^^^^^^^^^^…

App running on Port: 7000

The rest route works fine, but implementing it in Swagger, To create a documentation, I am getting that error above

The full code of the REST api looks thus.

var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mysql = require('mysql');
const swaggerJSDoc = require('swagger-jsdoc');  
const swaggerUI = require('swagger-ui-express'); 


var port = process.env.PORT || 7000;

//evade cors

app.use(function (req, res, next) {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
    res.setHeader('Access-Control-Allow-Credentials', true);
    next();
 });


app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
    extended:true
}));


//Swagger Configuration  
const swaggerOptions = {  
    swaggerDefinition: {  
        info: {  
            title:'Employee API',  
            version:'1.0.0'  
        }  
    },  
    apis:['index.js'],  
}  
const swaggerDocs = swaggerJSDoc(swaggerOptions);  
app.use('/api-docs',swaggerUI.serve,swaggerUI.setup(swaggerDocs)); 

app.get('/api/',function(req , res){
    return res.send({error: false,message: 'Pdf Generator example'})
});


var dbConn = mysql.createPool({
    host: 'localhost',
    user: 'root',
    password: '',
    database: 'fakeppldbpdf'
});

module.exports = dbConn;

/** 
 * @swagger 
 * /api/v1/listallstaff: 
 *   get: 
 *     description: Get all Employee 
 *     responses:  
 *       200: 
 *         description: Success  
 *   
 */ 

app.get('/api/v1/listallstaff',function(req,res){
    dbConn.query('SELECT * FROM sobreppltable',function(error, results, fields){
        if(error) throw error;
        return res.send({ error: false, data: results, message: 'users list' });
    })
})

/** 
 * @swagger 
 * /api/v1/listallstaff/:email
 *   get: 
 *     description: Get all Employee by Email
 *     responses:  
 *       200: 
 *         description: Success  
 *   
 */ 

app.get('/api/v1/listallstaff/:email',function(req,res){
    let email = req.params.email;
    dbConn.query('SELECT * FROM sobreppltable WHERE email =?', email,function(error, results, fields){
        if(error) throw error;
        return res.send({ error: false, data: results[0], message: 'users list' });
    })
})



app.listen(port,function(){
    console.log('App running on Port: '+port);
});

module.exports = app;

What Am I not doing correctly?

Upvotes: 8

Views: 35067

Answers (2)

J_Bon
J_Bon

Reputation: 180

You fixed it 'cause you added : at the end. Curly braces only define it as a path parameter.

Check next-swagger-doc documentation and Swagger.io to understand it better:

https://github.com/jellydn/next-swagger-doc

https://swagger.io/docs/specification/describing-parameters

Upvotes: 2

Revan
Revan

Reputation: 315

Fixed added curly braces

/** 
 * @swagger 
 * /api/v1/listallstaff/{email}:
 *   get: 
 *     description: Get all Employee by Email
 *     responses:  
 *       200: 
 *         description: Success  
 *   
 */ 

Solved it just incase for other newbies like me :)

Upvotes: 9

Related Questions