{"_id":"@dschulmeis/restify-openapi-enforcer-middleware","_rev":"3-5e63b80aab9fbe5fd8c8f7e5b12ea917","name":"@dschulmeis/restify-openapi-enforcer-middleware","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@dschulmeis/restify-openapi-enforcer-middleware","version":"1.0.0","description":"Tiny middleware for Restify to validate requests and responses with openapi-enforcer","author":{"name":"Dennis Schulmeister-Zimolong"},"license":"BSD-2-Clause","repository":{"type":"git","url":"git+https://github.com/DennisSchulmeister/restify-openapi-enforcer-middleware.git"},"bugs":{"url":"https://github.com/DennisSchulmeister/restify-openapi-enforcer-middleware/issues"},"homepage":"https://github.com/DennisSchulmeister/restify-openapi-enforcer-middleware#readme","keywords":["restify","openapi","middleware","rest","webservice"],"main":"index.js","type":"module","dependencies":{"openapi-enforcer":"^1.17.0","restify":"^8.6.1"},"scripts":{"do-publish":"npm publish --access=public"},"gitHead":"89c2086e3527d7191ea95dabbf9f9f0430fbc01d","_id":"@dschulmeis/restify-openapi-enforcer-middleware@1.0.0","_nodeVersion":"14.18.1","_npmVersion":"6.14.15","dist":{"integrity":"sha512-jpYg67yqi/RJ8hUKSSKYkI8j9ORbDreglTwSgaBj8W6QKjYxZTaY/tqZfl7Esbgetzv0/Mftm88S/2OGiEOtOw==","shasum":"42d5980a34fdd2798eb6a5aa7ca0b168ebfbf39d","tarball":"https://registry.npmjs.org/@dschulmeis/restify-openapi-enforcer-middleware/-/restify-openapi-enforcer-middleware-1.0.0.tgz","fileCount":4,"unpackedSize":10303,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiIDbiACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmozQhAAkTDBMKgQfY8DviEsOC5+0fw+hhghi2RouxEnsT1wztuMYKmc\r\ncaKlcMfproCah0tMAI7K3GxYM6XJx9NsSz/dE03P+yMMmPtk/mfdpuNL7Wjy\r\nXzednyTOkzRNIig85o/9JOcQdBiDhR4H8CrMhb3IsZMQv9TLj1TOiAdfZitT\r\nDmGdv3sbkacNrPmGepyEt36zEoq1n4QDwpHATZuNxmbv8kgR1rhFUjaXgbs0\r\nbKuJ+QVwJWHunQ5E7Qw4C3/S5AXmkH6ZuGTzfS4kLB3oVqZxv7s1+tx/UonA\r\nFpr7YBMtkvVfSKhMtdPhZjwlETC7w54IttmoruCOVGZStim2rFXI28qbtYLB\r\n2Nn8q+SMLk+LCwSbL0JsyCdYL3+SM16asJ17f62I6NS8jZaRQ0MJveVJRToz\r\nly2fLXQJMY6H5s1RueZzKZI5f5KIIGGsgR+C32jGDEyV4jy2euFpGnc2xxcN\r\ndtGurLtQJwdyOS7PFkgL2SZ4f+5cEx512F5zAuKDmHwRch1IAiu9I46eeDwQ\r\nnN+yiaPAPfvo965h536xMqHF8MlHNecI9YjVgp0sMXtS3udIXRRHpBPIb/ea\r\ne0HxMV1eP5aHsBac7pNfp/4KldCV+pFQsCKBBULG1yvp+I9Ms0abADdON41O\r\n0L5BWBgLGa5kjGJEJa1PK3iqz+g0Z4QbVTc=\r\n=oQjW\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICVOdNNOmOOUJHNImkQvgiP9hYI/P4tzDTo8PFhx7hlpAiBoXxu8wkSDMedvtdFxnTOeuJIfJvy2sqv+iCZ1y5JeVg=="}]},"_npmUser":{"name":"dschulmeis","email":"npmjs.com@windows3.de"},"directories":{},"maintainers":[{"name":"dschulmeis","email":"npmjs.com@windows3.de"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/restify-openapi-enforcer-middleware_1.0.0_1646278370497_0.9754027712072635"},"_hasShrinkwrap":false},"1.0.1":{"name":"@dschulmeis/restify-openapi-enforcer-middleware","version":"1.0.1","description":"Tiny middleware for Restify to validate requests and responses with openapi-enforcer","author":{"name":"Dennis Schulmeister-Zimolong"},"license":"BSD-2-Clause","repository":{"type":"git","url":"git+https://github.com/DennisSchulmeister/restify-openapi-enforcer-middleware.git"},"bugs":{"url":"https://github.com/DennisSchulmeister/restify-openapi-enforcer-middleware/issues"},"homepage":"https://github.com/DennisSchulmeister/restify-openapi-enforcer-middleware#readme","keywords":["restify","openapi","middleware","rest","webservice"],"main":"index.js","type":"module","dependencies":{"openapi-enforcer":"^1.17.0","restify":"^8.6.1"},"scripts":{"do-publish":"npm publish --access=public"},"gitHead":"f3ba5299e83722f5dd540849096245a074f890a8","_id":"@dschulmeis/restify-openapi-enforcer-middleware@1.0.1","_nodeVersion":"14.18.1","_npmVersion":"6.14.15","dist":{"integrity":"sha512-SGnDESmyeooj19/NDYe6Mk5YxX7UAMr+r/pCvYRzfsj7RRrL77IUcVUe8MdtNSrIu946lw9UBW69WQHE9CHtTQ==","shasum":"5e49af04ab7e92ca425723c48f376ef93ea55ed7","tarball":"https://registry.npmjs.org/@dschulmeis/restify-openapi-enforcer-middleware/-/restify-openapi-enforcer-middleware-1.0.1.tgz","fileCount":4,"unpackedSize":10587,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiIDiMACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpQuQ/+MZET3x+3CEwp4MXa3xLrZFK0h5gw/Nja9s1+IWWEqIHZpuLo\r\nn+z/EpZENKcvrrSHE7lhaVvAZLwZDtQIeuMF1FYhluaM3R1JfbDJSsliuuOI\r\naCeGZ0s+LDJh1XGk2WdrmQjug6pvhKhZDV/wGOMGyuT2WGHbgOW56ouwvRSG\r\nlBsuKZ8B00wL8Z9HcnFumooCcQhwgnysFRIcYj0WXNX/3R5NyfopmmCsEf0U\r\nerUHlf4lfwRKZOzdjeDpVLq+6poYg+qK5GbfUFYppqmFE60kH4KqSmfxwiZh\r\nwrZBHBJ2uWBz9jsgnNZh6oeU6fUNnULr3nIy8YXbLgfbsyZMSrImiD8AU4Ew\r\nXPpVj+X7d1M+WokQXT802YnojD/oNzxMYdnNQnpc/qzBEIHQ7aY0Op15r6eo\r\nrPwvs0HTjpC7PGbltp7ikRfEiIOHpkYse55GmgwN2stgmyIbIaYWvrdx0OPb\r\nRrCFZygrRPbgI8KyIq39rRv7GZJpei/lVNwdQEaznB1sSdAtl9QQOopybbQu\r\nWBJ+q/ne4jRBGl9c5j6njlDm0SWLpSh9olI5NlBArUF8QOQn0JwZZiHjTbcd\r\nitJ3o+sDxnOt8tGecuytQo5dXyBLZKsZAuvkGUKusZlxQhzyQ6fQrzVh5k9G\r\nnaSItIp2egx3z286w/fzfNinBtY0FoXETbE=\r\n=9zwG\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDVwwJLvPgzACXUbe3wCD1A6nCrSlRvffNt8D+BTOYKHAIhANH9ILwwsPtmWSg0PYvHUMSpxLqwPuPYOQCIB9nMIdJ+"}]},"_npmUser":{"name":"dschulmeis","email":"npmjs.com@windows3.de"},"directories":{},"maintainers":[{"name":"dschulmeis","email":"npmjs.com@windows3.de"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/restify-openapi-enforcer-middleware_1.0.1_1646278796546_0.2745610858530756"},"_hasShrinkwrap":false},"1.0.2":{"name":"@dschulmeis/restify-openapi-enforcer-middleware","version":"1.0.2","description":"Tiny middleware for Restify to validate requests and responses with openapi-enforcer","author":{"name":"Dennis Schulmeister-Zimolong"},"license":"BSD-2-Clause","repository":{"type":"git","url":"git+https://github.com/DennisSchulmeister/restify-openapi-enforcer-middleware.git"},"bugs":{"url":"https://github.com/DennisSchulmeister/restify-openapi-enforcer-middleware/issues"},"homepage":"https://github.com/DennisSchulmeister/restify-openapi-enforcer-middleware#readme","keywords":["restify","openapi","middleware","rest","webservice"],"main":"index.js","type":"module","dependencies":{"openapi-enforcer":"^1.17.0","restify":"^8.6.1"},"scripts":{"do-publish":"npm publish --access=public"},"gitHead":"eee2da43b81b3153da58fa3976f5be955701d66d","_id":"@dschulmeis/restify-openapi-enforcer-middleware@1.0.2","_nodeVersion":"14.18.1","_npmVersion":"6.14.15","dist":{"integrity":"sha512-Exr1Pf3/PZLm+g3Og08kafrR19Y8/ijdSUSCwxyk1bFduvVz0YqR2TsD83BF/mOAJbmdemF9cAu+amknFBNXLw==","shasum":"7817fe838651b33af8c6880e749928bdd24a4bd9","tarball":"https://registry.npmjs.org/@dschulmeis/restify-openapi-enforcer-middleware/-/restify-openapi-enforcer-middleware-1.0.2.tgz","fileCount":4,"unpackedSize":10729,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiIDyNACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqN9g/+LKWvgnAdzOWODpmDrth+FDUAu2EmzY3PFDuWgIBpHjzJWFAU\r\npFF/mBHMe55uQMArG72mfd4J5PDOgM0GudZxFinY7uSPReGGERLasTfGXJTX\r\n9Bx5NoCy2rWb988obWiroGjLAOKaDeoVHyIMBwA2Ob/mOUN0bc1M322qmSTM\r\n4RjA675qflmElGH90JuQvuR0Dxga4iprNsLzLlzQ+AXbOZsXFNSD7vbjW921\r\nqpeWC4+qjA/pExwzGt0aM/Qm7N30XZWfCMpzuXp63Lx+Miw1Fal/eZFqK3xE\r\nZKQKlI8ozU2zasURUO0YPwu7CtSOA+h88rvUSId/olqUmq4ux2VuGPtK7Ce6\r\nQoATPY5NnFZD1lJwJqBa8E9vzndPxWvxL6jZ5HKQ4w/iBAOWxexK963MnzKA\r\nYiFp5+jdzpBWvOoRj4c4qEte4+BQ7J5vVuwBzgnfmk4vrgjdR1T7gQnFyc9Z\r\naEDEGo2Ka0IrMzGo3OQEu8PI1zoOKRrRU9P/XKuTAcwVSprXkymjoT4gW7r6\r\n7wi4quZrnZaoY3eCATDSO3SEteX7C4QJyYVEvoHXuUQ8XxRshWBjgHilLKEZ\r\nrYyNz7zmqyVqAe8PEXrOByWaKliZAXfTF80gax3pMBUtcPEtrPe2V5jrNVg5\r\nvfNihyrsNDK11pawqemTomi5sZIrpnhiBp4=\r\n=BEbz\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCoIEQ4rZ3lngHMgIegr3ahi2ITjQiT1UYrA4eUH3URgQIhAOhQw4sUNGQg9Ou1i2hyHyd9nIZaLohdPG8g7WW4LVvk"}]},"_npmUser":{"name":"dschulmeis","email":"npmjs.com@windows3.de"},"directories":{},"maintainers":[{"name":"dschulmeis","email":"npmjs.com@windows3.de"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/restify-openapi-enforcer-middleware_1.0.2_1646279820985_0.4276632025885456"},"_hasShrinkwrap":false}},"time":{"created":"2022-03-03T03:32:50.445Z","1.0.0":"2022-03-03T03:32:50.649Z","modified":"2022-04-05T05:44:15.381Z","1.0.1":"2022-03-03T03:39:56.749Z","1.0.2":"2022-03-03T03:57:01.132Z"},"maintainers":[{"name":"dschulmeis","email":"npmjs.com@windows3.de"}],"description":"Tiny middleware for Restify to validate requests and responses with openapi-enforcer","homepage":"https://github.com/DennisSchulmeister/restify-openapi-enforcer-middleware#readme","keywords":["restify","openapi","middleware","rest","webservice"],"repository":{"type":"git","url":"git+https://github.com/DennisSchulmeister/restify-openapi-enforcer-middleware.git"},"author":{"name":"Dennis Schulmeister-Zimolong"},"bugs":{"url":"https://github.com/DennisSchulmeister/restify-openapi-enforcer-middleware/issues"},"license":"BSD-2-Clause","readme":"# Restify Middleware for OpenAPI Enforcer\n\n## Short description\n\nThis is a tiny package to provide a middleware for [Restify](http://restify.com/)\nto validate incomming HTTP requests and their responses against an OpenAPI\nspecification. Basically this is a replacement for the similar\n[Express.js](https://expressjs.com/) middleware\n[openapi-enforcer-middleware](https://www.npmjs.com/package/openapi-enforcer-middleware),\nalbeit much simpler and a bit less powerful.\n\nThe problem with `openapi-enforder-middleware` (or Restify, if you will) is\nthat while both Express.js and Restify use Sinatra-style handlers and middleware,\nthe request and response obejcts are not compatible. In theory it would be possible\nto wrap the `openapi-enforder-middleware` in a wrapper function that patches\nthe request object as needed, but there is no guarantee that this will remain\nworking in the future, as both projects could change anytime.\n\nSo the solution here is to provide a small middleware specificaly for Restify.\nThe goal is only to validate requests and responses. So I didn't bother to\nactually port the Express.js middleware over, but just wrote a small function\nmyself using the `openapi-enforcer` API.\n\n## Why?\n\nYou can skip this and jump right to the usage example, if you are not interested\nin the background musings.\n\nI am using this middleware in my lectures for \"Distributed Systems\" in the\nbachelor study course \"Business Computer Science\" of \"Corporate State University\nBaden-Württemberg Karlsruhe (DHBW Karlsruhe)\". I chose Restify over Express.js\nas it is more tailored torwards REST webservices and I like the concept of the\npre and post handlers as well as how content negotation and errors are handled.\nAll in all this allows for a very easy means to start developing one's own\nREST webservices without much magic, which is good if you are teaching junior\nstudents.\n\nPart of the lecture is to demonstrate a \"design first\" approach where first\nthe OpenAPI specification is written and the webservice is then implemented\naccordingly. Originaly I was even hoping to generete the server-code from\nthe OpenAPI specification. And while this is possible, all solutions proved\nnon-satisfying. There are almost no generators that output node.js/javascript\ncode and if there are, the code is of poor quality. Not the kind of spagethi\ncode I like to teach my students. So I decided to teach writing the server\nby hand, which actually is not hard at all. But then of course it would be\nuseful to benefit from the OpenAPI specification more than it being merely\na blueprint documentation. So the least thing is, that requests and responses\nneed to be automatically verified.\n\n`openapi-enforder-middleware` and others offer auto-wiring of controllers\nand handler methods. But this requires to disclose implementation details\n(the names of the controllers and their methods) in the OpenAPI specification,\nwhich really should be a binding and public documentation. But even if we\naccept that, there is really no benefit. What's the win if I don't need to\nrepeat the URL patterns in my JavaScript code, but I need to repeat my\ncontroller and method names in the OpenAPI specification? Or I keep the\nspecification clean and retype the URL patterns in JavaScript. In any case,\nthe two are not independent of each other and changing the one requires\nupdating the other. That's why I decided to not port these kind of features\nover from the original middleware.\n\nThe same goes for generating a HTML api documentation. In a real-world\nmicroservice architecture this would be handled by a dedicated documentation\nor API portal server anyway. So let's not carry that weight around. Remember,\nthe less code, the less bugs and thus less frustration.\n\n## Usage\n\nThe middleware expects an already initialized `OpenApiEnforcer` instance,\nso that you have a chance to customize the object or handle warnings and\nerrors from reading the OpenAPI specification file. The following example\nshows how to do this:\n\n```javascript\nimport OpenApiEnforcer from \"openapi-enforcer\";\nimport OpenApiEnforcerMiddleware from \"@dschulmeis/restify-openapi-enforcer-middleware\";\n\n// Replacement for node.js dirname in ES6 modules\nimport path from \"path\";\nimport { fileURLToPath } from \"url\";\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\n// Create restify server and populate it with plugins, middleware and routes\n// as usual\nconst server = restify.createServer();\n\n// Use OpenAPI Enforcer Middleware to validate requests and responses\nconst openApiFile = path.relative(\"\", path.join(__dirname, \"api\", \"openapi.yaml\"));\nconst openApiValidation = await OpenApiEnforcer(openApiFile, {fullResult: true});\n\nconst openApiEnforcer = await OpenApiEnforcer(openApiFile, {\n    hideWarnings: true,\n    componentOptions: {\n        production: process.env.NODE_ENV === \"production\"\n    },\n});\n\nserver.use(OpenApiEnforcerMiddleware(openApiEnforcer));\n\n// Example for a validated route\nserver.post(\"/address\", (req, res, next) => {\n    res.status(201);\n    res.header(\"Location\", \"...\");\n\n    // Use sendResult() instead of send()!\n    res.sendResult({\n        // ...\n    });\n});\n\n// Actually start the server and log errors and warnings from reading in the\n// OpenAPI specifcation file\nserver.listen(config.port, config.host, function() {\n    console.log(\"Server started!\");\n    console.log(`OpenAPI-Spezifikation: ${openApiFile}`)\n\n    if (openApiValidation.error) {\n        console.error(`${openApiValidation.error}\\n`);\n    }\n\n    if (openApiValidation.warning) {\n        console.warn(`${openApiValidation.warning}\\n`);\n    }\n\n    console.log();\n});\n```\n\n## Copyright\n\n[restify-openapi-enforcer-middleware](https://www.github.com/DennisSchulmeister/restify-openapi-enforcer-middleware) <br/>\n© 2022 Dennis Schulmeister-Zimolong <dennis@pingu-mail.de> <br/>\nLicensed under the 2-Clause BSD License.\n","readmeFilename":"README.md"}