From 067229e8f7d6b55a68cb62278a662fc2a97c9f0a Mon Sep 17 00:00:00 2001 From: Gabriel Simon Gianotti Date: Wed, 10 Nov 2021 12:16:03 -0300 Subject: [PATCH] refactor: replace lodash isObject/isPlainObject with alternatives (#2309) Refs #2187 --- package-lock.json | 5 +++++ package.json | 1 + src/execute/index.js | 2 +- src/execute/oas3/build-request.js | 2 +- src/helpers.js | 6 ++---- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 83d044d14..8d8dd40f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8649,6 +8649,11 @@ "integrity": "sha1-caUMhCnfync8kqOQpKA7OfzVHT4=", "dev": true }, + "is-plain-object": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", + "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==" + }, "is-potential-custom-element-name": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", diff --git a/package.json b/package.json index 299972648..e2afa4250 100644 --- a/package.json +++ b/package.json @@ -116,6 +116,7 @@ "fast-json-patch": "^3.0.0-1", "form-data-encoder": "^1.4.3", "formdata-node": "^4.0.0", + "is-plain-object": "^5.0.0", "js-yaml": "^4.1.0", "lodash": "^4.17.21", "qs": "^6.9.4", diff --git a/src/execute/index.js b/src/execute/index.js index 3de36e99c..1977af43e 100755 --- a/src/execute/index.js +++ b/src/execute/index.js @@ -1,7 +1,7 @@ import getIn from 'lodash/get'; -import isPlainObject from 'lodash/isPlainObject'; import url from 'url'; import cookie from 'cookie'; +import { isPlainObject } from 'is-plain-object'; import stockHttp, { mergeInQueryOrForm } from '../http/index.js'; import createError from '../specmap/lib/create-error.js'; diff --git a/src/execute/oas3/build-request.js b/src/execute/oas3/build-request.js index 25fcc9678..ff3abb8ce 100644 --- a/src/execute/oas3/build-request.js +++ b/src/execute/oas3/build-request.js @@ -1,7 +1,7 @@ // This function runs after the common function, // `src/execute/index.js#buildRequest` +import { isPlainObject } from 'is-plain-object'; import get from 'lodash/get'; -import isPlainObject from 'lodash/isPlainObject'; import btoa from 'btoa'; export default function buildRequest(options, req) { diff --git a/src/helpers.js b/src/helpers.js index 8afe372a2..f18a1f156 100755 --- a/src/helpers.js +++ b/src/helpers.js @@ -1,5 +1,3 @@ -import isObject from 'lodash/isObject'; - const toLower = (str) => String.prototype.toLowerCase.call(str); const escapeString = (str) => str.replace(/[^\w]/gi, '_'); @@ -136,7 +134,7 @@ export function normalizeSwagger(parsedSpec) { for (const pathName in paths) { const path = paths[pathName]; - if (!isObject(path)) { + if (path == null || !['object', 'function'].includes(typeof path)) { continue; // eslint-disable-line no-continue } @@ -145,7 +143,7 @@ export function normalizeSwagger(parsedSpec) { // eslint-disable-next-line no-restricted-syntax, guard-for-in for (const method in path) { const operation = path[method]; - if (!isObject(operation)) { + if (path == null || !['object', 'function'].includes(typeof path)) { continue; // eslint-disable-line no-continue }