Skip to content

Commit dc04c99

Browse files
authored
fix(resolver): avoid accessing properties of undefined or null parameters (#3927)
1 parent aa85b8e commit dc04c99

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/resolver/strategies/generic/normalize.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isPlainObject } from 'ramda-adjunct';
2+
13
import opId from '../../../helpers/op-id.js';
24

35
export default function normalize(parsedSpec) {
@@ -78,18 +80,22 @@ export default function normalize(parsedSpec) {
7880
for (const inherits of inheritsList) {
7981
// eslint-disable-next-line no-restricted-syntax
8082
for (const inheritName in inherits) {
81-
if (!operation[inheritName]) {
83+
if (!Array.isArray(operation[inheritName])) {
8284
operation[inheritName] = inherits[inheritName];
8385
} else if (inheritName === 'parameters') {
8486
// eslint-disable-next-line no-restricted-syntax
8587
for (const param of inherits[inheritName]) {
86-
const exists = operation[inheritName].some(
87-
(opParam) =>
88-
(opParam.name && opParam.name === param.name) ||
89-
(opParam.$ref && opParam.$ref === param.$ref) ||
90-
(opParam.$$ref && opParam.$$ref === param.$$ref) ||
91-
opParam === param
92-
);
88+
const exists = operation[inheritName].some((opParam) => {
89+
if (!isPlainObject(opParam) && !isPlainObject(param)) return false;
90+
if (opParam === param) return true;
91+
92+
return ['name', '$ref', '$$ref'].some(
93+
(key) =>
94+
typeof opParam[key] === 'string' &&
95+
typeof param[key] === 'string' &&
96+
opParam[key] === param[key]
97+
);
98+
});
9399

94100
if (!exists) {
95101
operation[inheritName].push(param);

0 commit comments

Comments
 (0)