File tree 6 files changed +43
-36
lines changed
6 files changed +43
-36
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @gitbook/openapi-parser ' : patch
3
+ ' @gitbook/react-openapi ' : patch
4
+ ---
5
+
6
+ Move filterSelectedOpenAPISchemas to @gitbook/openapi-parser
Original file line number Diff line number Diff line change @@ -6,4 +6,5 @@ export type * from '@scalar/openapi-types';
6
6
export * from './error' ;
7
7
export * from './helpers/shouldIgnoreEntity' ;
8
8
export * from './traverse' ;
9
+ export * from './schemas' ;
9
10
export type * from './types' ;
Original file line number Diff line number Diff line change
1
+ import type { OpenAPIV3 , OpenAPIV3_1 } from '@scalar/openapi-types' ;
2
+ import { shouldIgnoreEntity } from './helpers/shouldIgnoreEntity' ;
3
+ import type { OpenAPISchema } from './types' ;
4
+
5
+ /**
6
+ * Extract selected schemas from the OpenAPI document.
7
+ */
8
+ export function filterSelectedOpenAPISchemas (
9
+ schema : OpenAPIV3 . Document | OpenAPIV3_1 . Document ,
10
+ selectedSchemas : string [ ]
11
+ ) : OpenAPISchema [ ] {
12
+ const componentsSchemas = schema . components ?. schemas ?? { } ;
13
+
14
+ // Preserve the order of the selected schemas
15
+ return selectedSchemas
16
+ . map ( ( name ) => {
17
+ const schema = componentsSchemas [ name ] ;
18
+ if ( schema && ! shouldIgnoreEntity ( schema ) ) {
19
+ return {
20
+ name,
21
+ schema,
22
+ } ;
23
+ }
24
+ return null ;
25
+ } )
26
+ . filter ( ( schema ) : schema is OpenAPISchema => ! ! schema ) ;
27
+ }
Original file line number Diff line number Diff line change @@ -79,3 +79,8 @@ export type FilesystemEntry<T extends AnyObject> = {
79
79
filename : string ;
80
80
specification : T ;
81
81
} ;
82
+
83
+ export type OpenAPISchema = {
84
+ name : string ;
85
+ schema : OpenAPIV3 . SchemaObject ;
86
+ } ;
Original file line number Diff line number Diff line change 1
- import {
2
- type Filesystem ,
3
- type OpenAPIV3 ,
4
- type OpenAPIV3_1 ,
5
- type OpenAPIV3xDocument ,
6
- shouldIgnoreEntity ,
7
- } from '@gitbook/openapi-parser' ;
1
+ import type { Filesystem , OpenAPIV3xDocument } from '@gitbook/openapi-parser' ;
2
+ import { filterSelectedOpenAPISchemas } from '@gitbook/openapi-parser' ;
8
3
import { dereferenceFilesystem } from '../dereference' ;
9
- import type { OpenAPISchema , OpenAPISchemasData } from '../types' ;
4
+ import type { OpenAPISchemasData } from '../types' ;
10
5
11
6
//!!TODO: We should return only the schemas that are used in the block. Still a WIP awaiting future work.
12
7
@@ -32,26 +27,3 @@ export async function resolveOpenAPISchemas(
32
27
33
28
return { schemas } ;
34
29
}
35
- /**
36
- * Extract selected schemas from the OpenAPI document.
37
- */
38
- export function filterSelectedOpenAPISchemas (
39
- schema : OpenAPIV3 . Document | OpenAPIV3_1 . Document ,
40
- selectedSchemas : string [ ]
41
- ) : OpenAPISchema [ ] {
42
- const componentsSchemas = schema . components ?. schemas ?? { } ;
43
-
44
- // Preserve the order of the selected schemas
45
- return selectedSchemas
46
- . map ( ( name ) => {
47
- const schema = componentsSchemas [ name ] ;
48
- if ( schema && ! shouldIgnoreEntity ( schema ) ) {
49
- return {
50
- name,
51
- schema,
52
- } ;
53
- }
54
- return null ;
55
- } )
56
- . filter ( ( schema ) : schema is OpenAPISchema => ! ! schema ) ;
57
- }
Original file line number Diff line number Diff line change 1
1
import type {
2
2
OpenAPICustomOperationProperties ,
3
3
OpenAPICustomSpecProperties ,
4
+ OpenAPISchema ,
4
5
OpenAPIV3 ,
5
6
} from '@gitbook/openapi-parser' ;
6
7
@@ -56,11 +57,6 @@ export interface OpenAPIOperationData extends OpenAPICustomSpecProperties {
56
57
securities : [ string , OpenAPIV3 . SecuritySchemeObject ] [ ] ;
57
58
}
58
59
59
- export type OpenAPISchema = {
60
- name : string ;
61
- schema : OpenAPIV3 . SchemaObject ;
62
- } ;
63
-
64
60
export interface OpenAPISchemasData {
65
61
/** Components schemas to be used for schemas */
66
62
schemas : OpenAPISchema [ ] ;
You can’t perform that action at this time.
0 commit comments