express-joi-simple
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "express-joi-simple", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "", | ||
@@ -20,2 +20,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"body-parser": "^1.18.3", | ||
"joi-express": "^1.0.3", | ||
@@ -26,2 +27,3 @@ "swagger-json": "^1.3.4", | ||
"devDependencies": { | ||
"@types/body-parser": "^1.17.0", | ||
"@types/express": "^4.16.0", | ||
@@ -28,0 +30,0 @@ "@types/joi": "^13.4.2", |
@@ -10,11 +10,12 @@ # Express + Joi + Swagger | ||
## Example | ||
## Minimal Working Example | ||
``` | ||
import * as express from 'express'; | ||
import { router } from './router'; | ||
import * as joi from 'joi'; | ||
import { Doc, Validate } from 'express-joi-simple'; | ||
import * as BodyParser from 'body-parser'; | ||
import { Doc, Validate, RequestHandler } from 'express-joi-simple'; | ||
const app = express(); | ||
app.use(BodyParser.json()); | ||
@@ -24,7 +25,8 @@ const schema = { | ||
test1: joi.string().required() | ||
} | ||
}, | ||
model: 'Register' | ||
} | ||
// Note middleware here | ||
app.post('register',Validate(schema), (req: any, res: any) => { | ||
app.post('register', Validate(schema), (req: any, res: any) => { | ||
res.json({ | ||
@@ -35,3 +37,3 @@ message: 'register' | ||
app.use('/login', router); | ||
app.use(RequestHandler); | ||
@@ -44,2 +46,3 @@ app.listen(3000, () => { | ||
Use require instead of import for plain Javascript. | ||
Use require instead of import for plain Javascript. | ||
More complicated example you can find in example folder. |
@@ -21,4 +21,9 @@ | ||
} | ||
} else if (middleware.name === 'router') { // router middleware | ||
} else if (middleware.name === 'router' && middleware.handle.stack) { // router middleware | ||
middleware.handle.stack.forEach((handler: any) => { | ||
if(!handler.route) { | ||
return; | ||
} | ||
const { path, stack } = handler.route; | ||
@@ -39,3 +44,3 @@ if (path) { | ||
app.use('/', SwaggerUi.serve, SwaggerUi.setup(JSON.parse(swaggerDocument))); | ||
app.use('/doc', SwaggerUi.serve, SwaggerUi.setup(JSON.parse(swaggerDocument))); | ||
} |
import * as express from 'express'; | ||
import { router } from './router'; | ||
import * as BodyParser from 'body-parser'; | ||
import * as joi from 'joi'; | ||
import { Doc, Validate } from '../index'; | ||
import { Doc, Validate, RequestHandler } from '../index'; | ||
const app = express(); | ||
app.use(BodyParser.json()); | ||
app.use(RequestHandler); | ||
const schema = { | ||
body: { | ||
test1: joi.string().required() | ||
} | ||
}, | ||
model: 'Register' | ||
} | ||
app.post('register',Validate(schema), (req: any, res: any) => { | ||
app.post('/register', Validate(schema), (req: any, res: any) => { | ||
res.json({ | ||
@@ -22,4 +27,5 @@ message: 'register' | ||
app.use(RequestHandler); | ||
app.listen(3000, () => { | ||
Doc(app); | ||
}) |
@@ -6,7 +6,7 @@ import { Router } from 'express'; | ||
export const router: any = Router(); | ||
const schema = { | ||
body: { | ||
test1: joi.string().required() | ||
} | ||
}, | ||
model: 'Login' | ||
} | ||
@@ -13,0 +13,0 @@ |
export * from './Doc'; | ||
export * from './Validate'; | ||
export * from './RequestHandler'; |
import * as Joi from 'joi-express'; | ||
export function Validate(schema: any) { | ||
return Joi(schema); | ||
} | ||
export const Validate = Joi; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16887
25
252
44
4
5
+ Addedbody-parser@^1.18.3
+ Addedbody-parser@1.20.3(transitive)
+ Addedbytes@3.1.2(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedcontent-type@1.0.5(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddepd@2.0.0(transitive)
+ Addeddestroy@1.2.0(transitive)
+ Addedee-first@1.1.1(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.1.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhttp-errors@2.0.0(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedmedia-typer@0.3.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedms@2.0.0(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedon-finished@2.4.1(transitive)
+ Addedqs@6.13.0(transitive)
+ Addedraw-body@2.5.2(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedsetprototypeof@1.2.0(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedstatuses@2.0.1(transitive)
+ Addedtoidentifier@1.0.1(transitive)
+ Addedtype-is@1.6.18(transitive)
+ Addedunpipe@1.0.0(transitive)