diff --git a/README.md b/README.md index 4ac3572..53fc06c 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,9 @@ Delete an event: ## API Documentation API Swagger documentation can be accessed from the docker host machine: `http://localhost:3004/documentation` +Schema documents are available in OpenAPI v2 and v3 flavors. +* OpenAPI v2 Schema (Swagger) `http://localhost:3004/swagger.json` +* OpenAPI v3 Schema `http://localhost:3004/openapi.json` ## Heroku Deploy diff --git a/config.js b/config.js index 2348c3e..8974136 100644 --- a/config.js +++ b/config.js @@ -125,6 +125,14 @@ module.exports = { admin_email: process.env.ADMIN_EMAIL || 'info@heatsynclabs.org', domain: process.env.DOMAIN_LOCATION || 'http://localhost:3005', domain_dev: process.env.DOMAIN_LOCATION_DEV || 'http://localhost:3005', + openapiOptions: { + info: { + title: Pack.name, + description: Pack.description + ' - ' + env, + version: Pack.version, + }, + pathPrefixSize: 3, + }, server_url: process.env.SERVER_URL || `http://localhost:${port}`, swaggerOptions: { info: { diff --git a/index.js b/index.js index 7b1985e..3f819b3 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ const Hapi = require('@hapi/hapi'); const Inert = require('@hapi/inert'); const Vision = require('@hapi/vision'); const JWTAuth = require('hapi-auth-jwt2'); +const HapiOpenapi3 = require('hapi-openapi3'); const HapiSwagger = require('hapi-swagger'); const CookieAuth = require('@hapi/cookie'); const debug = require('debug')('errors'); @@ -41,10 +42,16 @@ async function start() { JWTAuth, Inert, Vision, + { + plugin: HapiOpenapi3, + options: { + ...config.openapiOptions, + includeFn: () => true, + } + }, { plugin: HapiSwagger, - // eslint-disable-next-line - options: config.swaggerOptions + options: config.swaggerOptions, }, ]); } catch (error) { diff --git a/package-lock.json b/package-lock.json index 7d26522..ced2765 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,8 @@ "custom-error": "^0.2.1", "debug": "^4.3.4", "hapi-auth-jwt2": "^10.2.0", - "hapi-swagger": "^15.0.0", + "hapi-openapi3": "^1.0.9", + "hapi-swagger": "^16.0.1", "joi": "^17.7.0", "jsonwebtoken": "^9.0.0", "knex": "^2.3.0", @@ -72,9 +73,9 @@ } }, "node_modules/@apidevtools/json-schema-ref-parser": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-9.1.0.tgz", - "integrity": "sha512-teB30tFooE3iQs2HQIKJ02D8UZA1Xy1zaczzhUjJs0CymYxeC0g+y5rCY2p8NHBM6DBUVoR8rSM4kHLj1WE9mQ==", + "version": "9.1.2", + "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-9.1.2.tgz", + "integrity": "sha512-r1w81DpR+KyRWd3f+rk6TNqMgedmAxZP5v5KWlXQWlgMUUtyEJch0DKEci1SorPMiSeM8XPl7MZ3miJ60JIpQg==", "dependencies": { "@jsdevtools/ono": "^7.1.3", "@types/json-schema": "^7.0.6", @@ -4359,10 +4360,19 @@ "semver": "bin/semver" } }, + "node_modules/hapi-openapi3": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/hapi-openapi3/-/hapi-openapi3-1.0.9.tgz", + "integrity": "sha512-ljHEmBV8VbO/2c2Rj3y6IDoctGarSQJFGZbT6Hhj3jxRhhM4uvfkEqz6wYKoIm3+fPg4vKE9Y+gYx+SfTpWn5g==", + "dependencies": { + "joi": "^17.4.0", + "statuses": "^2.0.1" + } + }, "node_modules/hapi-swagger": { - "version": "15.0.0", - "resolved": "https://registry.npmjs.org/hapi-swagger/-/hapi-swagger-15.0.0.tgz", - "integrity": "sha512-AsFI6KlUz1sRnzWbXl8rEcmzbIX/OTqWZnf21ILmeAUKw9EJ7ndEUKYLXzByehmD/JsfYdYjQ6hTQu6PaBw5+A==", + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/hapi-swagger/-/hapi-swagger-16.0.1.tgz", + "integrity": "sha512-G07CZ7t6ytZt7Om0sTvpwxvuoLb260dlBdHjxwilsX7WboBAItdm4xXTkfJoe/KpjXatyqVVT5uVckBrhvFY6g==", "dependencies": { "@hapi/boom": "^10.0.0", "@hapi/hoek": "^10.0.1", @@ -4549,9 +4559,9 @@ "dev": true }, "node_modules/http-status": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/http-status/-/http-status-1.6.1.tgz", - "integrity": "sha512-kr3txP/rwmTi6WhSPgw8Ai4WGq39l/Am8DeXgRhTSbjnnbo98m0A11+we+my3+NJw05h7g6HWhen+jJkLMw6oA==", + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/http-status/-/http-status-1.6.2.tgz", + "integrity": "sha512-oUExvfNckrpTpDazph7kNG8sQi5au3BeTo0idaZFXEhTaJKu7GNJCLHI0rYY2wljm548MSTM+Ljj/c6anqu2zQ==", "engines": { "node": ">= 0.4.0" } @@ -8296,6 +8306,14 @@ "node": ">=0.10.0" } }, + "node_modules/statuses": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/stream-shift": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.1.tgz", @@ -8444,9 +8462,9 @@ } }, "node_modules/swagger-ui-dist": { - "version": "4.15.5", - "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-4.15.5.tgz", - "integrity": "sha512-V3eIa28lwB6gg7/wfNvAbjwJYmDXy1Jo1POjyTzlB6wPcHiGlRxq39TSjYGVjQrUSAzpv+a7nzp7mDxgNy57xA==" + "version": "4.18.3", + "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-4.18.3.tgz", + "integrity": "sha512-QW280Uvt234+TLo9NMPRa2Sj17RoorbQlR2eEY4R6Cs0LbdXhiO14YWX9OPBkBdiN64GQYz4zU8wlHLVi81lBg==" }, "node_modules/tar-fs": { "version": "2.1.1", @@ -8924,9 +8942,9 @@ } }, "node_modules/validator": { - "version": "13.7.0", - "resolved": "https://registry.npmjs.org/validator/-/validator-13.7.0.tgz", - "integrity": "sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw==", + "version": "13.9.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.9.0.tgz", + "integrity": "sha512-B+dGG8U3fdtM0/aNK4/X8CXq/EcxU2WPrPEkJGslb47qyHsxmbggTWK0yEA4qnYVNF+nxNlN88o14hIcPmSIEA==", "engines": { "node": ">= 0.10" } @@ -9260,9 +9278,9 @@ } }, "@apidevtools/json-schema-ref-parser": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-9.1.0.tgz", - "integrity": "sha512-teB30tFooE3iQs2HQIKJ02D8UZA1Xy1zaczzhUjJs0CymYxeC0g+y5rCY2p8NHBM6DBUVoR8rSM4kHLj1WE9mQ==", + "version": "9.1.2", + "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-9.1.2.tgz", + "integrity": "sha512-r1w81DpR+KyRWd3f+rk6TNqMgedmAxZP5v5KWlXQWlgMUUtyEJch0DKEci1SorPMiSeM8XPl7MZ3miJ60JIpQg==", "requires": { "@jsdevtools/ono": "^7.1.3", "@types/json-schema": "^7.0.6", @@ -12606,10 +12624,19 @@ } } }, + "hapi-openapi3": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/hapi-openapi3/-/hapi-openapi3-1.0.9.tgz", + "integrity": "sha512-ljHEmBV8VbO/2c2Rj3y6IDoctGarSQJFGZbT6Hhj3jxRhhM4uvfkEqz6wYKoIm3+fPg4vKE9Y+gYx+SfTpWn5g==", + "requires": { + "joi": "^17.4.0", + "statuses": "^2.0.1" + } + }, "hapi-swagger": { - "version": "15.0.0", - "resolved": "https://registry.npmjs.org/hapi-swagger/-/hapi-swagger-15.0.0.tgz", - "integrity": "sha512-AsFI6KlUz1sRnzWbXl8rEcmzbIX/OTqWZnf21ILmeAUKw9EJ7ndEUKYLXzByehmD/JsfYdYjQ6hTQu6PaBw5+A==", + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/hapi-swagger/-/hapi-swagger-16.0.1.tgz", + "integrity": "sha512-G07CZ7t6ytZt7Om0sTvpwxvuoLb260dlBdHjxwilsX7WboBAItdm4xXTkfJoe/KpjXatyqVVT5uVckBrhvFY6g==", "requires": { "@hapi/boom": "^10.0.0", "@hapi/hoek": "^10.0.1", @@ -12744,9 +12771,9 @@ "dev": true }, "http-status": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/http-status/-/http-status-1.6.1.tgz", - "integrity": "sha512-kr3txP/rwmTi6WhSPgw8Ai4WGq39l/Am8DeXgRhTSbjnnbo98m0A11+we+my3+NJw05h7g6HWhen+jJkLMw6oA==" + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/http-status/-/http-status-1.6.2.tgz", + "integrity": "sha512-oUExvfNckrpTpDazph7kNG8sQi5au3BeTo0idaZFXEhTaJKu7GNJCLHI0rYY2wljm548MSTM+Ljj/c6anqu2zQ==" }, "human-interval": { "version": "2.0.1", @@ -15569,6 +15596,11 @@ } } }, + "statuses": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==" + }, "stream-shift": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.1.tgz", @@ -15683,9 +15715,9 @@ } }, "swagger-ui-dist": { - "version": "4.15.5", - "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-4.15.5.tgz", - "integrity": "sha512-V3eIa28lwB6gg7/wfNvAbjwJYmDXy1Jo1POjyTzlB6wPcHiGlRxq39TSjYGVjQrUSAzpv+a7nzp7mDxgNy57xA==" + "version": "4.18.3", + "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-4.18.3.tgz", + "integrity": "sha512-QW280Uvt234+TLo9NMPRa2Sj17RoorbQlR2eEY4R6Cs0LbdXhiO14YWX9OPBkBdiN64GQYz4zU8wlHLVi81lBg==" }, "tar-fs": { "version": "2.1.1", @@ -16052,9 +16084,9 @@ } }, "validator": { - "version": "13.7.0", - "resolved": "https://registry.npmjs.org/validator/-/validator-13.7.0.tgz", - "integrity": "sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw==" + "version": "13.9.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.9.0.tgz", + "integrity": "sha512-B+dGG8U3fdtM0/aNK4/X8CXq/EcxU2WPrPEkJGslb47qyHsxmbggTWK0yEA4qnYVNF+nxNlN88o14hIcPmSIEA==" }, "webidl-conversions": { "version": "3.0.1", diff --git a/package.json b/package.json index 788c72e..f826c6f 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,8 @@ "custom-error": "^0.2.1", "debug": "^4.3.4", "hapi-auth-jwt2": "^10.2.0", - "hapi-swagger": "^15.0.0", + "hapi-openapi3": "^1.0.9", + "hapi-swagger": "^16.0.1", "joi": "^17.7.0", "jsonwebtoken": "^9.0.0", "knex": "^2.3.0", diff --git a/routes/users.js b/routes/users.js index e145e42..a1fc00d 100644 --- a/routes/users.js +++ b/routes/users.js @@ -214,8 +214,7 @@ module.exports = [ token: Joi.string().uuid().required(), }), payload: Joi.object({ - password: Joi.string().regex(/^[a-zA-Z0-9]{6,1000}$/).required(), - verify_password: Joi.any().valid(Joi.ref('password')).required() + password: Joi.string().regex(/^[a-zA-Z0-9]{6,1000}$/).required() }) }, },