Skip to content

Commit

Permalink
refactor: replace lodash.pick for native object destructuring (#2235)
Browse files Browse the repository at this point in the history
Refs #2187
  • Loading branch information
jimmywarting authored Sep 13, 2021
1 parent bc1ab5f commit af2b86c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
5 changes: 2 additions & 3 deletions src/execute/oas3/parameter-builders.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pick from 'lodash/pick';

import stylize, { encodeDisallowedCharacters } from './style-serializer';
import serialize from './content-serializer';

Expand Down Expand Up @@ -45,9 +43,10 @@ export function query({ req, value, parameter }) {
}

if (value) {
const { style, explode, allowReserved } = parameter;
req.query[parameter.name] = {
value,
serializationOption: pick(parameter, ['style', 'explode', 'allowReserved']),
serializationOption: { style, explode, allowReserved },
};
} else if (parameter.allowEmptyValue && value !== undefined) {
const paramName = parameter.name;
Expand Down
13 changes: 6 additions & 7 deletions src/http/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'cross-fetch/polyfill'; /* global fetch */
import qs from 'qs';
import jsYaml from 'js-yaml';
import pick from 'lodash/pick';
import isFunction from 'lodash/isFunction';
import { Buffer } from 'buffer';
import { FormData, File, Blob } from 'formdata-node';
Expand Down Expand Up @@ -229,12 +228,12 @@ function formatKeyValue(key, input, skipEncoding = false) {
(type) => type !== 'undefined'
)
) {
return formatKeyValueBySerializationOption(
key,
value,
skipEncoding,
pick(encoding, ['style', 'explode', 'allowReserved'])
);
const { style, explode, allowReserved } = encoding;
return formatKeyValueBySerializationOption(key, value, skipEncoding, {
style,
explode,
allowReserved,
});
}

if (encoding.contentType) {
Expand Down
12 changes: 7 additions & 5 deletions src/interfaces.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pick from 'lodash/pick';

import { eachOperation, opId } from './helpers';

const nullFn = () => null;
Expand All @@ -15,16 +13,20 @@ export const self = {
// Make an execute, bound to arguments defined in mapTagOperation's callback (cb)
export function makeExecute(swaggerJs = {}) {
return ({ pathName, method, operationId }) =>
(parameters, opts = {}) =>
swaggerJs.execute({
(parameters, opts = {}) => {
const { requestInterceptor, responseInterceptor, userFetch } = swaggerJs;
return swaggerJs.execute({
spec: swaggerJs.spec,
...pick(swaggerJs, 'requestInterceptor', 'responseInterceptor', 'userFetch'),
requestInterceptor,
responseInterceptor,
userFetch,
pathName,
method,
parameters,
operationId,
...opts,
});
};
}

// Creates an interface with tags+operations = execute
Expand Down

0 comments on commit af2b86c

Please sign in to comment.