mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-24 19:32:07 +00:00
Move filterSelectedOpenAPISchemas to @gitbook/openapi-parser (#3054)
This commit is contained in:
@@ -6,4 +6,5 @@ export type * from '@scalar/openapi-types';
|
||||
export * from './error';
|
||||
export * from './helpers/shouldIgnoreEntity';
|
||||
export * from './traverse';
|
||||
export * from './schemas';
|
||||
export type * from './types';
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { OpenAPIV3, OpenAPIV3_1 } from '@scalar/openapi-types';
|
||||
import { shouldIgnoreEntity } from './helpers/shouldIgnoreEntity';
|
||||
import type { OpenAPISchema } from './types';
|
||||
|
||||
/**
|
||||
* Extract selected schemas from the OpenAPI document.
|
||||
*/
|
||||
export function filterSelectedOpenAPISchemas(
|
||||
schema: OpenAPIV3.Document | OpenAPIV3_1.Document,
|
||||
selectedSchemas: string[]
|
||||
): OpenAPISchema[] {
|
||||
const componentsSchemas = schema.components?.schemas ?? {};
|
||||
|
||||
// Preserve the order of the selected schemas
|
||||
return selectedSchemas
|
||||
.map((name) => {
|
||||
const schema = componentsSchemas[name];
|
||||
if (schema && !shouldIgnoreEntity(schema)) {
|
||||
return {
|
||||
name,
|
||||
schema,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.filter((schema): schema is OpenAPISchema => !!schema);
|
||||
}
|
||||
@@ -79,3 +79,8 @@ export type FilesystemEntry<T extends AnyObject> = {
|
||||
filename: string;
|
||||
specification: T;
|
||||
};
|
||||
|
||||
export type OpenAPISchema = {
|
||||
name: string;
|
||||
schema: OpenAPIV3.SchemaObject;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user