MCPcopy Create free account
hub / github.com/GitbookIO/gitbook / fetchOpenAPIFilesystem

Function fetchOpenAPIFilesystem

packages/gitbook/src/lib/openapi/fetch.ts:27–54  ·  view source on GitHub ↗
(
    args: ResolveOpenAPIBlockArgs<AnyOpenAPIBlock>
)

Source from the content-addressed store, hash-verified

25 * Fetch OpenAPI block.
26 */
27export async function fetchOpenAPIFilesystem(
28 args: ResolveOpenAPIBlockArgs<AnyOpenAPIBlock>
29): Promise<FetchOpenAPIFilesystemResult> {
30 const { context, block } = args;
31
32 const ref = block.data.ref;
33 const resolved = ref ? await resolveContentRef(ref, context) : null;
34
35 if (!resolved) {
36 return { filesystem: null, specUrl: null };
37 }
38
39 const result = await (() => {
40 // If the reference is a new OpenAPI reference, we return it.
41 if (ref.kind === 'openapi') {
42 assert(resolved.openAPIFilesystem);
43 return resolved.openAPIFilesystem;
44 }
45 // For legacy blocks ("swagger"), we need to fetch the file system.
46 return fetchFilesystem(resolved.href, context.space.id);
47 })();
48
49 if ('error' in result) {
50 throw new OpenAPIParseError(result.error.message, { code: result.error.code });
51 }
52
53 return { filesystem: result, specUrl: resolved.href };
54}
55
56/**
57 * Fetch the filesystem from the URL.

Calls 2

resolveContentRefFunction · 0.90
fetchFilesystemFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…