Skip to content

Commit 10a3c1c

Browse files
committed
fix(respect): error handling when servers are missing from both openapi and cli options
1 parent 9529a45 commit 10a3c1c

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

.changeset/sweet-pumpkins-wait.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@redocly/respect-core": patch
3+
"@redocly/cli": patch
4+
---
5+
6+
Improved Respect's error handling when server URLs are missing from both OpenAPI descriptions and CLI options. Now provides a clearer error message when no server URL is available.

__tests__/smoke/run-smoke.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ echo "✅ Docs built correctly."
2727
# Check for broken $refs (or other issues) in the split files, especially on Windows (it will fail on a difference)
2828
echo "Checking split files for issues..."
2929
diff -r pre-split output/split
30-
echo "✅ Files split correctly."
30+
echo "✅ Files split correctly."

packages/respect-core/src/modules/__tests__/flow-runner/get-server-url.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,15 @@ describe('getServerUrl', () => {
365365
],
366366
});
367367
});
368+
369+
it('should return undefined when descriptionName is provided but servers are undefined in sourceDescription', () => {
370+
const ctx = {
371+
$sourceDescriptions: {
372+
test: { servers: undefined },
373+
},
374+
} as unknown as TestContext;
375+
376+
const result = getServerUrl({ ctx, descriptionName: 'test' });
377+
expect(result).toBeUndefined();
378+
});
368379
});

packages/respect-core/src/modules/flow-runner/get-server-url.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export function getServerUrl({
112112
!descriptionName ||
113113
!ctx.$sourceDescriptions ||
114114
!ctx.$sourceDescriptions[descriptionName] ||
115-
!ctx.$sourceDescriptions[descriptionName].servers.length
115+
!ctx.$sourceDescriptions[descriptionName]?.servers?.length
116116
) {
117117
return undefined;
118118
}

scripts/local-pack.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ cd ../../
2929
# Restore original package.json files
3030
mv packages/core/package.json.bak packages/core/package.json
3131
mv packages/respect-core/package.json.bak packages/respect-core/package.json
32-
mv packages/cli/package.json.bak packages/cli/package.json
32+
mv packages/cli/package.json.bak packages/cli/package.json

0 commit comments

Comments
 (0)