Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sans-server-swagger

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sans-server-swagger - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

bin/schema.js

25

bin/middleware.js

@@ -23,12 +23,16 @@ /**

const path = require('path');
const Router = require('sans-server-router');
const schema = require('./schema');
const validate = require('./validate');
const yaml = require('js-yaml');
module.exports = middleware;
const acceptedMethods = { get: true, post: true, put: true, delete: true, options: true, head: true, patch: true };
function middleware(config, router) {
module.exports = function (configuration, router) {
const config = schema.normalize(configuration);
let ready = false;
// define the router if not yet defined
if (!router) router = Router({ paramFormat: 'handlebar' });
// produce the swagger object

@@ -175,3 +179,3 @@ const swagger = /\.json$/.test(config.swagger)

? swagger.produces[0]
: examples && Object.keys(examples)[0]; // TODO: default to produces first value
: examples && Object.keys(examples)[0];
if (examples && examples.hasOwnProperty(accept)) {

@@ -207,14 +211,19 @@ res.send(examples[accept]);

// return the middleware function - this essentially makes sure the router is ready before processing router middleware
return function byuApi(req, res, next) {
return function swaggerRouter(req, res, next) {
const server = this;
function execute() {
router.call(server, req, res, next);
}
// if the path does not match the base path then exit middleware
if (!config.ignoreBasePath && !rxBasepath.test(req.path)) {
this.log('path', 'The request path does not fall within the basePath: ' + req.url);
next();
execute();
} else {
ready ? next() : promise.then(() => next());
ready ? execute() : promise.then(() => execute());
}
};
}
};

@@ -221,0 +230,0 @@ /**

@@ -19,2 +19,2 @@ /**

module.exports = require('./bin/server');
module.exports = require('./bin/schema');
{
"name": "sans-server-swagger",
"version": "0.0.2",
"version": "0.0.3",
"description": "Sans-server middleware that uses swagger documents to validate requests and responses and to produce mocks.",

@@ -28,4 +28,3 @@ "main": "index.js",

"sans-server": "^0.0.22",
"sans-server-router": "^0.0.8",
"uuid": "^3.0.1"
"sans-server-router": "^0.0.8"
},

@@ -32,0 +31,0 @@ "repository": {

@@ -1,2 +0,2 @@

# node-byuapi-framework
# sans-server-swagger

@@ -10,13 +10,22 @@ A serverless framework that uses Swagger documents to produce web service schemas. Easy to integrate into unit tests, servers, AWS lambdas, etc.

```js
const byuApi = require('node-byuapi-framework');
const Server = require('sans-server');
const Swagger = require('sans-server-swagger');
const Router = require('sans-server-router');
// create an API instance
const api = byuApi({
// define the server
const server = Server();
// define the swagger middleware with a router
const swaggerMiddleware = Swagger(router, {
controllers: './controllers',
development: true,
router: Router({ paramFormat: 'handlebar' }),
swagger: './swagger.json'
});
// make a request against the API
api.request({ method: 'GET', path: '/v1/path/to/call' })
// use the swagger middleware
server.use(swaggerMiddleware);
// make a request against the server
server.request({ method: 'GET', path: '/v1/path/to/call' })
.then(function(res) {

@@ -23,0 +32,0 @@ console.log(res.statusCode);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc