mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-25 03:42:30 +00:00
29 lines
844 B
TypeScript
29 lines
844 B
TypeScript
import type { Filesystem, OpenAPISchema, OpenAPIV3xDocument } from '@gitbook/openapi-parser';
|
|
import { filterSelectedOpenAPISchemas } from '@gitbook/openapi-parser';
|
|
import { dereferenceFilesystem } from '../dereference';
|
|
|
|
/**
|
|
* Resolve an OpenAPI schemas from a file and compile it to a more usable format.
|
|
* Schemas are extracted from the OpenAPI components.schemas
|
|
*/
|
|
export async function resolveOpenAPISchemas(
|
|
filesystem: Filesystem<OpenAPIV3xDocument>,
|
|
options: {
|
|
schemas: string[];
|
|
}
|
|
): Promise<{
|
|
schemas: OpenAPISchema[];
|
|
} | null> {
|
|
const { schemas: selectedSchemas } = options;
|
|
|
|
const schema = await dereferenceFilesystem(filesystem);
|
|
|
|
const schemas = filterSelectedOpenAPISchemas(schema, selectedSchemas);
|
|
|
|
if (schemas.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
return { schemas };
|
|
}
|