@mintlify/prebuild 1.0.1208 → 1.0.1210
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.
|
@@ -7,6 +7,7 @@ export declare const generateOpenApiFromDocsConfig: (navigation: NavigationConfi
|
|
|
7
7
|
targetDir?: string;
|
|
8
8
|
localSchema?: boolean;
|
|
9
9
|
invalidSpecFiles?: InvalidSpecFile[];
|
|
10
|
+
mountPaths?: string[];
|
|
10
11
|
writeFile?: (filename: string, content: string) => void | Promise<void>;
|
|
11
12
|
}) => Promise<{
|
|
12
13
|
newNav: NavigationConfig;
|
|
@@ -5,8 +5,20 @@ import { divisions, } from '@mintlify/validation';
|
|
|
5
5
|
import * as path from 'path';
|
|
6
6
|
import { findInvalidSpecFile } from '../../invalidSpecFiles.js';
|
|
7
7
|
const DEFAULT_OUTPUT_DIR = 'api-reference';
|
|
8
|
+
const normalizeMountPath = (mountPath) => mountPath.replace(/^\/+|\/+$/g, '');
|
|
9
|
+
const getMountPathForPath = (candidatePath, mountPaths) => {
|
|
10
|
+
if (!candidatePath)
|
|
11
|
+
return '';
|
|
12
|
+
const normalizedPath = candidatePath.replace(/^\/+/, '');
|
|
13
|
+
const candidates = mountPaths
|
|
14
|
+
.map(normalizeMountPath)
|
|
15
|
+
.filter(Boolean)
|
|
16
|
+
.sort((a, b) => b.length - a.length);
|
|
17
|
+
return (candidates.find((mountPath) => normalizedPath === mountPath || normalizedPath.startsWith(`${mountPath}/`)) ?? '');
|
|
18
|
+
};
|
|
19
|
+
const resolveMountPath = (specPath, outputDir, mountPaths) => getMountPathForPath(specPath, mountPaths) || getMountPathForPath(outputDir, mountPaths);
|
|
8
20
|
export const generateOpenApiFromDocsConfig = async (navigation, openApiFiles, pagesAcc, opts) => {
|
|
9
|
-
const { overwrite, writeFiles, targetDir, localSchema, invalidSpecFiles, writeFile } = opts;
|
|
21
|
+
const { overwrite, writeFiles, targetDir, localSchema, invalidSpecFiles, mountPaths = [], writeFile, } = opts;
|
|
10
22
|
const newOpenApiFiles = [];
|
|
11
23
|
const openApiFilePromises = new Map();
|
|
12
24
|
async function processOpenApiInNav(nav) {
|
|
@@ -53,6 +65,7 @@ export const generateOpenApiFromDocsConfig = async (navigation, openApiFiles, pa
|
|
|
53
65
|
writeFiles,
|
|
54
66
|
outDir: outputDir,
|
|
55
67
|
outDirBasePath: path.join(targetDir ?? '', 'src', '_props'),
|
|
68
|
+
mountPath: resolveMountPath(openApiFile.originalFileLocation, outputDir, mountPaths),
|
|
56
69
|
overwrite,
|
|
57
70
|
localSchema,
|
|
58
71
|
writeFile,
|
|
@@ -161,17 +174,19 @@ export const generateOpenApiFromDocsConfig = async (navigation, openApiFiles, pa
|
|
|
161
174
|
const tempNav = [];
|
|
162
175
|
const tempDecoratedNav = [];
|
|
163
176
|
const writePromises = [];
|
|
177
|
+
let generatedSlugs = [];
|
|
164
178
|
if (isWebhook) {
|
|
165
179
|
const webhooks = schema.webhooks;
|
|
166
180
|
const webhookMatch = findOpenApiPath(webhooks, endpoint);
|
|
167
181
|
if (!webhookMatch) {
|
|
168
182
|
throw new Error(`Webhook ${endpoint} not found in ${openapiPath}. ${webhooks ? `Available webhooks: ${Object.keys(webhooks).join(', ')}` : ''}`.trim());
|
|
169
183
|
}
|
|
170
|
-
processOpenApiWebhook(webhookMatch.pathKey, webhookMatch.pathItem, schema, tempNav, tempDecoratedNav, writePromises, pagesAcc, {
|
|
184
|
+
generatedSlugs = processOpenApiWebhook(webhookMatch.pathKey, webhookMatch.pathItem, schema, tempNav, tempDecoratedNav, writePromises, pagesAcc, {
|
|
171
185
|
openApiFilePath: openApiFile.originalFileLocation,
|
|
172
186
|
writeFiles,
|
|
173
187
|
outDir: currentDirectory ?? DEFAULT_OUTPUT_DIR,
|
|
174
188
|
outDirBasePath: path.join(targetDir ?? '', 'src', '_props'),
|
|
189
|
+
mountPath: resolveMountPath(openApiFile.originalFileLocation, currentDirectory, mountPaths),
|
|
175
190
|
overwrite,
|
|
176
191
|
localSchema,
|
|
177
192
|
writeFile,
|
|
@@ -187,34 +202,21 @@ export const generateOpenApiFromDocsConfig = async (navigation, openApiFiles, pa
|
|
|
187
202
|
if (!opObject) {
|
|
188
203
|
throw new Error(`Method ${method.toUpperCase()} for endpoint ${match.pathKey} not found in ${openapiPath}`);
|
|
189
204
|
}
|
|
190
|
-
processOpenApiPath(match.pathKey, { [method.toLowerCase()]: opObject }, schema, tempNav, tempDecoratedNav, writePromises, pagesAcc, {
|
|
205
|
+
generatedSlugs = processOpenApiPath(match.pathKey, { [method.toLowerCase()]: opObject }, schema, tempNav, tempDecoratedNav, writePromises, pagesAcc, {
|
|
191
206
|
openApiFilePath: openApiFile.originalFileLocation,
|
|
192
207
|
writeFiles,
|
|
193
208
|
outDir: currentDirectory ?? DEFAULT_OUTPUT_DIR,
|
|
194
209
|
outDirBasePath: path.join(targetDir ?? '', 'src', '_props'),
|
|
210
|
+
mountPath: resolveMountPath(openApiFile.originalFileLocation, currentDirectory, mountPaths),
|
|
195
211
|
overwrite,
|
|
196
212
|
localSchema,
|
|
197
213
|
writeFile,
|
|
198
214
|
}, findNavGroup);
|
|
199
215
|
}
|
|
200
216
|
await Promise.all(writePromises);
|
|
201
|
-
|
|
202
|
-
const firstEntry = tempNav[0];
|
|
203
|
-
if (firstEntry &&
|
|
204
|
-
typeof firstEntry === 'object' &&
|
|
205
|
-
'pages' in firstEntry &&
|
|
206
|
-
Array.isArray(firstEntry.pages) &&
|
|
207
|
-
firstEntry.pages.length > 0) {
|
|
208
|
-
slug = firstEntry.pages[0];
|
|
209
|
-
}
|
|
210
|
-
else if (typeof firstEntry === 'string') {
|
|
211
|
-
slug = firstEntry;
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
slug = Object.keys(pagesAcc).pop();
|
|
215
|
-
}
|
|
217
|
+
const slug = generatedSlugs[0];
|
|
216
218
|
if (!slug) {
|
|
217
|
-
throw new Error(
|
|
219
|
+
throw new Error(`Failed to generate OpenAPI endpoint page for ${method.toUpperCase()} ${endpoint} in ${openapiPath}`);
|
|
218
220
|
}
|
|
219
221
|
if (currentOpenApiOwner && !explicitOpenapiPath) {
|
|
220
222
|
skipBulkForNodeId.add(currentOpenApiOwner);
|