{"_id":"@revmob/raml-validator","_rev":"52-7792d4244dee21f62dd3395eb07cd6c0","name":"@revmob/raml-validator","dist-tags":{"latest":"0.2.1"},"versions":{"0.1.0":{"name":"@revmob/raml-validator","version":"0.1.0","author":"","license":"ISC","_id":"@revmob/raml-validator@0.1.0","maintainers":[{"name":"hbarcelos","email":"rick.hjpbarcelos@gmail.com"}],"homepage":"https://github.com/revmobads/raml-validator#readme","bugs":{"url":"https://github.com/revmobads/raml-validator/issues"},"ava":{"babel":{"babelrc":true},"files":["**/*.test.js","!dist/**/*"],"require":"babel-register"},"dist":{"shasum":"c303ad75448696213252cc7d2f07e0325125c120","tarball":"https://registry.npmjs.org/@revmob/raml-validator/-/raml-validator-0.1.0.tgz","integrity":"sha512-MmXrssBZESo6AcwDWEPVfFHd0DXnLSkn0Cs5jNNzxVannmZZtFCf2UPRX6KNBhVEBODa/L34x45LDV201JiFnQ==","signatures":[{"sig":"MEUCIQCXscvTaPwftrVktt9wJq092F32a7+IYsytLZi+ipn66wIgVoIwNQFEEhhoY2ZzwcaH2SsU6z2P6RPAVLjAcFfm8AQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"dist/index.js","_from":".","module":"src/index.js","_shasum":"c303ad75448696213252cc7d2f07e0325125c120","gitHead":"19e047358386e70d12b8ede6263e23b2703a6597","scripts":{"lint":"eslint ./src","test":"$(npm bin)/ava","build":"babel ./src -d ./dist","clean":"if [ -d ./dist ]; then find ./dist -maxdepth 1 -exec rm -rf {} +; fi","test:watch":"npm t -- --watch","build:watch":"babel ./src -d ./dist --watch","prepublishOnly":"npm run lint && npm run build && npm run test"},"_npmUser":{"name":"hbarcelos","email":"rick.hjpbarcelos@gmail.com"},"repository":{"url":"git+https://github.com/revmobads/raml-validator.git","type":"git"},"_npmVersion":"3.10.10","description":"Project used for documenting and validating APIs","directories":{},"_nodeVersion":"6.12.1","dependencies":{"osprey":"^0.4.1"},"publishConfig":{"access":"public"},"devDependencies":{"ava":"^0.19.1","eslint":"^3.19.0","express":"^4.15.3","babel-cli":"^6.24.1","supertest":"^3.0.0","babel-eslint":"^7.2.3","babel-preset-env":"^1.5.1","eslint-plugin-node":"^4.2.2","eslint-plugin-import":"^2.3.0","babel-plugin-istanbul":"^4.1.4","eslint-plugin-promise":"^3.5.0","eslint-config-standard":"^10.2.1","eslint-plugin-standard":"^3.0.1","babel-plugin-transform-runtime":"^6.23.0","babel-plugin-syntax-class-properties":"^6.13.0","babel-plugin-transform-class-properties":"^6.24.1"},"_npmOperationalInternal":{"tmp":"tmp/raml-validator-0.1.0.tgz_1512671374921_0.353955039056018","host":"s3://npm-registry-packages"}},"0.2.0":{"name":"@revmob/raml-validator","version":"0.2.0","author":"","license":"ISC","_id":"@revmob/raml-validator@0.2.0","maintainers":[{"name":"guisouza","email":"gui_souza@me.com"},{"name":"hbarcelos","email":"rick.hjpbarcelos@gmail.com"},{"name":"revmobadmin","email":"revmobads@revmob.com"}],"homepage":"https://github.com/revmobads/raml-validator#readme","bugs":{"url":"https://github.com/revmobads/raml-validator/issues"},"ava":{"babel":{"babelrc":true},"files":["**/*.test.js","!dist/**/*"],"require":"babel-register"},"dist":{"shasum":"c689e3594fae8fd49cad2b179dce2f7c40c6d21d","tarball":"https://registry.npmjs.org/@revmob/raml-validator/-/raml-validator-0.2.0.tgz","integrity":"sha512-RuuPv7s8K1PpGCdElkETf/ifQHVTxbF42mLucAs1p7pUmgHEgC74GE/dOs6F0nIITPcVjzn/i4wb2DdDffzdgg==","signatures":[{"sig":"MEUCIG8w2H1it8+6E14YuX32UaWEXBuBr64aBd+PnuPi/PoqAiEAzd9WW9MPPmdbwfSPvT0Eq4Ra4FCd+ZXT/FMog6j+y8I=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"dist/index.js","_from":".","module":"src/index.js","_shasum":"c689e3594fae8fd49cad2b179dce2f7c40c6d21d","gitHead":"7f39e4760c1ca7cf3d9723a0aa624f67b0e1bbfd","scripts":{"lint":"eslint ./src","test":"$(npm bin)/ava","build":"babel ./src -d ./dist","clean":"if [ -d ./dist ]; then find ./dist -maxdepth 1 -exec rm -rf {} +; fi","test:watch":"npm t -- --watch","build:watch":"babel ./src -d ./dist --watch","prepublishOnly":"npm run lint && npm run build && npm run test"},"_npmUser":{"name":"hbarcelos","email":"rick.hjpbarcelos@gmail.com"},"repository":{"url":"git+https://github.com/revmobads/raml-validator.git","type":"git"},"_npmVersion":"3.10.10","description":"Project used for documenting and validating APIs","directories":{},"_nodeVersion":"6.12.1","dependencies":{"osprey":"^0.4.1"},"publishConfig":{"access":"public"},"devDependencies":{"ava":"^0.19.1","eslint":"^3.19.0","express":"^4.15.3","babel-cli":"^6.24.1","supertest":"^3.0.0","babel-eslint":"^7.2.3","babel-preset-env":"^1.5.1","eslint-plugin-node":"^4.2.2","eslint-plugin-import":"^2.3.0","babel-plugin-istanbul":"^4.1.4","eslint-plugin-promise":"^3.5.0","eslint-config-standard":"^10.2.1","eslint-plugin-standard":"^3.0.1","babel-plugin-transform-runtime":"^6.23.0","babel-plugin-syntax-class-properties":"^6.13.0","babel-plugin-transform-class-properties":"^6.24.1"},"_npmOperationalInternal":{"tmp":"tmp/raml-validator-0.2.0.tgz_1512672551954_0.35350339487195015","host":"s3://npm-registry-packages"}},"0.2.1":{"name":"@revmob/raml-validator","version":"0.2.1","author":"","license":"ISC","_id":"@revmob/raml-validator@0.2.1","maintainers":[{"name":"danilojuns","email":"danilojun9@gmail.com"},{"name":"dri9595","email":"me@dri.cool"},{"name":"fabiotoi","email":"fabioptoi@gmail.com"},{"name":"guisouza","email":"gui_souza@me.com"},{"name":"henrique_kenji","email":"henrique.kenji@revmob.com"},{"name":"rafaelmenegazzi","email":"rafael.menegazzi.usp@gmail.com"},{"name":"revmobadmin","email":"revmobads@revmob.com"},{"name":"tech-revmob","email":"tech@revmob.com"}],"homepage":"https://github.com/revmobads/raml-validator#readme","bugs":{"url":"https://github.com/revmobads/raml-validator/issues"},"ava":{"babel":{"babelrc":true},"files":["**/*.test.js","!dist/**/*"],"require":"babel-register"},"dist":{"shasum":"5d7c01c00335c094655e074e077f63d19aa008be","tarball":"https://registry.npmjs.org/@revmob/raml-validator/-/raml-validator-0.2.1.tgz","fileCount":11,"integrity":"sha512-b0NhEhTa0iLeXsQC0hQejeKk1Yyd+c3B38BL4BWsrUY5X8m8pmF5rDVKr4xgbzn0DloqSWBGRxTZ+wJNPkiU3Q==","signatures":[{"sig":"MEUCIE+8O18GebxTr7uuGK8Jedxf5iXyzsFJiKAFcQ4+xKUMAiEA/r1uRtBm6iks9wJOMLCBlJFwfgZn3u9VZL+ryzvbucc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":37668,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbrqI1CRA9TVsSAnZWagAAapMP/1VSSiw+bT9640sm9lNz\nQiQrroJGb/V/Z84mfKt5YlczudO3BvQ/dRQlXmMVvfqQnwe8NY6nML2VYTOb\nM9qKLJ8757/3SiZX/9rkLNk49ctjIKCAmjXXy1KbXRTVL0lPr0cE2NPkIsbA\nxntbTa++FtxfUcQuuedBPyjWkhg5t3HVT0/KbhbxH4VEZ6Uv0JbctzR6qlyg\nZDI77mfKaBgacRvatYGhspgpVO6Cx1KJ74ZVuhjtg2QzfItN/iWr2LeHt0xr\nm6Zv0rAfeMX1nBkF6/O0bwYGfdwM3c7pSUBxadrI8wC97HvoleqVPyX/XEN0\na2WfWwOev+y0BOoOy2XFLSMzFtzu7kmnnj4yHSKLIqAwnqSxC/DzBvpZ0XoB\n6IOHpUdlM5wDngd/nj+adrRQkBkuQN6cclRIRZ3OO9jbp8cEgnH2inMQag30\nthgZJ1VZqsaJPlCJUfcqDTNEQjHcH70+U8NoGBwCSx7+ArYY5p9MOU+cQfur\nc6xx0mr6bR2Xh8m5MIX+Q2CLeylswEx6PoQeLSurU4ryy0WijUIMCCCsgrMC\n/T3byUUcF6qdTrL52fjaWMLpA/Z6feHPI5Llk8+VUDrxG3mWOaDNqp1qUPXB\n7F6LcEr059/4SAt9rd/i/fOfljot9Yaf21Mw/gC5+qLguilF79mpyDGxV8ba\nO8xm\r\n=A8bg\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","module":"src/index.js","gitHead":"de443ce9daf4476ef1e72913e292444140aee518","scripts":{"lint":"eslint ./src","test":"$(npm bin)/ava","build":"babel ./src -d ./dist","clean":"if [ -d ./dist ]; then find ./dist -maxdepth 1 -exec rm -rf {} +; fi","test:watch":"npm t -- --watch","build:watch":"babel ./src -d ./dist --watch","prepublishOnly":"npm run lint && npm run build && npm run test"},"_npmUser":{"name":"fabiotoi","email":"fabioptoi@gmail.com"},"repository":{"url":"git+https://github.com/revmobads/raml-validator.git","type":"git"},"_npmVersion":"6.4.1","description":"Project used for documenting and validating APIs","directories":{},"_nodeVersion":"8.12.0","dependencies":{"osprey":"~0.4.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"ava":"^0.19.1","eslint":"^3.19.0","express":"^4.15.3","babel-cli":"^6.24.1","supertest":"^3.0.0","babel-eslint":"^7.2.3","babel-preset-env":"^1.5.1","eslint-plugin-node":"^4.2.2","eslint-plugin-import":"^2.3.0","babel-plugin-istanbul":"^4.1.4","eslint-plugin-promise":"^3.5.0","eslint-config-standard":"^10.2.1","eslint-plugin-standard":"^3.0.1","babel-plugin-transform-runtime":"^6.23.0","babel-plugin-syntax-class-properties":"^6.13.0","babel-plugin-transform-class-properties":"^6.24.1"},"_npmOperationalInternal":{"tmp":"tmp/raml-validator_0.2.1_1538171444706_0.7634737578281579","host":"s3://npm-registry-packages"}}},"time":{"created":"2017-12-07T18:29:35.956Z","modified":"2026-03-06T15:30:42.042Z","0.1.0":"2017-12-07T18:29:35.956Z","0.2.0":"2017-12-07T18:49:13.112Z","0.2.1":"2018-09-28T21:50:44.915Z"},"bugs":{"url":"https://github.com/revmobads/raml-validator/issues"},"license":"ISC","homepage":"https://github.com/revmobads/raml-validator#readme","repository":{"url":"git+https://github.com/revmobads/raml-validator.git","type":"git"},"description":"Project used for documenting and validating APIs","maintainers":[{"email":"rafael@artnic.io","name":"artnic"},{"email":"lucas.souza@infleux.co","name":"inf.simstm"},{"email":"igor.correa@infleux.co","name":"igor.correa"}],"readme":"# RAML Validator\n\nWelcome to a new era. An era where we, revmobers, will document every API! 😎\n\n## Why\nBecause loggin the input payload and response json to understand what's going on sucks 😭\n\nTo help us, we will use RAML (**REST**ful **A**PI **M**odeling **L**anguage) to document our code,\nand complementary libs ([osprey](https://github.com/mulesoft/osprey)) to validate requests against our doc.\n\n## What is does\n\nBefore your request reaches your controllers, raml express middleware will:\n - intercept the request;\n - check where it was going to;\n - validate them against a raml file;\n - return an error if the request payload doesn't meet the criteria\n\n## Default Error Handler\n\nThe default error handler will return array of error:\n\n```raml\n400:\n  body:\n    type: object\n    properties:\n      errors: error[]\n    examples:\n      invalidResponse:\n        errors: [{\n            message: 'Validation Error!',\n            details: {\n                age: 'Missing required property: age',\n                name: 'Invalid type, expected string'\n            }\n        }]\n```\n\nThe response:\n```json\n{\n    \"errors\": [{\n        \"message\": \"Validation Error!\",\n        \"details\": {\n            \"age\": \"Missing required property: age\",\n            \"name\": \"Invalid type, expected string\"\n        }\n    }]\n}\n```\n\n## Installation\n\nJust do a:\n\n```bash\nnpm install --save @revmob/raml-validator\n```\n\n## How to use\n\nTo see an example, just access `examples/express.js`.\nThe default middleware is created Asyncronously, using promise.\nThat being said, just pass your Express instance to raml-validator like this:\n**ALWAYS** define raml-validator middleware **BEFORE** your routes, otherwise it won't validate your request before your controller processing it\n\n``` javascript\n\nimport ramlValidator from 'raml-validator'\n\nconst config = {\n  path: 'path/to/api.raml'\n}\n\nconst app = express()\n\nramlValidator(config)\n  .then(({ validator, errorHandler, finalErrorHandler }) =>\n    app.use(validator) // MUST come before your routes\n     .use(errorHandler) // MUST come before your routes\n     .use(myRoutes)\n     .use(finalErrorHandler) // SHOULD be the last\n   )\n  .then(app => app.listen(8080))\n\n```\n\n## Configuration\n\n### Osprey\n\nThe config object accepts the following:\n\n``` javascript\nconst config = {\n  path: 'path/to/api.raml', //ABSOLUTE path to raml file\n  customErrorHandler: function (req, res, errors, stack) {\n    // A custom Error Handler, where you can process invalid requests your way.\n  },\n  server: {\n    cors: true\n  },\n  security: {\n    basicAuth: {\n      validateUser: (user, password, done) => {\n        if (user === MY_USER && password === MY_PASSWORD) {\n          return done(null, true)\n        }\n\n        return done(null, false)\n      }\n    }\n  }\n}\n\n```\n\nFor more details, please refer to osprey documentation for [server](https://github.com/mulesoft/osprey/blob/master/README.md#server-resource-handling) and [security](https://github.com/mulesoft/osprey/blob/master/README.md#security).\n\n### Additional configuration\n\nAs of `0.2.0`, this package expose the `hooks` configuration.\n\nThis allows you to intercept RAML errors. It's specially useful for logging:\n\nThere are 2 different hooks:\n\n- `onValidationError :: (errors: Error[], req: HttpRequest, res: HttpResponse) -> void`: will be called if RAML validation fails.\n- `onUnknownError :: (error: Error, req: HttpRequest, res: HttpResponse) -> void`: will be called if something goes wrong with the validation setup.\n\n``` javascript\nconst config = {\n  path: 'path/to/api.raml',\n  server: {\n    cors: true\n  },\n  security: {\n    basicAuth: {\n      validateUser: (user, password, done) => {\n        if (user === MY_USER && password === MY_PASSWORD) {\n          return done(null, true)\n        }\n\n        return done(null, false)\n      }\n    }\n  },\n  hooks: {\n    onValidationError: (errors, req, res) => {\n      errors.map(error => console.log(error))\n    },\n    onUnknownError: (error, req, res) => {\n      console.log(error)\n    }\n  }\n}\n\n```\n\n## I am a hipster and don't use Express.js\n\nIf you're not using `express.js` server, feel free to contribute by PRing a new raml middleware! :)\n\n","readmeFilename":"README.md"}