Skip to content

Commit 0e31b97

Browse files
authored
fix: validate plugins in extends (#2210)
1 parent c00f087 commit 0e31b97

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

.changeset/eight-onions-visit.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@redocly/openapi-core": patch
3+
"@redocly/cli": patch
4+
---
5+
6+
Fixed plugins validation in config files referenced in the `extends` section.

packages/core/src/config/__tests__/config-resolvers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ describe('resolveConfig', () => {
348348
it('should resolve `recommended-strict` ruleset correctly', async () => {
349349
const expectedStrict = JSON.parse(JSON.stringify(recommended)) as Omit<
350350
RawGovernanceConfig,
351-
'extends'
351+
'extends' | 'plugins'
352352
>;
353353
for (const section of Object.values(expectedStrict)) {
354354
for (let ruleName in section) {

packages/core/src/config/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export type DecoratorConfig = PreprocessorConfig;
5555

5656
export type RawGovernanceConfig<T extends 'built-in' | undefined = undefined> = {
5757
extends?: string[];
58+
plugins?: (string | Plugin)[];
5859

5960
rules?: RuleMap<BuiltInCommonRuleId, RuleConfig, T>;
6061
oas2Rules?: RuleMap<BuiltInOAS2RuleId, RuleConfig, T>;
@@ -84,7 +85,7 @@ export type RawGovernanceConfig<T extends 'built-in' | undefined = undefined> =
8485
overlay1Decorators?: Record<string, DecoratorConfig>;
8586
};
8687

87-
export type ResolvedGovernanceConfig = Omit<RawGovernanceConfig, 'extends'>;
88+
export type ResolvedGovernanceConfig = Omit<RawGovernanceConfig, 'extends' | 'plugins'>;
8889

8990
export type PreprocessorsConfig = {
9091
oas3?: Oas3PreprocessorsSet;

packages/core/src/types/redocly-yaml.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'node:path';
22
import { rootRedoclyConfigSchema } from '@redocly/config';
33
import { listOf } from './index.js';
44
import { SpecVersion, getTypes } from '../oas-types.js';
5-
import { isCustomRuleId } from '../utils.js';
5+
import { isCustomRuleId, omit } from '../utils.js';
66
import { getNodeTypesFromJSONSchema } from './json-schema-adapter.js';
77
import { normalizeTypes } from '../types/index.js';
88
import { isAbsoluteUrl } from '../ref-utils.js';
@@ -212,6 +212,7 @@ const configGovernanceProperties: Record<
212212
} as PropType;
213213
},
214214
} as PropType,
215+
plugins: { type: 'array', items: { type: 'string' } },
215216

216217
rules: 'Rules',
217218
oas2Rules: 'Rules',
@@ -268,7 +269,7 @@ const createConfigApisProperties = (nodeTypes: Record<string, NodeType>): NodeTy
268269
...nodeTypes['rootRedoclyConfigSchema.apis_additionalProperties'],
269270
properties: {
270271
...nodeTypes['rootRedoclyConfigSchema.apis_additionalProperties']?.properties,
271-
...ConfigGovernance.properties,
272+
...omit(ConfigGovernance.properties, ['plugins']), // plugins are not allowed in apis
272273
},
273274
});
274275

packages/core/src/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,13 @@ export function getOwn(obj: Record<string, any>, key: string) {
291291
export type CollectFn = (value: unknown) => void;
292292

293293
export type Exact<T extends object> = T & { [key: string]: undefined };
294+
295+
export function omit<O extends object, K extends keyof O>(obj: O, keys: K[]): Omit<O, K> {
296+
const result = { ...obj };
297+
298+
keys.forEach((key) => {
299+
delete result[key];
300+
});
301+
302+
return result;
303+
}

0 commit comments

Comments
 (0)