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