mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-12 05:48:57 +00:00
Add option to pass scalar plugins (#3027)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@gitbook/openapi-parser': patch
|
||||
---
|
||||
|
||||
Add option to pass scalar plugins
|
||||
@@ -1,4 +1,5 @@
|
||||
import { type AnyApiDefinitionFormat, load } from '@scalar/openapi-parser';
|
||||
import { load } from '@scalar/openapi-parser';
|
||||
import type { ParseOpenAPIInput } from './parse';
|
||||
import { fetchURLs } from './scalar-plugins/fetchURLs';
|
||||
import type { Filesystem } from './types';
|
||||
|
||||
@@ -6,19 +7,13 @@ import type { Filesystem } from './types';
|
||||
* Create a filesystem from an OpenAPI document.
|
||||
* Fetches all the URLs specified in references and builds a filesystem.
|
||||
*/
|
||||
export async function createFileSystem(input: {
|
||||
/**
|
||||
* The OpenAPI document to create the filesystem from.
|
||||
*/
|
||||
value: AnyApiDefinitionFormat;
|
||||
/**
|
||||
* The root URL of the specified OpenAPI document.
|
||||
* Used to resolve relative URLs.
|
||||
*/
|
||||
rootURL: string | null;
|
||||
}): Promise<Filesystem> {
|
||||
const { filesystem } = await load(input.value, {
|
||||
plugins: [fetchURLs({ rootURL: input.rootURL })],
|
||||
export async function createFileSystem(
|
||||
input: Pick<ParseOpenAPIInput, 'value' | 'rootURL' | 'options'>
|
||||
): Promise<Filesystem> {
|
||||
const { value, rootURL, options } = input;
|
||||
|
||||
const { filesystem } = await load(value, {
|
||||
plugins: [fetchURLs({ rootURL }), ...(options?.plugins || [])],
|
||||
});
|
||||
|
||||
return filesystem;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { AnyApiDefinitionFormat } from '@scalar/openapi-parser';
|
||||
import type { AnyApiDefinitionFormat, LoadPlugin } from '@scalar/openapi-parser';
|
||||
import { OpenAPIParseError } from './error';
|
||||
import { convertOpenAPIV2ToOpenAPIV3 } from './v2';
|
||||
import { parseOpenAPIV3 } from './v3';
|
||||
@@ -16,6 +16,12 @@ export interface ParseOpenAPIInput {
|
||||
* Trust the input. This will skip advanced validation.
|
||||
*/
|
||||
trust?: boolean;
|
||||
/**
|
||||
* Options for the parser.
|
||||
*/
|
||||
options?: {
|
||||
plugins?: LoadPlugin[];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,12 +12,16 @@ import type { Filesystem, OpenAPIV3xDocument } from './types';
|
||||
export async function parseOpenAPIV3(
|
||||
input: ParseOpenAPIInput
|
||||
): Promise<Filesystem<OpenAPIV3xDocument>> {
|
||||
const { value, rootURL, trust } = input;
|
||||
const { value, rootURL, trust, options = {} } = input;
|
||||
const specification = trust
|
||||
? await trustedValidate({ value, rootURL })
|
||||
: await untrustedValidate({ value, rootURL });
|
||||
|
||||
const filesystem = await createFileSystem({ value: specification, rootURL });
|
||||
const filesystem = await createFileSystem({
|
||||
value: specification,
|
||||
rootURL,
|
||||
options,
|
||||
});
|
||||
|
||||
return filesystem;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user