Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js scocontroller.login({username,password}); 设{response,code}=auth; 返回res.status(代码).json(响应); }); }; module.exports=authRoutes; 您使_Node.js_Swagger Ui_Swagger Jsdocs - Fatal编程技术网

Node.js scocontroller.login({username,password}); 设{response,code}=auth; 返回res.status(代码).json(响应); }); }; module.exports=authRoutes; 您使

Node.js scocontroller.login({username,password}); 设{response,code}=auth; 返回res.status(代码).json(响应); }); }; module.exports=authRoutes; 您使,node.js,swagger-ui,swagger-jsdocs,Node.js,Swagger Ui,Swagger Jsdocs,scocontroller.login({username,password}); 设{response,code}=auth; 返回res.status(代码).json(响应); }); }; module.exports=authRoutes; 您使用的是swagger.json文件吗?您好,现在没有。我已经在我的应用程序中硬编码了。js您使用的是swagger.json文件吗?您好,现在没有。我已经在我的应用程序中硬编码了。jsHi Parveen,非常感谢!这成功了!最后很容易,不是吗

scocontroller.login({username,password}); 设{response,code}=auth; 返回res.status(代码).json(响应); }); }; module.exports=authRoutes;
您使用的是swagger.json文件吗?您好,现在没有。我已经在我的应用程序中硬编码了。js您使用的是swagger.json文件吗?您好,现在没有。我已经在我的应用程序中硬编码了。jsHi Parveen,非常感谢!这成功了!最后很容易,不是吗。我的错误是认为swagger.json将由swagger自动生成,但事实并非如此。再次感谢,没关系。干杯嗨,帕文,非常感谢!这成功了!最后很容易,不是吗。我的错误是认为swagger.json将由swagger自动生成,但事实并非如此。再次感谢,没关系。干杯您使用的swagger jsdocs的版本是什么。我想他们把它升级到了ES6标准。因此,使用
require('swagger-jsdoc')
将使我使用的版本失败
“swagger-jsdoc”:“6.0.0”
您使用的swagger-jsdoc的版本是什么。我想他们把它升级到了ES6标准。因此,使用
require('swagger-jsdoc')
将使我使用的版本失败
“swagger-jsdoc”:“6.0.0”
// requires
const path = require("path");
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");

const postsRoutes = require("./routes/posts/posts");
const userRoutes = require("./routes/auth/user");
const swaggerUi = require("swagger-ui-express");
const swaggerJSDoc = require("swagger-jsdoc");

// https://swagger.io/specification/v2/
const swaggerOptions = {
  swaggerDefinition: {
    info: {
      title: "Post API",
      description: "This is a sample Post API",
      contact: {
        name: "Test ",
        url: "http://www.swagger.io/support",
        email: "test@gmail.com"
      },
      servers: ["http://localhost:3850/"]
    }
  },
  swagger: "2.0",
  apis: ["/backend/routes/posts/posts.js"]
};

const app = express();
let options = {
  explorer: true
};

// swagger
const swaggerDocs = swaggerJSDoc(swaggerOptions);
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocs, options));

// MONGOOSE CONNECT
mongoose
  .connect(
    "mongodb+srv://"
  )
  .then(() => {
    console.log("####-connected to MongoDB");
  })
  .catch(error => {
    console.log("Connection ERROR!", error);
  });

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use("/images", express.static(path.join("backend/images")));

// CORS
app.use((req, res, next) => {
  res.setHeader("Access-Control-Allow-Origin", "*");
  res.setHeader(
    "Access-Control-Allow-Headers",
    "Origin, X-Requested-With, Content-Type, Accept, Authorization"
  );
  res.setHeader(
    "Access-Control-Allow-Methods",
    "GET, POST, PATCH, PUT, DELETE, OPTIONS"
  );
  next();
});

// ROUTES
app.use("/api/posts", postsRoutes);
app.use("/api/user", userRoutes);

module.exports = app;
// express router
const router = express.Router();

// get posts endpoint
/**
 * @swagger
 * /api/posts:
 *  get:
 *   description use to request all posts
 *   responses:
 *   '200':
 *     description: a successful response
 */
router.get("", PostController.getPosts);
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('./swagger.json');
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
{
    "swagger": "2.0",
    "info": {
      "version": "1.0.0",
      "title": "Parveen App API",
      "description": "Find out how your APIs work",
      "license": {
        "name": "MIT",
        "url": "https://opensource.org/licenses/MIT"
      }
    },
    "host": "localhost:5000",
    "basePath": "/api/v1",
    "tags": [
      {
        "name": "Users",
        "description": "API for users in the system"
      }

    ],
    "schemes": [
      "http",
      "https"
    ],
    "consumes": [
      "application/json"
    ],
    "produces": [
      "application/json"
    ],
    "securityDefinitions": {
        "ApiKeyAuth":{
          "type": "apiKey",
          "in": "headers",
          "name": "authorization"
        }
    },
    "paths": {
      "/users/login": {
        "post": {
          "summary": "Login user",
          "tags": [
            "Users"
          ],
          "description": "Login user in system",
          "parameters": [
            {
              "name": "user",
              "in": "body",
              "description": "Login user",
              "schema": {
                "$ref": "#/definitions/User"
              }
            }
          ],
          "produces": [
            "application/json"
          ],
          "responses": {
            "200": {
              "description": "Login Success",
              "schema": {
                "$ref": "#/definitions/User"
              }
            },
            "401":{
              "description": "Login details are not valid!!"
            },
            "404":{
              "description": "Email is not registered!"
            },
            "500":{
              "description": "User login failed!!"
            }
          }
        }
      }
    },

    "definitions": {

      "User": {
        "properties": {
          "email": {
            "type": "string"
          },
          "password": {
            "type": "string"
          }
        }
      },
      "userEmail":{
        "properties": {
          "email": {
            "type": "string"
          }
        }
      }



    }
  }