Skip to content

removes lodash.uniq and lodash.zipobject dependencies #893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
"json-schema-traverse": "^1.0.0",
"lodash.clonedeep": "^4.5.0",
"lodash.get": "^4.4.2",
"lodash.uniq": "^4.5.0",
"lodash.zipobject": "^4.1.3",
"media-typer": "^1.1.0",
"multer": "^1.4.5-lts.1",
"ono": "^7.1.3",
Expand Down
4 changes: 2 additions & 2 deletions src/middlewares/openapi.metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _zipObject from 'lodash.zipobject';
import { zipObject } from './util';
import { pathToRegexp } from 'path-to-regexp';
import { Response, NextFunction } from 'express';
import { OpenApiContext } from '../framework/openapi.context';
Expand Down Expand Up @@ -94,7 +94,7 @@ export function applyOpenApiMetadata(
const paramKeys = keys.map((k) => k.name);
try {
const paramsVals = matchedRoute.slice(1).map(decodeURIComponent);
const pathParams = _zipObject(paramKeys, paramsVals);
const pathParams = zipObject(paramKeys, paramsVals);

const r = {
schema,
Expand Down
7 changes: 7 additions & 0 deletions src/middlewares/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,10 @@ export const findResponseContent = function (
}
return null;
};

export const zipObject = (keys, values) =>
keys.reduce((acc, key, idx) => {
acc[key] = values[idx]
return acc
}, {})

4 changes: 2 additions & 2 deletions src/openapi.validator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Options } from 'ajv';
import ono from 'ono';
import * as express from 'express';
import * as _uniq from 'lodash.uniq';
import * as middlewares from './middlewares';
import { Application, Response, NextFunction, Router } from 'express';
import { OpenApiContext } from './framework/openapi.context';
Expand Down Expand Up @@ -237,7 +236,8 @@ export class OpenApiValidator {
}

// install param on routes with paths
for (const p of _uniq(pathParams)) {
const uniqPathParams = [...new Set(pathParams)]
for (const p of uniqPathParams) {
app.param(
p,
(
Expand Down