Skip to content

Commit

Permalink
refactor: replace lodash isArray + assign (#2236)
Browse files Browse the repository at this point in the history
- replace lodash.isArray for native Array.isArray
- replace lodash.assign for native object destructuring or Object.assign

Refs #2187
  • Loading branch information
jimmywarting authored Sep 13, 2021
1 parent af2b86c commit e3d4ef3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/execute/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import getIn from 'lodash/get';
import isPlainObject from 'lodash/isPlainObject';
import isArray from 'lodash/isArray';
import url from 'url';
import cookie from 'cookie';

Expand Down Expand Up @@ -77,7 +76,7 @@ export function execute({
...extras,
});

if (request.body && (isPlainObject(request.body) || isArray(request.body))) {
if (request.body && (isPlainObject(request.body) || Array.isArray(request.body))) {
request.body = JSON.stringify(request.body);
}

Expand Down
3 changes: 1 addition & 2 deletions src/execute/oas3/build-request.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// This function runs after the common function,
// `src/execute/index.js#buildRequest`
import assign from 'lodash/assign';
import get from 'lodash/get';
import isPlainObject from 'lodash/isPlainObject';
import btoa from 'btoa';
Expand Down Expand Up @@ -88,7 +87,7 @@ export default function buildRequest(options, req) {
// Add security values, to operations - that declare their need on them
// Adapted from the Swagger2 implementation
export function applySecurities({ request, securities = {}, operation = {}, spec }) {
const result = assign({}, request);
const result = { ...request };
const { authorized = {} } = securities;
const security = operation.security || spec.security || [];
const isAuthorized = authorized && !!Object.keys(authorized).length;
Expand Down
3 changes: 1 addition & 2 deletions src/execute/swagger2/build-request.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import btoa from 'btoa';
import assign from 'lodash/assign';

// This function runs after the common function,
// `src/execute/index.js#buildRequest`
Expand Down Expand Up @@ -57,7 +56,7 @@ export default function buildRequest(options, req) {

// Add security values, to operations - that declare their need on them
export function applySecurities({ request, securities = {}, operation = {}, spec }) {
const result = assign({}, request);
const result = { ...request };
const { authorized = {}, specSecurity = [] } = securities;
const security = operation.security || specSecurity;
const isAuthorized = authorized && !!Object.keys(authorized).length;
Expand Down
5 changes: 2 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assign from 'lodash/assign';
import startsWith from 'lodash/startsWith';
import Url from 'url';

Expand Down Expand Up @@ -34,11 +33,11 @@ function Swagger(url, opts = {}) {
return new Swagger(opts);
}

assign(this, opts);
Object.assign(this, opts);

const prom = this.resolve().then(() => {
if (!this.disableInterfaces) {
assign(this, Swagger.makeApisTagOperation(this));
Object.assign(this, Swagger.makeApisTagOperation(this));
}
return this;
});
Expand Down

0 comments on commit e3d4ef3

Please sign in to comment.