@mintlify/prebuild 1.0.1012 → 1.0.1013

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ import { OpenApiFile } from '@mintlify/models';
2
+ export interface GetOpenApiFilesOptions {
3
+ mintIgnore?: string[];
4
+ disableOpenApi?: boolean;
5
+ }
6
+ export declare const getOpenApiFiles: (contentDirectoryPath: string, { mintIgnore, disableOpenApi }?: GetOpenApiFilesOptions) => Promise<OpenApiFile[]>;
@@ -0,0 +1,42 @@
1
+ import { validate } from '@mintlify/common';
2
+ import { readFile } from 'fs/promises';
3
+ import yaml from 'js-yaml';
4
+ import * as path from 'path';
5
+ import { getFileList } from '../fs/index.js';
6
+ import { getFileExtension } from '../utils.js';
7
+ import { addWarning } from './warnings.js';
8
+ export const getOpenApiFiles = async (contentDirectoryPath, { mintIgnore = [], disableOpenApi = false } = {}) => {
9
+ if (disableOpenApi)
10
+ return [];
11
+ const allFiles = getFileList(contentDirectoryPath, contentDirectoryPath, mintIgnore);
12
+ const openApiFiles = [];
13
+ for await (const filename of allFiles) {
14
+ const extension = getFileExtension(filename);
15
+ if (extension !== 'json' && extension !== 'yaml' && extension !== 'yml')
16
+ continue;
17
+ const filePath = path.join(contentDirectoryPath, filename);
18
+ const str = await readFile(filePath, 'utf8');
19
+ const obj = yaml.load(str);
20
+ if (!obj || typeof obj !== 'object')
21
+ continue;
22
+ if (!Object.keys(obj).includes('openapi'))
23
+ continue;
24
+ try {
25
+ const { schema: openApiDocument } = await validate(obj);
26
+ if (openApiDocument) {
27
+ openApiFiles.push({
28
+ filename: path.parse(filename).name,
29
+ spec: obj,
30
+ originalFileLocation: filename,
31
+ });
32
+ }
33
+ }
34
+ catch (error) {
35
+ addWarning({
36
+ type: 'openapi',
37
+ message: `Error validating OpenAPI file ${filename}: ${error}`,
38
+ });
39
+ }
40
+ }
41
+ return openApiFiles;
42
+ };
@@ -8,6 +8,7 @@ export declare const prebuild: (contentDirectoryPath: string, { localSchema, gro
8
8
  strict?: boolean;
9
9
  }) => Promise<PrebuildResult | undefined>;
10
10
  export * from './categorizeFilePaths.js';
11
+ export * from './getOpenApiFiles.js';
11
12
  export * from '../createPage/index.js';
12
13
  export * from '../createPage/preparseMdx/index.js';
13
14
  export * from './update/index.js';
@@ -36,6 +36,7 @@ export const prebuild = async (contentDirectoryPath, { localSchema, groups, disa
36
36
  return { fileImportsMap };
37
37
  };
38
38
  export * from './categorizeFilePaths.js';
39
+ export * from './getOpenApiFiles.js';
39
40
  export * from '../createPage/index.js';
40
41
  export * from '../createPage/preparseMdx/index.js';
41
42
  export * from './update/index.js';