Return empty string if no server provided (#2878)

This commit is contained in:
Nolann B.
2025-02-26 09:13:27 +01:00
committed by GitHub
parent a749c67803
commit f1d1d2fd81
3 changed files with 10 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@gitbook/react-openapi': patch
---
Return empty string if no server provided
@@ -50,9 +50,9 @@ describe('#getDefaultServerURL', () => {
expect(result).toBe('https://user.example.com/v1'); expect(result).toBe('https://user.example.com/v1');
}); });
it('returns null if no servers are provided', () => { it('returns empty string if no servers are provided', () => {
const servers: OpenAPIV3.ServerObject[] = []; const servers: OpenAPIV3.ServerObject[] = [];
const result = getDefaultServerURL(servers); const result = getDefaultServerURL(servers);
expect(result).toBeNull(); expect(result).toBe('');
}); });
}); });
+3 -2
View File
@@ -3,10 +3,11 @@ import { OpenAPIV3 } from '@gitbook/openapi-parser';
/** /**
* Get the default URL for the server. * Get the default URL for the server.
*/ */
export function getDefaultServerURL(servers: OpenAPIV3.ServerObject[]): null | string { export function getDefaultServerURL(servers: OpenAPIV3.ServerObject[]): string {
const server = servers[0]; const server = servers[0];
if (!server) { if (!server) {
return null; // Return empty string if no server is found to display nothing
return '';
} }
return interpolateServerURL(server); return interpolateServerURL(server);