/** * Auth application */ function authApp() { /* express.js configurations */ app.set('port', env.getAPIPort()); app.set('view engine', 'jade'); app.set('json spaces', 0); app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(app.router); /* swagger configs */ app.use(express.json()); app.use(express.urlencoded()); var subpath = express(); app.use("/" + utils.getApiVersion(), subpath); //Set Content-Type to the one of the application function respondWithDefaultContentType(req, res, next) { res.contentType(constants.getMediaType()); next(); } app.get('/*', respondWithDefaultContentType); app.post('/*', respondWithDefaultContentType); app.put('/*', respondWithDefaultContentType); app.del('/*', respondWithDefaultContentType); swagger.setAppHandler(subpath); swagger .addGet(authentication.decrypt) .addGet(authentication.encrypt); swagger.configureDeclaration("authentication", { description: "Operations about encryption/decryption", produces: ["application/json"] }); /* sets API info */ swagger.setApiInfo({ title: "AUTH API", description: "This is concept API", contact: "*****@*****.**" }); // Configures the app's base path and api version. swagger.configureSwaggerPaths("", "api", ""); swagger.configure(env.getAPIHost() + '/' + utils.getApiVersion(), "1.0.0"); app.use(cors(utils.corsOptions)); return app; }
swagger.addModels(models) .addGet(statsResources.getStats) .addGet(videosResources.findAll) .addGet(videosResources.findById) .addPost(videosResources.create) .addGet(problemsResources.findAll) .addGet(problemsResources.findById) .addPost(problemsResources.postAnswer) ; swagger.configureDeclaration('stats', { description: 'Operations about Stats', authorizations: ['oauth2'], produces: ['application/json'] }); swagger.configureDeclaration('videos', { description: 'Operations about Videos', authorizations: ['oauth2'], produces: ['application/json'] }); swagger.configureDeclaration('problems', { description: 'Operations about Problems', authorizations: ['oauth2'], produces: ['application/json'] });
exports.configure = function(app, express){ var corsOptions = { credentials: true, origin: function(origin,callback) { if(origin===undefined) { callback(null,false); } else { // change wordnik.com to your allowed domain. var match = origin.match("^(.*)?.wordnik.com(\:[0-9]+)?"); var allowed = (match!==null && match.length > 0); callback(null,allowed); } } }; var subpath = express(); app.use("/docs", subpath); swagger.setAppHandler(subpath); var models = require("./models.js"); var resources = require("./resources.js"); swagger.addModels(models) .addPost(resources.createAppServer) .addPut(resources.updateAppServer) .addGet(resources.getAppServer) .addGet(resources.listAppServer) .addDelete(resources.removeAppServer) .addGet(resources.getServerApplications) .addPost(resources.addApplicationToServer) .addPost(resources.associateApplicationToServer) .addDelete(resources.removeApplicationFromServer) .addPost(resources.createApplication) .addPut(resources.updateApplication) .addGet(resources.getApplication) .addGet(resources.listApplications) .addDelete(resources.removeApplication) swagger.configureDeclaration("appServer", { description : "Operações de Servidor de Aplicação", authorizations : ["basic"], produces: ["application/json"], consumes: ['application/json'] }); swagger.configureDeclaration("application", { description : "Operações de Aplicação", authorizations : ["basic"], produces: ["application/json"], consumes: ['application/json'] }); // set api info swagger.setApiInfo({ title: "Server API", description: "API REST para gerenciar um catálogo de servidores de aplicação assim como as aplicações hospedadas nestes.", contact: "*****@*****.**", }); // Configures the app's base path and api version. swagger.configureSwaggerPaths("", "api-docs", "") swagger.configure("http://server-api-v1.elasticbeanstalk.com", "1.0.0"); // Serve up swagger ui at /docs via static route var docs_handler = express.static(__dirname.replace('/swagger', '') + '/public/swagger-ui'); app.get(/^\/docs(\/.*)?$/, function(req, res, next) { if (req.url === '/docs') { // express static barfs on root url w/o trailing slash res.writeHead(302, { 'Location' : req.url + '/' }); res.end(); return; } // take off leading /docs so that connect locates file correctly req.url = req.url.substr('/docs'.length); return docs_handler(req, res, next); }); }
// .addGet(routes.pets.findByTags) // .addGet(routes.pets.findByStatus) // .addGet(routes.pets.findById) // .addPost(routes.pets.addPet) // .addPut(routes.pets.updatePet) // .addDelete(routes.pets.deletePet) ; // Configures the app's base path and api version. console.log(BASE_URL+API_STRING); swagger.configureDeclaration("users", { description: "User Operations", // authorizations: ["oath2"], produces: ["application/json"] }); // set api info swagger.setApiInfo({ title: "Neo4j-Swagger API", description: "This a sample server built on top of Neo4j, a graph database. The neo4j toggle (<b>top right</b>) controls whether the underlying neo4j cypher queries are returned to the client. Learn more at <a href=\"https://github.com/tinj/node-neo4j-swagger-api\">https://github.com/tinj/node-neo4j-swagger-api</a> TODO: Add graph visualizations! (help wanted)", contact: "*****@*****.**" }); swagger.setAuthorizations({ apiKey: { type: "apiKey", passAs: "header" }
nickname: "findAllNmscs" }, 'action': nmscs.findAll }); swagger.addGet({ 'spec': { description: "Operations about Nmscs", path: "/nmscs/{nmscId}", notes: "Returns an Nmsc based on ID", summary: "Find Nmsc by ID", method: "GET", type: "Nmsc", parameters: [param.path("nmscId", "ID of the Nmsc that needs to be fetched", "string")], errorResponses: [swagger.errors.notFound('Nmsc')], nickname: "getNmscById" }, 'action': nmscs.findById }); //Configures the app's base path and api version. swagger.configureSwaggerPaths("", "api-docs", ""); var swaggerUri = process.env.SWAGGER_URI || 'http://localhost:3000'; swagger.configure(swaggerUri, "1.0.0"); swagger.configureDeclaration('nmscs', { description: 'Operations about Nmscs' });
done => auth.requiresCurrentUser(req, res, done), done => auth.requiresResearcherLogin(req, res, done), done => controller.listUsers(req, res, done) ], next); } }); swagger.addPut({ spec: { path: "/user/{id}/push", summary: "Add push token for user", method: "PUT", type: "Add Push Token", nickname: "addPush", produces: ["application/json"] }, action: (req, res, next) => { async.series([ done => auth.requiresCurrentUser(req, res, done), done => validator.validateAddPush(req, res, done), done => controller.addPush(req, res, done) ], next); } }); swagger.configureDeclaration('user', { description: 'User', authorizations: ['apiKey'], produces: ['application/json'] });
app.get(/^\/docs(\/.*)?$/, function(req, res, next) { if (req.url === '/docs') { // express static barfs on root url w/o trailing slash res.writeHead(302, { 'Location' : req.url + '/' }); res.end(); return; } // take off leading /docs so that connect locates file correctly req.url = req.url.substr('/docs'.length); return docs_handler(req, res, next); }); /** * Final Swagger Settings */ swagger.configureDeclaration("patients", { description : "CRUD Ops for Patients and Ops to answer Questions", produces: ["application/json"] }); swagger.configureDeclaration("accounts", { description : "Account Operations", produces: ["application/json"] }); swagger.configureDeclaration("questions", { description : "Ops about Creating/Getting Questions with Answers", produces: ["application/json"] }); swagger.configureDeclaration("notifications", { description : "Ops about Notifications", produces: ["application/json"]