@mintlify/cli 4.0.1077 → 4.0.1078
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.
- package/__test__/openApiCheck.test.ts +48 -8
- package/bin/cli.js +21 -31
- package/bin/openApiCheck.js +54 -0
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/cli.tsx +27 -39
- package/src/openApiCheck.tsx +51 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mintlify/cli",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1078",
|
|
4
4
|
"description": "The Mintlify CLI",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.0.0"
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
"vitest": "2.1.9",
|
|
96
96
|
"vitest-mock-process": "1.0.4"
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "9649cbed95403dc2d61e4f4a3b02a307ad7528ea"
|
|
99
99
|
}
|
package/src/cli.tsx
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { validate, getOpenApiDocumentFromUrl, isAllowedLocalSchemaUrl } from '@mintlify/common';
|
|
2
1
|
import {
|
|
3
2
|
buildGraph,
|
|
4
3
|
getBrokenExternalLinks,
|
|
@@ -19,12 +18,14 @@ import {
|
|
|
19
18
|
} from '@mintlify/previewing';
|
|
20
19
|
import { checkUrl } from '@mintlify/scraping';
|
|
21
20
|
import { render, Text } from 'ink';
|
|
21
|
+
import fs from 'node:fs/promises';
|
|
22
22
|
import path from 'path';
|
|
23
23
|
import yargs from 'yargs';
|
|
24
24
|
import { hideBin } from 'yargs/helpers';
|
|
25
25
|
|
|
26
26
|
import { accessibilityCheck } from './accessibilityCheck.js';
|
|
27
27
|
import { setTelemetryEnabled } from './config.js';
|
|
28
|
+
import { CMD_EXEC_PATH } from './constants.js';
|
|
28
29
|
import {
|
|
29
30
|
checkPort,
|
|
30
31
|
checkNodeVersion,
|
|
@@ -32,13 +33,13 @@ import {
|
|
|
32
33
|
getVersions,
|
|
33
34
|
suppressConsoleWarnings,
|
|
34
35
|
terminate,
|
|
35
|
-
readLocalOpenApiFile,
|
|
36
36
|
} from './helpers.js';
|
|
37
37
|
import { init } from './init.js';
|
|
38
38
|
import { login } from './login.js';
|
|
39
39
|
import { logout } from './logout.js';
|
|
40
40
|
import { mdxLinter } from './mdxLinter.js';
|
|
41
41
|
import { migrateMdx } from './migrateMdx.js';
|
|
42
|
+
import { checkOpenApiFile, getOpenApiFilenamesFromDocsConfig } from './openApiCheck.js';
|
|
42
43
|
import { scrapeSite, scrapePage, scrapeOpenApi } from './scrape.js';
|
|
43
44
|
import { status } from './status.js';
|
|
44
45
|
import { createTelemetryMiddleware } from './telemetry/middleware.js';
|
|
@@ -154,6 +155,24 @@ export const cli = ({ packageName = 'mint' }: { packageName?: string }) => {
|
|
|
154
155
|
.usage('usage: mintlify validate [options]')
|
|
155
156
|
.example('mintlify validate', 'validate the build'),
|
|
156
157
|
async (argv) => {
|
|
158
|
+
if (!argv['disable-openapi']) {
|
|
159
|
+
let openApiFilenames: string[] = [];
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
const docsJson = await fs.readFile(path.join(CMD_EXEC_PATH, 'docs.json'), 'utf-8');
|
|
163
|
+
openApiFilenames = getOpenApiFilenamesFromDocsConfig(JSON.parse(docsJson));
|
|
164
|
+
} catch {}
|
|
165
|
+
|
|
166
|
+
const results = await Promise.all(
|
|
167
|
+
openApiFilenames.map((file) => checkOpenApiFile(file, argv['local-schema']))
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
if (results.some((valid) => !valid)) {
|
|
171
|
+
await terminate(1);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
157
176
|
const { cli: cliVersion } = getVersions();
|
|
158
177
|
await validateBuild({
|
|
159
178
|
...argv,
|
|
@@ -200,7 +219,7 @@ export const cli = ({ packageName = 'mint' }: { packageName?: string }) => {
|
|
|
200
219
|
)
|
|
201
220
|
.command(
|
|
202
221
|
'openapi-check <filename>',
|
|
203
|
-
|
|
222
|
+
false,
|
|
204
223
|
(yargs) =>
|
|
205
224
|
yargs
|
|
206
225
|
.positional('filename', {
|
|
@@ -216,42 +235,11 @@ export const cli = ({ packageName = 'mint' }: { packageName?: string }) => {
|
|
|
216
235
|
'use a locally hosted schema file (note: only https protocol is supported in production)',
|
|
217
236
|
}),
|
|
218
237
|
async ({ filename, 'local-schema': localSchema }) => {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (filename.startsWith('http://') && !localSchema) {
|
|
227
|
-
addLog(
|
|
228
|
-
<WarningLog message="include the --local-schema flag to check locally hosted OpenAPI files" />
|
|
229
|
-
);
|
|
230
|
-
addLog(<WarningLog message="only https protocol is supported in production" />);
|
|
231
|
-
await terminate(0);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const document = await readLocalOpenApiFile(filename);
|
|
235
|
-
|
|
236
|
-
if (!document) {
|
|
237
|
-
throw new Error(
|
|
238
|
-
'failed to parse OpenAPI spec: could not parse file correctly, please check for any syntax errors.'
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
await validate(document);
|
|
242
|
-
addLog(<SuccessLog message="OpenAPI definition is valid." />);
|
|
243
|
-
} catch (err) {
|
|
244
|
-
if (err && typeof err === 'object' && 'code' in err && err.code === 'ENOENT') {
|
|
245
|
-
addLog(
|
|
246
|
-
<ErrorLog message={`file not found, please check the path provided: ${filename}`} />
|
|
247
|
-
);
|
|
248
|
-
} else {
|
|
249
|
-
addLog(<ErrorLog message={err instanceof Error ? err.message : 'unknown error'} />);
|
|
250
|
-
}
|
|
251
|
-
await terminate(1);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
await terminate(0);
|
|
238
|
+
addLog(
|
|
239
|
+
<WarningLog message="openapi-check is deprecated, use `mintlify validate` instead" />
|
|
240
|
+
);
|
|
241
|
+
const valid = await checkOpenApiFile(filename, localSchema);
|
|
242
|
+
await terminate(valid ? 0 : 1);
|
|
255
243
|
}
|
|
256
244
|
)
|
|
257
245
|
.command(
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { validate, getOpenApiDocumentFromUrl, isAllowedLocalSchemaUrl } from '@mintlify/common';
|
|
2
|
+
import { addLog, ErrorLog, SuccessLog, WarningLog } from '@mintlify/previewing';
|
|
3
|
+
import type { DocsConfig } from '@mintlify/validation';
|
|
4
|
+
|
|
5
|
+
import { readLocalOpenApiFile } from './helpers.js';
|
|
6
|
+
|
|
7
|
+
export const getOpenApiFilenamesFromDocsConfig = (config: Pick<DocsConfig, 'api'>): string[] => {
|
|
8
|
+
const openapi = config.api?.openapi;
|
|
9
|
+
if (openapi === undefined) return [];
|
|
10
|
+
if (typeof openapi === 'string') return [openapi];
|
|
11
|
+
if (Array.isArray(openapi)) return openapi;
|
|
12
|
+
return [openapi.source];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const checkOpenApiFile = async (
|
|
16
|
+
filename: string,
|
|
17
|
+
localSchema: boolean
|
|
18
|
+
): Promise<boolean> => {
|
|
19
|
+
try {
|
|
20
|
+
if (isAllowedLocalSchemaUrl(filename, localSchema)) {
|
|
21
|
+
await getOpenApiDocumentFromUrl(filename);
|
|
22
|
+
addLog(<SuccessLog message="OpenAPI definition is valid." />);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (filename.startsWith('http://') && !localSchema) {
|
|
27
|
+
addLog(
|
|
28
|
+
<WarningLog message="include the --local-schema flag to check locally hosted OpenAPI files" />
|
|
29
|
+
);
|
|
30
|
+
addLog(<WarningLog message="only https protocol is supported in production" />);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const document = await readLocalOpenApiFile(filename);
|
|
35
|
+
if (!document) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
'failed to parse OpenAPI spec: could not parse file correctly, please check for any syntax errors.'
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
await validate(document);
|
|
41
|
+
addLog(<SuccessLog message="OpenAPI definition is valid." />);
|
|
42
|
+
return true;
|
|
43
|
+
} catch (err) {
|
|
44
|
+
if (err && typeof err === 'object' && 'code' in err && err.code === 'ENOENT') {
|
|
45
|
+
addLog(<ErrorLog message={`file not found, please check the path provided: ${filename}`} />);
|
|
46
|
+
} else {
|
|
47
|
+
addLog(<ErrorLog message={err instanceof Error ? err.message : 'unknown error'} />);
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
};
|