Skip to content
Draft
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
43 changes: 43 additions & 0 deletions packages/core/src/config/__tests__/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { type SpecVersion } from '../../oas-types.js';
import { rootRedoclyConfigSchema } from '@redocly/config';
import { Config } from '../config.js';
import * as utils from '../../utils.js';
import * as jsYaml from '../../js-yaml/index.js';
import * as fs from 'node:fs';
import { ignoredFileStub } from './fixtures/ingore-file.js';
import * as path from 'node:path';
import { createConfig } from '../index.js';
import { specVersions } from '../../oas-types.js';

vi.mock('../../js-yaml/index.js', async () => {
const actual = await vi.importActual('../../js-yaml/index.js');
Expand Down Expand Up @@ -239,3 +241,44 @@
expect(config).toMatchSnapshot();
});
});

describe('rootRedoclyConfigSchema synchronization', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm reluctant to add a unit test for this here. Imagine you just want to add a property--but you wouldn't be able to do it without releasing a new config version. Can you move it to something like a smoke test (so it's not required for merging PRs)?

Copy link
Collaborator

@tatomyr tatomyr Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe term 'intergration test' is more relevant to our case though.

it('should have all spec version rules, preprocessors and decorators in rootRedoclyConfigSchema', () => {
const schemaProperties = rootRedoclyConfigSchema.properties as Record<string, unknown>;

const specVersionsRequiringConfig = specVersions.filter((version) => version !== 'overlay1');

const missingProperties: string[] = [];

for (const version of specVersionsRequiringConfig) {
const rulesKey = `${version}Rules`;
const preprocessorsKey = `${version}Preprocessors`;
const decoratorsKey = `${version}Decorators`;

if (!schemaProperties[rulesKey]) {
missingProperties.push(rulesKey);
}
if (!schemaProperties[preprocessorsKey]) {
missingProperties.push(preprocessorsKey);
}
if (!schemaProperties[decoratorsKey]) {
missingProperties.push(decoratorsKey);
}
}

if (!schemaProperties['overlay1Rules']) {
missingProperties.push('overlay1Rules');
}

if (missingProperties.length > 0) {
throw new Error(

Check failure on line 274 in packages/core/src/config/__tests__/config.test.ts

View workflow job for this annotation

GitHub Actions / build-and-unit

packages/core/src/config/__tests__/config.test.ts > rootRedoclyConfigSchema synchronization > should have all spec version rules, preprocessors and decorators in rootRedoclyConfigSchema

Error: Missing properties in rootRedoclyConfigSchema from @redocly/config package: oas3_2Rules oas3_2Preprocessors oas3_2Decorators When adding a new spec version, you must also add the corresponding properties (e.g., oas3_2Rules) to the rootRedoclyConfigSchema in the @redocly/config package. ❯ packages/core/src/config/__tests__/config.test.ts:274:13
`Missing properties in rootRedoclyConfigSchema from @redocly/config package:\n` +
` ${missingProperties.join('\n ')}\n\n` +
`When adding a new spec version, you must also add the corresponding properties ` +
`(e.g., ${missingProperties[0]}) to the rootRedoclyConfigSchema in the @redocly/config package.`
);
}

expect(missingProperties).toEqual([]);
});
});
Loading