mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-06 04:21:09 +00:00
chore: use dequal instead of lodash.isequal (#1626)
* chore: use dequal instead of lodash.isequal * add a reference
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import * as path from 'path';
|
||||
import { red, blue, yellow, green } from 'colorette';
|
||||
import { performance } from 'perf_hooks';
|
||||
const isEqual = require('lodash.isequal');
|
||||
import {
|
||||
Config,
|
||||
SpecVersion,
|
||||
@@ -12,6 +11,7 @@ import {
|
||||
bundleDocument,
|
||||
isRef,
|
||||
} from '@redocly/openapi-core';
|
||||
import { dequal } from '@redocly/openapi-core/lib/utils';
|
||||
import {
|
||||
getFallbackApisOrExit,
|
||||
printExecutionTime,
|
||||
@@ -449,7 +449,7 @@ export async function handleJoin(argv: JoinOptions, config: Config, packageVersi
|
||||
// Compare properties only if both are reference objects
|
||||
if (!isRef(pathParameter) && !isRef(parameter)) {
|
||||
if (pathParameter.name === parameter.name && pathParameter.in === parameter.in) {
|
||||
if (!isEqual(pathParameter.schema, parameter.schema)) {
|
||||
if (!dequal(pathParameter.schema, parameter.schema)) {
|
||||
exitWithError(`Different parameter schemas for (${parameter.name}) in ${path}.`);
|
||||
}
|
||||
isFoundParameter = true;
|
||||
@@ -535,7 +535,7 @@ export async function handleJoin(argv: JoinOptions, config: Config, packageVersi
|
||||
|
||||
function isServersEqual(serverOne: Oas3Server, serverTwo: Oas3Server) {
|
||||
if (serverOne.description === serverTwo.description) {
|
||||
return isEqual(serverOne.variables, serverTwo.variables);
|
||||
return dequal(serverOne.variables, serverTwo.variables);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -636,7 +636,7 @@ export async function handleJoin(argv: JoinOptions, config: Config, packageVersi
|
||||
}
|
||||
|
||||
function doesComponentsDiffer(curr: object, next: object) {
|
||||
return !isEqual(Object.values(curr)[0], Object.values(next)[0]);
|
||||
return !dequal(Object.values(curr)[0], Object.values(next)[0]);
|
||||
}
|
||||
|
||||
function validateComponentsDifference(files: any) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { red, blue, yellow, green } from 'colorette';
|
||||
import * as fs from 'fs';
|
||||
import { parseYaml, slash, isRef, isTruthy } from '@redocly/openapi-core';
|
||||
import { dequal } from '@redocly/openapi-core/lib/utils';
|
||||
import * as path from 'path';
|
||||
import { performance } from 'perf_hooks';
|
||||
const isEqual = require('lodash.isequal');
|
||||
import {
|
||||
printExecutionTime,
|
||||
pathToFilename,
|
||||
@@ -232,7 +232,7 @@ function findComponentTypes(components: any) {
|
||||
}
|
||||
|
||||
function doesFileDiffer(filename: string, componentData: any) {
|
||||
return fs.existsSync(filename) && !isEqual(readYaml(filename), componentData);
|
||||
return fs.existsSync(filename) && !dequal(readYaml(filename), componentData);
|
||||
}
|
||||
|
||||
function removeEmptyComponents(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import isEqual = require('lodash.isequal');
|
||||
import { BaseResolver, resolveDocument, makeRefId, makeDocumentFromString } from './resolve';
|
||||
import { normalizeVisitors } from './visitors';
|
||||
import { normalizeTypes } from './types';
|
||||
@@ -13,7 +12,7 @@ import {
|
||||
import { isAbsoluteUrl, isRef, Location, refBaseName } from './ref-utils';
|
||||
import { initRules } from './config/rules';
|
||||
import { reportUnresolvedRef } from './rules/no-unresolved-refs';
|
||||
import { isPlainObject, isTruthy } from './utils';
|
||||
import { dequal, isPlainObject, isTruthy } from './utils';
|
||||
import { isRedoclyRegistryURL } from './redocly/domains';
|
||||
import { RemoveUnusedComponents as RemoveUnusedComponentsOas2 } from './decorators/oas2/remove-unused-components';
|
||||
import { RemoveUnusedComponents as RemoveUnusedComponentsOas3 } from './decorators/oas3/remove-unused-components';
|
||||
@@ -446,7 +445,7 @@ function makeBundleVisitor(
|
||||
return true;
|
||||
}
|
||||
|
||||
return isEqual(node, target.node);
|
||||
return dequal(node, target.node);
|
||||
}
|
||||
|
||||
function getComponentName(
|
||||
|
||||
@@ -284,3 +284,40 @@ export function getProxyAgent() {
|
||||
const proxy = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
|
||||
return proxy ? new HttpsProxyAgent(proxy) : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if two objects are deeply equal.
|
||||
* Borrowed the source code from https://github.com/lukeed/dequal.
|
||||
*/
|
||||
export function dequal(foo: any, bar: any): boolean {
|
||||
let ctor, len;
|
||||
if (foo === bar) return true;
|
||||
|
||||
if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
|
||||
if (ctor === Date) return foo.getTime() === bar.getTime();
|
||||
if (ctor === RegExp) return foo.toString() === bar.toString();
|
||||
|
||||
if (ctor === Array) {
|
||||
if ((len = foo.length) === bar.length) {
|
||||
while (len-- && dequal(foo[len], bar[len]));
|
||||
}
|
||||
return len === -1;
|
||||
}
|
||||
|
||||
if (!ctor || typeof foo === 'object') {
|
||||
len = 0;
|
||||
for (ctor in foo) {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(foo, ctor) &&
|
||||
++len &&
|
||||
!Object.prototype.hasOwnProperty.call(bar, ctor)
|
||||
)
|
||||
return false;
|
||||
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
|
||||
}
|
||||
return Object.keys(bar).length === len;
|
||||
}
|
||||
}
|
||||
|
||||
return foo !== foo && bar !== bar;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user