1
- import { fetchOpenAPIFilesystem } from '@/lib/openapi/fetch' ;
2
- import type { ResolveOpenAPIBlockResult } from '@/lib/openapi/types' ;
3
1
import { OpenAPIParseError } from '@gitbook/openapi-parser' ;
4
2
import { type OpenAPISchemasData , resolveOpenAPISchemas } from '@gitbook/react-openapi' ;
5
- import type { AnyOpenAPIBlock , ResolveOpenAPIBlockArgs } from './types' ;
3
+ import { fetchOpenAPIFilesystem } from './fetch' ;
4
+ import type {
5
+ OpenAPISchemasBlock ,
6
+ ResolveOpenAPIBlockArgs ,
7
+ ResolveOpenAPIBlockResult ,
8
+ } from './types' ;
6
9
7
10
type ResolveOpenAPISchemasBlockResult = ResolveOpenAPIBlockResult < OpenAPISchemasData > ;
8
11
9
- const weakmap = new WeakMap < AnyOpenAPIBlock , Promise < ResolveOpenAPISchemasBlockResult > > ( ) ;
12
+ const weakmap = new WeakMap < OpenAPISchemasBlock , Promise < ResolveOpenAPISchemasBlockResult > > ( ) ;
10
13
11
14
/**
12
15
* Cache the result of resolving an OpenAPI block.
13
16
* It is important because the resolve is called in sections and in the block itself.
14
17
*/
15
18
export function resolveOpenAPISchemasBlock (
16
- args : ResolveOpenAPIBlockArgs
19
+ args : ResolveOpenAPIBlockArgs < OpenAPISchemasBlock >
17
20
) : Promise < ResolveOpenAPISchemasBlockResult > {
18
21
if ( weakmap . has ( args . block ) ) {
19
22
return weakmap . get ( args . block ) ! ;
@@ -28,10 +31,10 @@ export function resolveOpenAPISchemasBlock(
28
31
* Resolve OpenAPI schemas block.
29
32
*/
30
33
async function baseResolveOpenAPISchemasBlock (
31
- args : ResolveOpenAPIBlockArgs
34
+ args : ResolveOpenAPIBlockArgs < OpenAPISchemasBlock >
32
35
) : Promise < ResolveOpenAPISchemasBlockResult > {
33
36
const { context, block } = args ;
34
- if ( ! block . data . path || ! block . data . method ) {
37
+ if ( ! block . data . schemas || ! block . data . schemas . length ) {
35
38
return { data : null , specUrl : null } ;
36
39
}
37
40
@@ -42,7 +45,9 @@ async function baseResolveOpenAPISchemasBlock(
42
45
return { data : null , specUrl : null } ;
43
46
}
44
47
45
- const data = await resolveOpenAPISchemas ( filesystem ) ;
48
+ const data = await resolveOpenAPISchemas ( filesystem , {
49
+ schemas : block . data . schemas ,
50
+ } ) ;
46
51
47
52
return { data, specUrl } ;
48
53
} catch ( error ) {
0 commit comments