diff --git a/package-lock.json b/package-lock.json index c1d457a..708862e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,16 @@ { "name": "@goodrequest/express-joi-to-swagger", - "version": "1.0.3", + "version": "1.0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@goodrequest/express-joi-to-swagger", - "version": "1.0.3", + "version": "1.0.4", "license": "MIT", "dependencies": { "buffer": "6.0.3", + "compare-versions": "6.1.0", "create-file-webpack": "1.0.2", "css-loader": "7.1.1", "express": "4.19.2", @@ -18,7 +19,6 @@ "joi-to-swagger": "github:GoodRequest/joi-to-swagger#cea5393", "lodash": "4.17.21", "passport": "0.7.0", - "passport-local": "1.0.0", "stream-browserify": "3.0.0", "style-loader": "4.0.0", "swagger-ui-dist": "5.15.2", @@ -27,12 +27,9 @@ }, "devDependencies": { "@goodrequest/eslint-config-typescript": "1.3.0", - "@types/copy-webpack-plugin": "10.1.0", "@types/express": "4.17.21", "@types/lodash": "4.17.0", "@types/passport": "1.0.16", - "@types/passport-jwt": "4.0.1", - "@types/passport-local": "1.0.38", "@types/swagger-ui-dist": "3.30.4", "@typescript-eslint/eslint-plugin": "7.7.0", "copyfiles": "2.4.1", @@ -353,16 +350,6 @@ "@types/node": "*" } }, - "node_modules/@types/copy-webpack-plugin": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/@types/copy-webpack-plugin/-/copy-webpack-plugin-10.1.0.tgz", - "integrity": "sha512-Dk0NUW3X6hVQdkH2n9R7NejjPNCocZBiv8XF8Ac5su2d6EKzCcG/yWDwnWGrEsAWvogoADJyUKULwncx0G9Jkg==", - "deprecated": "This is a stub types definition. copy-webpack-plugin provides its own type definitions, so you do not need this installed.", - "dev": true, - "dependencies": { - "copy-webpack-plugin": "*" - } - }, "node_modules/@types/eslint": { "version": "8.40.2", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.40.2.tgz", @@ -432,15 +419,6 @@ "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, - "node_modules/@types/jsonwebtoken": { - "version": "9.0.2", - "resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz", - "integrity": "sha512-drE6uz7QBKq1fYqqoFKTDRdFCPHd5TCub75BM+D+cMx7NU9hUz7SESLfC2fSCXVFMO5Yj8sOWHuGqPgjc+fz0Q==", - "dev": true, - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@types/lodash": { "version": "4.17.0", "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.0.tgz", @@ -467,37 +445,6 @@ "@types/express": "*" } }, - "node_modules/@types/passport-jwt": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@types/passport-jwt/-/passport-jwt-4.0.1.tgz", - "integrity": "sha512-Y0Ykz6nWP4jpxgEUYq8NoVZeCQPo1ZndJLfapI249g1jHChvRfZRO/LS3tqu26YgAS/laI1qx98sYGz0IalRXQ==", - "dev": true, - "dependencies": { - "@types/jsonwebtoken": "*", - "@types/passport-strategy": "*" - } - }, - "node_modules/@types/passport-local": { - "version": "1.0.38", - "resolved": "https://registry.npmjs.org/@types/passport-local/-/passport-local-1.0.38.tgz", - "integrity": "sha512-nsrW4A963lYE7lNTv9cr5WmiUD1ibYJvWrpE13oxApFsRt77b0RdtZvKbCdNIY4v/QZ6TRQWaDDEwV1kCTmcXg==", - "dev": true, - "dependencies": { - "@types/express": "*", - "@types/passport": "*", - "@types/passport-strategy": "*" - } - }, - "node_modules/@types/passport-strategy": { - "version": "0.2.35", - "resolved": "https://registry.npmjs.org/@types/passport-strategy/-/passport-strategy-0.2.35.tgz", - "integrity": "sha512-o5D19Jy2XPFoX2rKApykY15et3Apgax00RRLf0RUotPDUsYrQa7x4howLYr9El2mlUApHmCMv5CZ1IXqKFQ2+g==", - "dev": true, - "dependencies": { - "@types/express": "*", - "@types/passport": "*" - } - }, "node_modules/@types/qs": { "version": "6.9.7", "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz", @@ -967,45 +914,6 @@ "url": "https://github.com/sponsors/epoberezkin" } }, - "node_modules/ajv-formats": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", - "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", - "dev": true, - "dependencies": { - "ajv": "^8.0.0" - }, - "peerDependencies": { - "ajv": "^8.0.0" - }, - "peerDependenciesMeta": { - "ajv": { - "optional": true - } - } - }, - "node_modules/ajv-formats/node_modules/ajv": { - "version": "8.12.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", - "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==", - "dev": true, - "dependencies": { - "fast-deep-equal": "^3.1.1", - "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.2.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, - "node_modules/ajv-formats/node_modules/json-schema-traverse": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", - "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", - "dev": true - }, "node_modules/ajv-keywords": { "version": "3.5.2", "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz", @@ -1472,6 +1380,11 @@ "node": ">= 12" } }, + "node_modules/compare-versions": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-6.1.0.tgz", + "integrity": "sha512-LNZQXhqUvqUTotpZ00qLSaify3b4VFD588aRr8MKFw4CMUr98ytzCW5wDH5qx/DEY5kCDXcbcRuCqL0szEf2tg==" + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -1516,61 +1429,6 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==" }, - "node_modules/copy-webpack-plugin": { - "version": "11.0.0", - "resolved": "https://registry.npmjs.org/copy-webpack-plugin/-/copy-webpack-plugin-11.0.0.tgz", - "integrity": "sha512-fX2MWpamkW0hZxMEg0+mYnA40LTosOSa5TqZ9GYIBzyJa9C3QUaMPSE2xAi/buNr8u89SfD9wHSQVBzrRa/SOQ==", - "dev": true, - "dependencies": { - "fast-glob": "^3.2.11", - "glob-parent": "^6.0.1", - "globby": "^13.1.1", - "normalize-path": "^3.0.0", - "schema-utils": "^4.0.0", - "serialize-javascript": "^6.0.0" - }, - "engines": { - "node": ">= 14.15.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/webpack" - }, - "peerDependencies": { - "webpack": "^5.1.0" - } - }, - "node_modules/copy-webpack-plugin/node_modules/globby": { - "version": "13.2.0", - "resolved": "https://registry.npmjs.org/globby/-/globby-13.2.0.tgz", - "integrity": "sha512-jWsQfayf13NvqKUIL3Ta+CIqMnvlaIDFveWE/dpOZ9+3AMEJozsxDvKA02zync9UuvOM8rOXzsD5GqKP4OnWPQ==", - "dev": true, - "dependencies": { - "dir-glob": "^3.0.1", - "fast-glob": "^3.2.11", - "ignore": "^5.2.0", - "merge2": "^1.4.1", - "slash": "^4.0.0" - }, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/copy-webpack-plugin/node_modules/slash": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/slash/-/slash-4.0.0.tgz", - "integrity": "sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/copyfiles": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/copyfiles/-/copyfiles-2.4.1.tgz", @@ -3847,15 +3705,6 @@ "readable-stream": "~1.0.31" } }, - "node_modules/normalize-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", - "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/nth-check": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz", @@ -4084,17 +3933,6 @@ "url": "https://github.com/sponsors/jaredhanson" } }, - "node_modules/passport-local": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/passport-local/-/passport-local-1.0.0.tgz", - "integrity": "sha512-9wCE6qKznvf9mQYYbgJ3sVOHmCWoUNMVFoZzNoznmISbhnNNPhN9xfY3sLmScHMetEJeoY7CXwfhCe7argfQow==", - "dependencies": { - "passport-strategy": "1.x.x" - }, - "engines": { - "node": ">= 0.4.0" - } - }, "node_modules/passport-strategy": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz", @@ -4491,15 +4329,6 @@ "node": ">=0.10.0" } }, - "node_modules/require-from-string": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", - "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/resolve": { "version": "1.22.8", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", @@ -4639,59 +4468,6 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, - "node_modules/schema-utils": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-4.2.0.tgz", - "integrity": "sha512-L0jRsrPpjdckP3oPug3/VxNKt2trR8TcabrM6FOAAlvC/9Phcmm+cuAgTlxBqdBR1WJx7Naj9WHw+aOmheSVbw==", - "dev": true, - "dependencies": { - "@types/json-schema": "^7.0.9", - "ajv": "^8.9.0", - "ajv-formats": "^2.1.1", - "ajv-keywords": "^5.1.0" - }, - "engines": { - "node": ">= 12.13.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/webpack" - } - }, - "node_modules/schema-utils/node_modules/ajv": { - "version": "8.12.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", - "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==", - "dev": true, - "dependencies": { - "fast-deep-equal": "^3.1.1", - "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.2.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, - "node_modules/schema-utils/node_modules/ajv-keywords": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-5.1.0.tgz", - "integrity": "sha512-YCS/JNFAUyr5vAuhk1DWm1CBxRHW9LbJ2ozWeemrIqpbsqKjHVxYPyi5GC0rjZIT5JxJ3virVTS8wk4i/Z+krw==", - "dev": true, - "dependencies": { - "fast-deep-equal": "^3.1.3" - }, - "peerDependencies": { - "ajv": "^8.8.2" - } - }, - "node_modules/schema-utils/node_modules/json-schema-traverse": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", - "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", - "dev": true - }, "node_modules/semver": { "version": "7.6.0", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", diff --git a/package.json b/package.json index 747230e..6a04807 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ ], "dependencies": { "buffer": "6.0.3", + "compare-versions": "6.1.0", "create-file-webpack": "1.0.2", "css-loader": "7.1.1", "express": "4.19.2", @@ -30,7 +31,6 @@ "joi-to-swagger": "github:GoodRequest/joi-to-swagger#cea5393", "lodash": "4.17.21", "passport": "0.7.0", - "passport-local": "1.0.0", "stream-browserify": "3.0.0", "style-loader": "4.0.0", "swagger-ui-dist": "5.15.2", @@ -39,12 +39,9 @@ }, "devDependencies": { "@goodrequest/eslint-config-typescript": "1.3.0", - "@types/copy-webpack-plugin": "10.1.0", "@types/express": "4.17.21", "@types/lodash": "4.17.0", "@types/passport": "1.0.16", - "@types/passport-jwt": "4.0.1", - "@types/passport-local": "1.0.38", "@types/swagger-ui-dist": "3.30.4", "@typescript-eslint/eslint-plugin": "7.7.0", "copyfiles": "2.4.1", @@ -55,7 +52,7 @@ "prettier": "3.2.5", "typescript": "5.4.5" }, - "description": "Solution that generates beatiful Swagger API documentation from code. 💻", + "description": "Solution that generates beautiful Swagger API documentation from code. 💻", "bugs": { "url": "https://github.com/GoodRequest/express-joi-to-swagger/issues" }, diff --git a/src/types/create-file-webpack/index.d.ts b/src/types/create-file-webpack/index.d.ts new file mode 100644 index 0000000..53d96f8 --- /dev/null +++ b/src/types/create-file-webpack/index.d.ts @@ -0,0 +1,20 @@ +import { Compiler } from 'webpack' + +declare class CreateFilePlugin { + constructor(options: CreateFilePlugin.IOptions) + + /** + * Apply the plugin + */ + apply(compiler: Compiler): void +} + +export = CreateFilePlugin + +declare namespace CreateFilePlugin { + interface IOptions { + path: string + fileName: string + content: string + } +} diff --git a/src/ui/index.ts b/src/ui/index.ts index e7046e0..1adb2b7 100644 --- a/src/ui/index.ts +++ b/src/ui/index.ts @@ -1,8 +1,6 @@ import webpack from 'webpack' import path from 'path' import HtmlWebpackPlugin from 'html-webpack-plugin' -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore import CreateFileWebpack from 'create-file-webpack' import { IGenerateSwaggerConfig } from '../types/interfaces' diff --git a/src/ui/src.js b/src/ui/src.js index 5971ef7..2a18597 100644 --- a/src/ui/src.js +++ b/src/ui/src.js @@ -1,7 +1,7 @@ import { trim, every } from 'lodash' - import { SwaggerUIBundle, SwaggerUIStandalonePreset } from 'swagger-ui-dist' import 'swagger-ui-dist/swagger-ui.css' +import { compareVersions, validate } from 'compare-versions' const AdvancedFilterPlugin = () => ({ fn: { @@ -14,7 +14,7 @@ const AdvancedFilterPlugin = () => ({ const filteredData = taggedOps .map((entities) => { - const newentities = entities.map((entity, key) => { + const newEntities = entities.map((entity, key) => { if (key === 'operations') { const operations = entity.filter((operation) => { const hasEvery = every(normPhrases, (normPhrase) => { @@ -38,7 +38,7 @@ const AdvancedFilterPlugin = () => ({ } return entity }) - return newentities + return newEntities }) .filter((entities) => !(entities.get('operations').size <= 0)) @@ -50,7 +50,18 @@ const AdvancedFilterPlugin = () => ({ // eslint-disable-next-line no-undef, no-void void fetch(`archive.json?v=${APP_VERSION}`) .then((response) => response.json()) - .then((data) => { + .then((versionsData) => { + const sortedVersionsData = versionsData.sort((a, b) => { + const aIsSemver = validate(a.name) + const bIsSemver = validate(b.name) + + if (aIsSemver && bIsSemver) { + return compareVersions(b.name, a.name) + } + + return a.name.localeCompare(b.name) + }) + SwaggerUIBundle({ dom_id: '#swagger', filter: true, @@ -65,9 +76,9 @@ void fetch(`archive.json?v=${APP_VERSION}`) plugins: [AdvancedFilterPlugin, SwaggerUIBundle.plugins.DownloadUrl], presets: [ SwaggerUIBundle.presets.apis, - SwaggerUIStandalonePreset // // NOTE: turn on for topbar + SwaggerUIStandalonePreset // NOTE: turn on for topbar ], - urls: data, - 'urls.primaryName': data?.[0]?.name // default spec + urls: sortedVersionsData, + 'urls.primaryName': sortedVersionsData?.[0]?.name // default spec }) })