Skip to content

Commit 1289304

Browse files
authored
chore!: refactor config loading and usage (#2131)
* remove benchmark from the openapi-core package * remove getMergedApiConfig * chore: update redocly/config to v0.26.2 * remove redundant layers when resolving config * merge StyleguideConfig into Config * remove internal usage of processRawConfig
1 parent 1e804cf commit 1289304

File tree

165 files changed

+2661
-3328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+2661
-3328
lines changed

.changeset/young-trains-brush.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@redocly/openapi-core": major
3+
---
4+
5+
Streamlined Redocly configuration interfaces for improved developer experience.
6+
Removed `StyleguideConfig` class in favor of the unified `Config` class.
7+
Removed `getMergedConfig` function - use `Config.forAlias()` method instead to retrieve API-specific configurations.

.github/workflows/pr-title.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ jobs:
1212
env:
1313
PR_TITLE: ${{ github.event.pull_request.title }}
1414
run: |
15-
if ! echo "$PR_TITLE" | grep -E "^(fix|feat|chore|docs)(\([a-z-]+\))?: (🔖 |🧪 )?[a-z].+[^.]$"; then
15+
if ! echo "$PR_TITLE" | grep -E "^(fix|feat|chore|docs)(\([a-z-]+\))?(\!)?: (🔖 |🧪 )?[a-z].+[^.]$"; then
1616
echo "❌ PR title '$PR_TITLE' does not match the required format"
1717
echo "Required format: type(scope): subject"
1818
echo "Examples:"
1919
echo " feat: add new feature"
2020
echo " fix(core): fix bug"
2121
echo " docs: update README"
22+
echo " chore!: breaking change"
2223
exit 1
2324
fi
2425
echo "✅ PR title format is valid"
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
Found undefined and using theme.openapi options
32
Prerendering docs
43

54
🎉 bundled successfully in: redoc-static.html (332 KiB) [⏱ <test>ms].

__tests__/check-config/invalid-config--lint-config-error/snapshot.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ Error was generated by the configuration struct rule.
1414

1515
❌ Your config has 1 error.
1616

17+

__tests__/check-config/invalid-config--no-option/snapshot.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ Error was generated by the configuration struct rule.
1414

1515
❌ Your config has 1 error.
1616

17+

__tests__/check-config/wrong-config-type-extensions-in-assertions/snapshot.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ Error was generated by the configuration struct rule.
1616
Deprecated plugin format detected: type-extension
1717
❌ Your config has 1 error.
1818

19+

__tests__/commands.test.ts

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,81 @@ describe('E2E', () => {
8282
const result = getCommandOutput(args, {}, { testPath });
8383
await expect(cleanupOutput(result)).toMatchFileSnapshot(join(testPath, 'snapshot.txt'));
8484
});
85+
86+
test('lint file by alias using file path (at the config level)', async () => {
87+
const dirName = 'assertions-severity-override';
88+
const testPath = join(__dirname, `lint/${dirName}`);
89+
90+
const args = getParams(indexEntryPoint, ['lint', 'openapi.yaml']);
91+
92+
const result = getCommandOutput(args, {}, { testPath });
93+
await expect(cleanupOutput(result)).toMatchFileSnapshot(join(testPath, 'snapshot.txt'));
94+
});
95+
96+
test('lint file by alias using file path (not from the config level)', async () => {
97+
const dirName = 'assertions-severity-override';
98+
const testPath = join(__dirname, `lint/${dirName}`);
99+
100+
const args = getParams(indexEntryPoint, [
101+
'lint',
102+
join(testPath, 'openapi.yaml'),
103+
'--config',
104+
join(testPath, 'redocly.yaml'),
105+
]);
106+
107+
const result = getCommandOutput(args, {}, {});
108+
await expect(cleanupOutput(result)).toMatchFileSnapshot(join(testPath, 'snapshot_2.txt'));
109+
});
110+
111+
test('lint file by alias using file path (without using extends in config) (at the config level)', async () => {
112+
const dirName = 'assertions-severity-override-without-extends';
113+
const testPath = join(__dirname, `lint/${dirName}`);
114+
115+
const args = getParams(indexEntryPoint, ['lint', 'openapi.yaml']);
116+
117+
const result = getCommandOutput(args, {}, { testPath });
118+
await expect(cleanupOutput(result)).toMatchFileSnapshot(join(testPath, 'snapshot.txt'));
119+
});
120+
121+
test('lint file by alias using file path (without using extends in config) (not from the config level)', async () => {
122+
const dirName = 'assertions-severity-override-without-extends';
123+
const testPath = join(__dirname, `lint/${dirName}`);
124+
125+
const args = getParams(indexEntryPoint, [
126+
'lint',
127+
join(testPath, 'openapi.yaml'),
128+
'--config',
129+
join(testPath, 'redocly.yaml'),
130+
]);
131+
132+
const result = getCommandOutput(args, {}, {});
133+
await expect(cleanupOutput(result)).toMatchFileSnapshot(join(testPath, 'snapshot_2.txt'));
134+
});
85135
});
86136

87137
describe('zero-config', () => {
88138
const folderPath = join(__dirname, 'zero-config');
89139

90-
it('default-recommended-fallback', async () => {
140+
test('default-recommended-fallback', async () => {
91141
const testPath = join(folderPath, 'default-recommended-fallback');
92142
const args = getParams(indexEntryPoint, ['lint', './openapi.yaml']);
93143
const result = getCommandOutput(args, {}, { testPath });
94144
await expect(cleanupOutput(result)).toMatchFileSnapshot(join(testPath, 'snapshot.txt'));
95145
});
96146

97-
it('no-default-recommended-fallback', async () => {
147+
test('no-default-recommended-fallback', async () => {
98148
const testPath = join(folderPath, 'no-default-recommended-fallback');
99149
const args = getParams(indexEntryPoint, ['lint', './openapi.yaml']);
100150
const result = getCommandOutput(args, {}, { testPath });
101151
await expect(cleanupOutput(result)).toMatchFileSnapshot(join(testPath, 'snapshot.txt'));
102152
});
153+
154+
test('no-default-recommended-fallback-with-empty-config', async () => {
155+
const testPath = join(folderPath, 'no-default-recommended-fallback-with-empty-config');
156+
const args = getParams(indexEntryPoint, ['lint', './openapi.yaml']);
157+
const result = getCommandOutput(args, {}, { testPath });
158+
await expect(cleanupOutput(result)).toMatchFileSnapshot(join(testPath, 'snapshot.txt'));
159+
});
103160
});
104161

105162
describe('check-config', () => {
@@ -597,6 +654,21 @@ describe('E2E', () => {
597654
const result = getCommandOutput(args, {}, { testPath });
598655
await expect(cleanupOutput(result)).toMatchFileSnapshot(join(testPath, 'snapshot_3.txt'));
599656
});
657+
658+
test('lint a specific api when alias is: specified (1); not specified (used the file path) (2)', async () => {
659+
const testPath = join(folderPath, 'apply-per-api-decorators');
660+
const args1 = getParams(indexEntryPoint, ['lint', '--config=nested/redocly.yaml', 'test@fs']);
661+
const result1 = getCommandOutput(args1, {}, { testPath });
662+
await expect(cleanupOutput(result1)).toMatchFileSnapshot(join(testPath, 'snapshot_4.txt'));
663+
664+
const args2 = getParams(indexEntryPoint, [
665+
'lint',
666+
'--config=nested/redocly.yaml',
667+
'nested/openapi/main.yaml',
668+
]);
669+
const result2 = getCommandOutput(args2, {}, { testPath });
670+
await expect(cleanupOutput(result2)).toMatchFileSnapshot(join(testPath, 'snapshot_4.txt'));
671+
});
600672
});
601673

602674
describe('build-docs', () => {

__tests__/lint-config/config-structure/snapshot.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,3 +631,4 @@ Error was generated by the configuration struct rule.
631631

632632
❌ Your config has 44 errors.
633633

634+

__tests__/lint-config/config-with-refs-extended/snapshot.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ Error was generated by the configuration struct rule.
8080

8181
❌ Your config has 6 errors.
8282

83+

__tests__/lint-config/invalid-config--lint-config-error/snapshot.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ Error was generated by the configuration struct rule.
1414

1515
❌ Your config has 1 error.
1616

17+

0 commit comments

Comments
 (0)