From a2956210793d346f25643a9ba013fe39e53478c6 Mon Sep 17 00:00:00 2001 From: Vic <74506415+victorioxd@users.noreply.github.com> Date: Thu, 7 Jul 2022 16:42:27 +0200 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9E=95=20Add=20fastify=20swagger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 + yarn.lock | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 208 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index feafbe9..62265a8 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "scripts": { "start": "node dist/server.js", "lint": "eslint src", + "lint:fix": "eslint src --fix", "build": "tsc", "dev": "yarn build && yarn start", "test": "tap --no-coverage" @@ -16,6 +17,7 @@ "dependencies": { "@fastify/cors": "7.0.0", "@fastify/mongodb": "5.0.0", + "@fastify/swagger": "6.x", "dotenv": "16.0.1", "fastify": "3.29.0" }, diff --git a/yarn.lock b/yarn.lock index 8f974bc..98aa548 100644 --- a/yarn.lock +++ b/yarn.lock @@ -392,6 +392,31 @@ fastify-plugin "^3.0.0" mongodb "^4.0.1" +"@fastify/static@^5.0.0": + version "5.0.2" + resolved "https://registry.yarnpkg.com/@fastify/static/-/static-5.0.2.tgz#46cee887393b422f4b10a46a14e970a64dd086d4" + integrity sha512-HvyXZ5a7hUHoSBRq9jKUuKIUCkHMkCDcmiAeEmixXlGOx8pEWx3NYOIaiivcjWa6/NLvfdUT+t/jzfVQ2PA7Gw== + dependencies: + content-disposition "^0.5.3" + encoding-negotiator "^2.0.1" + fastify-plugin "^3.0.0" + glob "^7.1.4" + p-limit "^3.1.0" + readable-stream "^3.4.0" + send "^0.17.1" + +"@fastify/swagger@6.x": + version "6.1.0" + resolved "https://registry.yarnpkg.com/@fastify/swagger/-/swagger-6.1.0.tgz#8f58177a9c7da3ad6ebcc87a419171a32db0702b" + integrity sha512-oum6QzV1/8/2eqWOEYzqwhRJQ3ftpxfGnDGmAinLIyeTrsr7xpNev/8iRxAAb7S6S8KRIIybkhvzvkuqnQKTkA== + dependencies: + "@fastify/static" "^5.0.0" + fastify-plugin "^3.0.0" + js-yaml "^4.0.0" + json-schema-resolver "^1.3.0" + openapi-types "^10.0.0" + rfdc "^1.3.0" + "@humanwhocodes/config-array@^0.9.2": version "0.9.5" resolved "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.9.5.tgz" @@ -1025,6 +1050,13 @@ concat-map@0.0.1: resolved "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz" integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= +content-disposition@^0.5.3: + version "0.5.4" + resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.4.tgz#8b82b4efac82512a02bb0b1dcec9d2c5e8eb5bfe" + integrity sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ== + dependencies: + safe-buffer "5.2.1" + convert-source-map@^1.7.0: version "1.8.0" resolved "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.8.0.tgz" @@ -1056,6 +1088,13 @@ csstype@^3.0.2: resolved "https://registry.npmjs.org/csstype/-/csstype-3.0.11.tgz" integrity sha512-sa6P2wJ+CAbgyy4KFssIb/JNMLxFvKF1pCYCSXS8ZMuqZnMsrxqI2E5sPyoTpxoPU/gVZMzr2zjOfg8GIZOMsw== +debug@2.6.9: + version "2.6.9" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" + integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA== + dependencies: + ms "2.0.0" + debug@^4.0.0, debug@^4.1.0, debug@^4.1.1, debug@^4.3.2: version "4.3.4" resolved "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz" @@ -1090,6 +1129,16 @@ denque@^2.0.1: resolved "https://registry.npmjs.org/denque/-/denque-2.0.1.tgz" integrity sha512-tfiWc6BQLXNLpNiR5iGd0Ocu3P3VpxfzFiqubLgMfhfOw9WyvgJBd46CClNn9k3qfbjvT//0cf7AlYRX/OslMQ== +depd@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9" + integrity sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ== + +destroy@~1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80" + integrity sha512-3NdhDuEXnfun/z7x9GOElY49LoqVHoGScmOKwmxhsS8N5Y+Z8KyPPDnaSzqWgYt/ji4mqwfTS34Htrk0zPIXVg== + diff@^4.0.1, diff@^4.0.2: version "4.0.2" resolved "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz" @@ -1114,6 +1163,11 @@ dotenv@16.0.1: resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.1.tgz#8f8f9d94876c35dac989876a5d3a82a267fdce1d" integrity sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ== +ee-first@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" + integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow== + electron-to-chromium@^1.4.118: version "1.4.137" resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.137.tgz" @@ -1124,6 +1178,16 @@ emoji-regex@^8.0.0: resolved "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz" integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== +encodeurl@~1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" + integrity sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w== + +encoding-negotiator@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/encoding-negotiator/-/encoding-negotiator-2.0.1.tgz#79871bb5473b81f6a0670e8de5303fb5ee0868a3" + integrity sha512-GSK7qphNR4iPcejfAlZxKDoz3xMhnspwImK+Af5WhePS9jUpK/Oh7rUdyENWu+9rgDflOCTmAojBsgsvM8neAQ== + es6-error@^4.0.1: version "4.1.1" resolved "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz" @@ -1134,6 +1198,11 @@ escalade@^3.1.1: resolved "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz" integrity sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw== +escape-html@~1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988" + integrity sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow== + escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz" @@ -1266,6 +1335,11 @@ esutils@^2.0.2: resolved "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz" integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g== +etag@~1.8.1: + version "1.8.1" + resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887" + integrity sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg== + events-to-array@^1.0.1: version "1.1.2" resolved "https://registry.npmjs.org/events-to-array/-/events-to-array-1.1.2.tgz" @@ -1432,6 +1506,11 @@ forwarded@0.2.0: resolved "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz" integrity sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow== +fresh@0.5.2: + version "0.5.2" + resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7" + integrity sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q== + fromentries@^1.2.0: version "1.3.2" resolved "https://registry.npmjs.org/fromentries/-/fromentries-1.3.2.tgz" @@ -1567,6 +1646,17 @@ html-escaper@^2.0.0: resolved "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz" integrity sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg== +http-errors@1.8.1: + version "1.8.1" + resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.8.1.tgz#7c3f28577cbc8a207388455dbd62295ed07bd68c" + integrity sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g== + dependencies: + depd "~1.1.2" + inherits "2.0.4" + setprototypeof "1.2.0" + statuses ">= 1.5.0 < 2" + toidentifier "1.0.1" + ieee754@^1.1.13: version "1.2.1" resolved "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz" @@ -1603,7 +1693,7 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@2: +inherits@2, inherits@2.0.4, inherits@^2.0.3: version "2.0.4" resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== @@ -1784,7 +1874,7 @@ js-yaml@^3.13.1: argparse "^1.0.7" esprima "^4.0.0" -js-yaml@^4.1.0: +js-yaml@^4.0.0, js-yaml@^4.1.0: version "4.1.0" resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz" integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA== @@ -1796,6 +1886,15 @@ jsesc@^2.5.1: resolved "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz" integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA== +json-schema-resolver@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/json-schema-resolver/-/json-schema-resolver-1.3.0.tgz#0840864b06780363d31fb03cdfae5047e2f81fbb" + integrity sha512-EX7W1r8aZ/T3j8GbbBxPXi60bnsELfT90OiA1QrbGMvwzVSbyMNOAzvMFcFb8m7gKCXZLJpGe+cJOvWgoFl29A== + dependencies: + debug "^4.1.1" + rfdc "^1.1.4" + uri-js "^4.2.2" + json-schema-traverse@^0.4.1: version "0.4.1" resolved "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz" @@ -1914,6 +2013,11 @@ micromatch@^4.0.4: braces "^3.0.2" picomatch "^2.3.1" +mime@1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1" + integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== + mimic-fn@^2.1.0: version "2.1.0" resolved "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz" @@ -1958,11 +2062,21 @@ mongodb@^4.0.1: optionalDependencies: saslprep "^1.0.3" +ms@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + integrity sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A== + ms@2.1.2, ms@^2.1.2: version "2.1.2" resolved "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz" integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== +ms@2.1.3: + version "2.1.3" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" + integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== + natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz" @@ -2023,6 +2137,13 @@ object-assign@^4.1.1: resolved "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz" integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM= +on-finished@~2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947" + integrity sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww== + dependencies: + ee-first "1.1.1" + once@^1.3.0: version "1.4.0" resolved "https://registry.npmjs.org/once/-/once-1.4.0.tgz" @@ -2037,6 +2158,11 @@ onetime@^5.1.0: dependencies: mimic-fn "^2.1.0" +openapi-types@^10.0.0: + version "10.0.0" + resolved "https://registry.yarnpkg.com/openapi-types/-/openapi-types-10.0.0.tgz#0debbf663b2feed0322030b5b7c9080804076934" + integrity sha512-Y8xOCT2eiKGYDzMW9R4x5cmfc3vGaaI4EL2pwhDmodWw1HlK18YcZ4uJxc7Rdp7/gGzAygzH9SXr6GKYIXbRcQ== + opener@^1.5.1: version "1.5.2" resolved "https://registry.npmjs.org/opener/-/opener-1.5.2.tgz" @@ -2073,6 +2199,13 @@ p-limit@^2.2.0: dependencies: p-try "^2.0.0" +p-limit@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b" + integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ== + dependencies: + yocto-queue "^0.1.0" + p-locate@^4.1.0: version "4.1.0" resolved "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz" @@ -2209,6 +2342,11 @@ quick-format-unescaped@^4.0.3: resolved "https://registry.npmjs.org/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz" integrity sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg== +range-parser@~1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031" + integrity sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg== + react-devtools-core@^4.19.1: version "4.24.7" resolved "https://registry.yarnpkg.com/react-devtools-core/-/react-devtools-core-4.24.7.tgz#43df22e6d244ed8286fd3ff16a80813998fe82a0" @@ -2234,6 +2372,15 @@ react@^17.0.2: loose-envify "^1.1.0" object-assign "^4.1.1" +readable-stream@^3.4.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198" + integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA== + dependencies: + inherits "^2.0.3" + string_decoder "^1.1.1" + util-deprecate "^1.0.1" + readdirp@~3.6.0: version "3.6.0" resolved "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz" @@ -2308,7 +2455,7 @@ reusify@^1.0.4: resolved "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz" integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== -rfdc@^1.1.4, rfdc@^1.2.0: +rfdc@^1.1.4, rfdc@^1.2.0, rfdc@^1.3.0: version "1.3.0" resolved "https://registry.npmjs.org/rfdc/-/rfdc-1.3.0.tgz" integrity sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA== @@ -2327,6 +2474,11 @@ run-parallel@^1.1.9: dependencies: queue-microtask "^1.2.2" +safe-buffer@5.2.1, safe-buffer@~5.2.0: + version "5.2.1" + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" + integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== + safe-buffer@~5.1.1: version "5.1.2" resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz" @@ -2376,6 +2528,25 @@ semver@^7.3.2, semver@^7.3.5: dependencies: lru-cache "^6.0.0" +send@^0.17.1: + version "0.17.2" + resolved "https://registry.yarnpkg.com/send/-/send-0.17.2.tgz#926622f76601c41808012c8bf1688fe3906f7820" + integrity sha512-UJYB6wFSJE3G00nEivR5rgWp8c2xXvJ3OPWPhmuteU0IKj8nKbG3DrjiOmLwpnHGYWAVwA69zmTm++YG0Hmwww== + dependencies: + debug "2.6.9" + depd "~1.1.2" + destroy "~1.0.4" + encodeurl "~1.0.2" + escape-html "~1.0.3" + etag "~1.8.1" + fresh "0.5.2" + http-errors "1.8.1" + mime "1.6.0" + ms "2.1.3" + on-finished "~2.3.0" + range-parser "~1.2.1" + statuses "~1.5.0" + set-blocking@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz" @@ -2386,6 +2557,11 @@ set-cookie-parser@^2.4.1: resolved "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.4.8.tgz" integrity sha512-edRH8mBKEWNVIVMKejNnuJxleqYE/ZSdcT8/Nem9/mmosx12pctd80s2Oy00KNZzrogMZS5mauK2/ymL1bvlvg== +setprototypeof@1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424" + integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw== + shebang-command@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz" @@ -2487,6 +2663,11 @@ stack-utils@^2.0.2, stack-utils@^2.0.4: dependencies: escape-string-regexp "^2.0.0" +"statuses@>= 1.5.0 < 2", statuses@~1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c" + integrity sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA== + string-similarity@^4.0.1: version "4.0.4" resolved "https://registry.npmjs.org/string-similarity/-/string-similarity-4.0.4.tgz" @@ -2501,6 +2682,13 @@ string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2 is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.1" +string_decoder@^1.1.1: + version "1.3.0" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e" + integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== + dependencies: + safe-buffer "~5.2.0" + strip-ansi@^3.0.1: version "3.0.1" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz" @@ -2639,6 +2827,11 @@ to-regex-range@^5.0.1: dependencies: is-number "^7.0.0" +toidentifier@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35" + integrity sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA== + tr46@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz" @@ -2730,6 +2923,11 @@ uri-js@^4.2.2: dependencies: punycode "^2.1.0" +util-deprecate@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" + integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw== + uuid@^3.3.3: version "3.4.0" resolved "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz" @@ -2860,6 +3058,11 @@ yargs@^15.0.2: y18n "^4.0.0" yargs-parser "^18.1.2" +yocto-queue@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" + integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== + yoga-layout-prebuilt@^1.9.6: version "1.10.0" resolved "https://registry.npmjs.org/yoga-layout-prebuilt/-/yoga-layout-prebuilt-1.10.0.tgz" From 58b98e7e8fe0f9b153e5e490597ba8b18bd4d26f Mon Sep 17 00:00:00 2001 From: Vic <74506415+victorioxd@users.noreply.github.com> Date: Thu, 7 Jul 2022 16:43:00 +0200 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=92=A5=20Add=20docs=20by=20swagger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.ts | 164 +++++++++++++++++++++++++++++++++++++++++++++----- src/server.ts | 22 ++++--- 2 files changed, 163 insertions(+), 23 deletions(-) diff --git a/src/App.ts b/src/App.ts index 94f398d..85fffd0 100644 --- a/src/App.ts +++ b/src/App.ts @@ -2,40 +2,176 @@ import fastify, { FastifyServerOptions } from 'fastify'; import fastifyMongodb from '@fastify/mongodb'; import './config/env'; import cors from '@fastify/cors'; +import fastifySwagger from '@fastify/swagger'; -function build(opts:FastifyServerOptions={}) { +async function build(opts: FastifyServerOptions = {}, isTest = false) { const App = fastify(opts); App.register(fastifyMongodb, { - url: process.env.MONGO_URL + url: process.env.MONGO_URL, }); App.register(cors, { - origin: '*' + origin: '*', }); - - App.get('/', async (req, res) => { - const fumos = await App.mongo.db?.collection('fumos').find({}).toArray(); - + if (!isTest) { + await App.register(fastifySwagger, { + routePrefix: '/docs', + swagger: { + info: { + title: 'Fumo-API', + description: 'Rest API of images of fumos (japanese plushies).', + version: '2.2.0', + contact: { + email: 'vic@nosesisaid.me', + name: 'Nosesisaid', + url: 'https://github.com/nosesisaid', + }, + license: { + name: 'MIT', + url: 'https://opensource.org/licenses/MIT', + }, + }, + externalDocs: { + url: 'https://github.com/nosesisaid/fumo-api', + description: 'Find more info here', + }, + host: 'fumo-api.nosesisaid.me', + schemes: ['https'], + consumes: ['application/json'], + produces: ['application/json'], + tags: [ + { name: 'images', description: 'image related end-points' }, + ], + definitions: { + Fumo: { + type: 'object', + required: ['id', 'URL'], + properties: { + id: { type: 'string'}, + URL: { type: 'string' }, + caption: { type: 'string' }, + fumos: { type: 'array', } }, + }, + }, + + }, + uiConfig: { + deepLinking: false, + }, + uiHooks: { + onRequest: function (request, reply, next) { + next(); + }, + preHandler: function (request, reply, next) { + next(); + }, + }, + staticCSP: true, + transformStaticCSP: (header) => header, + exposeRoute: true, + }); + } + App.get('/', { + schema: { + description: 'Get the full list of fumos', + tags: ['images'], + response: { + 200: { + type: 'array', + items: { + type: 'object', + properties: { + id: { type: 'string' }, + URL: { type: 'string' }, + caption: { type: 'string' }, + fumos: { type: 'array', }, + }, + }, + }, + }, + }, + },async (req, res) => { + const fumos = await App.mongo.db?.collection('fumos').find({}).toArray(); res.status(200).send(fumos); }); - App.get('/fumo/:id', async (req, res) => { - - const id = (req as any).params.id; - const fumo = await (await App.mongo.db?.collection('fumos'))?.findOne({_id: id}); + App.get('/fumo/:id',{ + schema: { + description: 'Get a fumo by it\'s id', + tags: ['images'], + params: { + type: 'object', + properties: { + id: { type: 'string', description: 'The id of the fumo' }, + }, + }, + response: { + 200: { + type: 'object', + properties: { + id: { type: 'string' }, + URL: { type: 'string' }, + caption: { type: 'string' }, + fumos: { type: 'array', }, + }, + }, + }, + }, + }, async (req, res) => { + //TODO: fix this + const id = (req.params as { id: string }).id; + + const fumo = await ( + await App.mongo.db?.collection('fumos') + )?.findOne({ _id: id }); res.status(200).send(fumo); }); - App.get('/random', async (req,res)=> { + App.get('/random', { + schema: { + description: 'Get a random fumo', + tags: ['images'], + response: { + 200: { + type: 'object', + properties: { + id: { type: 'string' }, + URL: { type: 'string' }, + caption: { type: 'string' }, + fumos: { type: 'array', }, + }, + }, + }, + }, + }, async (req, res) => { const fumos = await App.mongo.db?.collection('fumos').find({}).toArray(); if (!fumos) return res.status(400).send('No fumo :( (server error)'); const fumo = fumos[Math.floor(Math.random() * fumos?.length)]; - + res.status(200).send(fumo); }); - App.get('/fumos', async(req, res) => { + App.get('/fumos', { + schema: { + description: 'Get a list of fumos', + tags: ['images'], + response: { + 200: { + type: 'array', + items: { + type: 'object', + properties: { + id: { type: 'string' }, + URL: { type: 'string' }, + caption: { type: 'string' }, + fumos: { type: 'array', }, + }, + }, + }, + }, + }, + }, async (req, res) => { const fumos = await App.mongo.db?.collection('fumos').find({}).toArray(); res.status(200).send(fumos); diff --git a/src/server.ts b/src/server.ts index 1baaf7e..48e68fe 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,11 +1,15 @@ import {PORT} from './config/env'; import build from './App'; - -const server = build({ - logger: true -}); - -server.listen(PORT,'0.0.0.0', err => { - if (err) throw err; - console.log('Server listening on port ' + PORT); -}); \ No newline at end of file +async function main() { + + const server = await build({ + logger: true + }); + await server.ready(); + await server.swagger(); + server.listen(PORT,'0.0.0.0', err => { + if (err) throw err; + console.log('Server listening on port ' + PORT); + }); +} +main(); \ No newline at end of file From 54b65bf1c204d9f66a1d580516535a142ac11c21 Mon Sep 17 00:00:00 2001 From: Vic <74506415+victorioxd@users.noreply.github.com> Date: Thu, 7 Jul 2022 16:43:08 +0200 Subject: [PATCH 3/5] async tests --- tests/random.test.js | 2 +- tests/root.test.js | 2 +- tests/specific.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/random.test.js b/tests/random.test.js index 3551a29..b5e6cae 100644 --- a/tests/random.test.js +++ b/tests/random.test.js @@ -2,7 +2,7 @@ const build = require("../dist/App.js").default; const {test} = require("tap"); test('call `/random` route', async (t) => { t.plan(2) - const app = build(); + const app = await build(); const response = await app.inject({ method: 'GET', url:'/random' diff --git a/tests/root.test.js b/tests/root.test.js index dbd1467..0ed29ed 100644 --- a/tests/root.test.js +++ b/tests/root.test.js @@ -4,7 +4,7 @@ const { test } = require("tap"); test('call `/` route', async (t) => { t.plan(2); - const app = build(); + const app = await build(); const response = await app.inject({ method: 'GET', url:'/' diff --git a/tests/specific.test.js b/tests/specific.test.js index 3498703..1220f71 100644 --- a/tests/specific.test.js +++ b/tests/specific.test.js @@ -3,7 +3,7 @@ const {test} = require("tap"); test('call `/fumo/id` route', async (t) => { t.plan(4) - const app = build(); + const app = await build(); const id = '6128c5578caf0cf9a83f73e8'; const response = await app.inject({ method: 'GET', From 0a91e17bc2fac329ebce8babe29409919ccead6c Mon Sep 17 00:00:00 2001 From: Vic <74506415+victorioxd@users.noreply.github.com> Date: Thu, 7 Jul 2022 16:00:20 +0000 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=90=9B=20fix=20=5Fid=20and=20specific?= =?UTF-8?q?=20fumo=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/App.ts b/src/App.ts index 85fffd0..09986bc 100644 --- a/src/App.ts +++ b/src/App.ts @@ -47,7 +47,7 @@ async function build(opts: FastifyServerOptions = {}, isTest = false) { type: 'object', required: ['id', 'URL'], properties: { - id: { type: 'string'}, + _id: { type: 'string'}, URL: { type: 'string' }, caption: { type: 'string' }, fumos: { type: 'array', } }, @@ -81,7 +81,7 @@ async function build(opts: FastifyServerOptions = {}, isTest = false) { items: { type: 'object', properties: { - id: { type: 'string' }, + _id: { type: 'string' }, URL: { type: 'string' }, caption: { type: 'string' }, fumos: { type: 'array', }, @@ -102,14 +102,14 @@ async function build(opts: FastifyServerOptions = {}, isTest = false) { params: { type: 'object', properties: { - id: { type: 'string', description: 'The id of the fumo' }, + _id: { type: 'string', description: 'The id of the fumo' }, }, }, response: { 200: { type: 'object', properties: { - id: { type: 'string' }, + _id: { type: 'string' }, URL: { type: 'string' }, caption: { type: 'string' }, fumos: { type: 'array', }, @@ -118,12 +118,8 @@ async function build(opts: FastifyServerOptions = {}, isTest = false) { }, }, }, async (req, res) => { - //TODO: fix this - const id = (req.params as { id: string }).id; - - const fumo = await ( - await App.mongo.db?.collection('fumos') - )?.findOne({ _id: id }); + const params = req.params; + const fumo = await (await App.mongo.db?.collection('fumos'))?.findOne({_id: (params as any).id}); res.status(200).send(fumo); }); @@ -136,7 +132,7 @@ async function build(opts: FastifyServerOptions = {}, isTest = false) { 200: { type: 'object', properties: { - id: { type: 'string' }, + _id: { type: 'string' }, URL: { type: 'string' }, caption: { type: 'string' }, fumos: { type: 'array', }, @@ -162,7 +158,7 @@ async function build(opts: FastifyServerOptions = {}, isTest = false) { items: { type: 'object', properties: { - id: { type: 'string' }, + _id: { type: 'string' }, URL: { type: 'string' }, caption: { type: 'string' }, fumos: { type: 'array', }, From 02e842d6885aa79b47cf431a0c85322572b11293 Mon Sep 17 00:00:00 2001 From: Vic <74506415+victorioxd@users.noreply.github.com> Date: Thu, 7 Jul 2022 16:24:06 +0000 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=93=9D=20Set=20documentation=20link?= =?UTF-8?q?=20in=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 95ea1c6..ef27569 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ Rest API of images of fumos (japanese plushies) using typescript and fastify. ![logo](https://repository-images.githubusercontent.com/395606928/753b9fdd-b978-4b74-841e-f3973daf9129) - +## Documentation +Documentation available at [fumo-api.nosesisaid.com/docs](https://fumo-api.nosesisaid.com/docs) ## Contributing if you would like something to be different or have any suggestion, please [open an issue](https://github.com/nosesisaid/fumo-api/issues/new).