(
args: ResolveOpenAPIBlockArgs<AnyOpenAPIBlock>
)
| 25 | * Fetch OpenAPI block. |
| 26 | */ |
| 27 | export 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. |
no test coverage detected
searching dependent graphs…