File tree Expand file tree Collapse file tree 6 files changed +43
-36
lines changed
Expand file tree Collapse file tree 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';
66export * from './error' ;
77export * from './helpers/shouldIgnoreEntity' ;
88export * from './traverse' ;
9+ export * from './schemas' ;
910export 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> = {
7979 filename : string ;
8080 specification : T ;
8181} ;
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' ;
83import { dereferenceFilesystem } from '../dereference' ;
9- import type { OpenAPISchema , OpenAPISchemasData } from '../types' ;
4+ import type { OpenAPISchemasData } from '../types' ;
105
116//!!TODO: We should return only the schemas that are used in the block. Still a WIP awaiting future work.
127
@@ -32,26 +27,3 @@ export async function resolveOpenAPISchemas(
3227
3328 return { schemas } ;
3429}
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 11import type {
22 OpenAPICustomOperationProperties ,
33 OpenAPICustomSpecProperties ,
4+ OpenAPISchema ,
45 OpenAPIV3 ,
56} from '@gitbook/openapi-parser' ;
67
@@ -56,11 +57,6 @@ export interface OpenAPIOperationData extends OpenAPICustomSpecProperties {
5657 securities : [ string , OpenAPIV3 . SecuritySchemeObject ] [ ] ;
5758}
5859
59- export type OpenAPISchema = {
60- name : string ;
61- schema : OpenAPIV3 . SchemaObject ;
62- } ;
63-
6460export interface OpenAPISchemasData {
6561 /** Components schemas to be used for schemas */
6662 schemas : OpenAPISchema [ ] ;
You can’t perform that action at this time.
0 commit comments