Swagger - Change Project Directory

I created a new project ( nodeJS ) inside the root directory inside my workspace, and after a while I wanted to separate the client and server side of the project. To do this, I created two folders (server and client) inside the project root directory and moved all the files and directories to the appropriate folder.

After that, I can not start the server, because it says that Swagger cannot find the swagger.yaml file (I moved it to the server folder)

{ Error: ENOENT: no such file or directory, open 'C:\Users\User\Documents\movieCollection\api\swagger\swagger.yaml' at Error (native) at Object.fs.openSync (fs.js:634:18) at Object.fs.readFileSync (fs.js:502:33) at C:\Users\User\AppData\Roaming\npm\node_modules\swagger\lib\commands\project\project.js:283:44 at findProjectFile (C:\Users\User\AppData\Roaming\npm\node_modules\swagger\lib\commands\project\project.js:308:14) at readProject (C:\Users\User\AppData\Roaming\npm\node_modules\swagger\lib\commands\project\project.js:268:3) at Command.edit (C:\Users\User\AppData\Roaming\npm\node_modules\swagger\lib\commands\project\project.js:240:3) at Command.<anonymous> (C:\Users\User\AppData\Roaming\npm\node_modules\swagger\lib\util\cli.js:167:27) at Command.listener (C:\Users\User\AppData\Roaming\npm\node_modules\swagger\node_modules\commander\index.js:301:8) at emitTwo (events.js:106:13) errno: -4058, code: 'ENOENT', syscall: 'open', path: 'C:\\Users\\User\\Documents\\movieCollection\\api\\swagger\\swagger.yaml' } 

I tried to edit the default.yaml file inside the node server configuration folder, but the problem still persists.

Is there a way to reassign the swagger project configuration to a new folder (directory-> server folder)?

default.yaml:

 # swagger configuration file # values in the swagger hash are system configuration for swagger-node swagger: fittingsDirs: [ api/fittings ] defaultPipe: null swaggerControllerPipe: swagger_controllers # defines the standard processing pipe for controllers # values defined in the bagpipes key are the bagpipes pipes and fittings definitions # (see https://github.com/apigee-127/bagpipes) bagpipes: _router: name: swagger_router mockMode: false mockControllersDirs: [ ./server/api/mocks ] controllersDirs: [ ./server/api/controllers ] _swagger_validate: name: swagger_validator validateResponse: true # pipe for all swagger-node controllers swagger_controllers: - onError: json_error_handler - cors - swagger_security - _swagger_validate - express_compatibility - _router # pipe to serve swagger (endpoint is in swagger.yaml) swagger_raw: name: swagger_raw # any other values in this file are just loaded into the config for application access... 

EDIT: Added app.js

app.js:

 'use strict'; var SwaggerExpress = require('swagger-express-mw'); var express = require("express"); var config = require('config'); var cors = require('cors'); var bodyParser = require('body-parser'); var mongoose = require('mongoose'); var passport = require('passport'); var flash = require('connect-flash'); var session = require('express-session'); var routes = require('./src/routes'); var routingPath = '../server'; var app = express(); var spec = fs.readFileSync('../server/api/swagger.yaml', 'utf8'); var swaggerDoc = jsyaml.safeLoad(spec); // Enable CORS app.use(cors()); // Bootstrap routes app.use(routes); // Static files app.use('/', express.static(__dirname + '/../public')); module.exports = app; // for testing var config = { appRoot: __dirname // required config }; swaggerExpress.runner.swagger.basePath = routingPath; SwaggerExpress.create(config, function(err, swaggerExpress) { if (err) { throw err; } // install middleware swaggerExpress.register(app); var port = process.env.PORT || 10010; app.listen(port); console.log('Server started: http://127.0.0.1:' + port ); }); 
+7
source share
1 answer
 'use strict'; import errors from './components/errors'; import path from 'path'; var swaggerUi = require('swagger-ui-express'); var swaggerDocument = require('./swagger.js'); export default function(app) { // Insert routes below app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); } added this in route file... 
0
source

All Articles