From 7943376d6ffae75a6e5acfe5efefc9d73a7ff944 Mon Sep 17 00:00:00 2001 From: Carmine DiMascio Date: Wed, 20 Mar 2019 23:37:16 -0400 Subject: [PATCH] update readme --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2eb4b7cd..6b26d4b0 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,13 @@ new OpenApiMiddleware({ apiSpecPath: './openapi.yaml', validateApiDoc: true, // default enableObjectCoercion: true, // should be default + errorTransform: v => ({ // optional error transform + statusCode: v.status, // the http status to return + error: { // the custom error object + code: v.status, + message: v.errors[0].message, + }, + }), }).install(app); ``` @@ -57,10 +64,7 @@ new OpenApiMiddleware({ }).install(app); app.get('/v1/pets', function(req, res, next) { - res.json([ - { id: 1, name: 'max' }, - { id: 2, name: 'mini' }, - ]); + res.json([{ id: 1, name: 'max' }, { id: 2, name: 'mini' }]); }); app.post('/v1/pets', function(req, res, next) { @@ -72,7 +76,7 @@ app.post('/v1/pets', function(req, res, next) { app.get('/v1/pets/:id', function(req, res, next) { res.json({ id: req.params.id, - name: 'sparky' + name: 'sparky', }); });