@mintlify/scraping 4.0.137 → 4.0.139

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintlify/scraping",
3
- "version": "4.0.137",
3
+ "version": "4.0.139",
4
4
  "description": "Scrape documentation frameworks to Mintlify docs",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -38,7 +38,7 @@
38
38
  "format:check": "prettier . --check"
39
39
  },
40
40
  "dependencies": {
41
- "@mintlify/common": "1.0.291",
41
+ "@mintlify/common": "1.0.293",
42
42
  "@mintlify/openapi-parser": "^0.0.7",
43
43
  "fs-extra": "^11.1.1",
44
44
  "hast-util-to-mdast": "^10.1.0",
@@ -61,7 +61,7 @@
61
61
  "@mintlify/models": "0.0.175",
62
62
  "@mintlify/prettier-config": "1.0.4",
63
63
  "@mintlify/ts-config": "2.0.2",
64
- "@mintlify/validation": "0.1.310",
64
+ "@mintlify/validation": "0.1.312",
65
65
  "@trivago/prettier-plugin-sort-imports": "^4.2.1",
66
66
  "@tsconfig/recommended": "1.x",
67
67
  "@types/hast": "^3.0.4",
@@ -78,5 +78,5 @@
78
78
  "typescript": "^5.5.3",
79
79
  "vitest": "^2.0.4"
80
80
  },
81
- "gitHead": "4f3cc5724e880a693746426e868f9ec83ecfb3a0"
81
+ "gitHead": "e3a0a63406ce2444d1c8bff5c3ca77238b96ed77"
82
82
  }
@@ -166,3 +166,61 @@ export function processOpenApiPath<N, DN>(
166
166
  }
167
167
 
168
168
  export const DEFAULT_API_GROUP_NAME = 'API Reference';
169
+ export const DEFAULT_WEBHOOK_GROUP_NAME = 'Webhooks';
170
+
171
+ export function processOpenApiWebhook<N, DN>(
172
+ webhook: string,
173
+ webhookObject: OpenAPIV3.PathItemObject,
174
+ _schema: OpenAPI.Document,
175
+ nav: N,
176
+ decoratedNav: DN,
177
+ writePromises: Promise<void>[],
178
+ pagesAcc: Record<string, DecoratedNavigationPage>,
179
+ options: GenerateOpenApiPagesOptions,
180
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
181
+ findNavGroup: (nav: any, groupName?: string) => any
182
+ ) {
183
+ const openApiFilePathFromRoot = options.openApiFilePath
184
+ ? optionallyAddLeadingSlash(options.openApiFilePath)
185
+ : undefined;
186
+
187
+ Object.values(OpenAPIV3.HttpMethods).forEach((method) => {
188
+ if (method in webhookObject) {
189
+ const operation = webhookObject[method];
190
+ const groupName = operation?.tags?.[0] ?? DEFAULT_WEBHOOK_GROUP_NAME;
191
+ const title =
192
+ prepareStringToBeValidFilename(operation?.summary) ??
193
+ `${prepareStringToBeValidFilename(webhook)}`;
194
+ const folder = prepareStringToBeValidFilename(groupName) ?? '';
195
+ const base = join(options.outDir ?? '', folder, title);
196
+
197
+ const navGroup = findNavGroup(nav, groupName);
198
+ const decoratedNavGroup = findNavGroup(decoratedNav, groupName);
199
+
200
+ const filenameWithoutExtension = generateUniqueFilenameWithoutExtension(navGroup, base);
201
+
202
+ const openapiMetaTag = `${
203
+ openApiFilePathFromRoot ? `${openApiFilePathFromRoot} ` : ''
204
+ }webhook ${webhook}`;
205
+
206
+ const description = operation?.description;
207
+
208
+ navGroup.push(filenameWithoutExtension);
209
+ const page: DecoratedNavigationPage = {
210
+ openapi: openapiMetaTag,
211
+ href: resolve('/', filenameWithoutExtension),
212
+ title: slugToTitle(filenameWithoutExtension),
213
+ description,
214
+ version: options.version,
215
+ };
216
+ decoratedNavGroup.push(page);
217
+ pagesAcc[filenameWithoutExtension] = page;
218
+ const targetPath = options.outDirBasePath
219
+ ? join(options.outDirBasePath, `${filenameWithoutExtension}.mdx`)
220
+ : `${filenameWithoutExtension}.mdx`;
221
+ if (options.writeFiles && (!fse.pathExistsSync(targetPath) || options.overwrite)) {
222
+ writePromises.push(createOpenApiFrontmatter(targetPath, openapiMetaTag, options.version));
223
+ }
224
+ }
225
+ });
226
+ }
@@ -14,6 +14,7 @@ import {
14
14
  OpenApiPageGenerationResult,
15
15
  processOpenApiPath,
16
16
  DEFAULT_API_GROUP_NAME,
17
+ processOpenApiWebhook,
17
18
  } from './common.js';
18
19
 
19
20
  export async function generateOpenApiPages(
@@ -23,8 +24,17 @@ export async function generateOpenApiPages(
23
24
  const { document, isUrl } = await getOpenApiDefinition(pathOrDocumentOrUrl);
24
25
  const { schema } = await validate(document);
25
26
 
26
- if (schema?.paths === undefined || Object.keys(schema.paths).length === 0) {
27
+ if (
28
+ schema?.openapi === '3.0.0' &&
29
+ (schema.paths === undefined || Object.keys(schema.paths).length === 0)
30
+ ) {
27
31
  throw new Error('No paths defined.');
32
+ } else if (
33
+ schema?.openapi === '3.1.0' &&
34
+ (schema.paths === undefined || Object.keys(schema.paths).length === 0) &&
35
+ (schema.webhooks === undefined || Object.keys(schema.webhooks).length === 0)
36
+ ) {
37
+ throw new Error('No paths or webhooks defined.');
28
38
  }
29
39
 
30
40
  const nav: Navigation = [];
@@ -32,22 +42,43 @@ export async function generateOpenApiPages(
32
42
  const writePromises: Promise<void>[] = [];
33
43
  const pagesAcc: Record<string, DecoratedNavigationPage> = {};
34
44
 
35
- Object.entries(schema.paths).forEach(([path, pathItemObject]) => {
36
- if (!pathItemObject || typeof pathItemObject !== 'object') {
37
- return;
38
- }
39
- processOpenApiPath<Navigation, DecoratedNavigation>(
40
- path,
41
- pathItemObject,
42
- schema as OpenAPI.Document,
43
- nav,
44
- decoratedNav,
45
- writePromises,
46
- pagesAcc,
47
- opts ?? {},
48
- findNavGroup
49
- );
50
- });
45
+ if (schema?.paths) {
46
+ Object.entries(schema.paths).forEach(([path, pathItemObject]) => {
47
+ if (!pathItemObject || typeof pathItemObject !== 'object') {
48
+ return;
49
+ }
50
+ processOpenApiPath<Navigation, DecoratedNavigation>(
51
+ path,
52
+ pathItemObject,
53
+ schema as OpenAPI.Document,
54
+ nav,
55
+ decoratedNav,
56
+ writePromises,
57
+ pagesAcc,
58
+ opts ?? {},
59
+ findNavGroup
60
+ );
61
+ });
62
+ }
63
+
64
+ if (schema?.webhooks) {
65
+ Object.entries(schema.webhooks).forEach(([webhook, webhookObject]) => {
66
+ if (!webhookObject || typeof webhookObject !== 'object') {
67
+ return;
68
+ }
69
+ processOpenApiWebhook<Navigation, DecoratedNavigation>(
70
+ webhook,
71
+ webhookObject,
72
+ schema as OpenAPI.Document,
73
+ nav,
74
+ decoratedNav,
75
+ writePromises,
76
+ pagesAcc,
77
+ opts ?? {},
78
+ findNavGroup
79
+ );
80
+ });
81
+ }
51
82
 
52
83
  await Promise.all(writePromises);
53
84
 
@@ -59,6 +90,7 @@ export async function generateOpenApiPages(
59
90
  isUrl,
60
91
  };
61
92
  }
93
+
62
94
  const findNavGroup = <T extends NavigationGroup | DecoratedNavigationGroup>(
63
95
  nav: T['pages'][number][],
64
96
  groupName: string = DEFAULT_API_GROUP_NAME
@@ -14,6 +14,7 @@ import {
14
14
  OpenApiPageGenerationResult,
15
15
  processOpenApiPath,
16
16
  DEFAULT_API_GROUP_NAME,
17
+ processOpenApiWebhook,
17
18
  } from './common.js';
18
19
 
19
20
  export async function generateOpenApiPagesForDocsConfig(
@@ -23,8 +24,17 @@ export async function generateOpenApiPagesForDocsConfig(
23
24
  const { document, isUrl } = await getOpenApiDefinition(pathOrDocumentOrUrl);
24
25
  const { schema } = await validate(document);
25
26
 
26
- if (schema?.paths === undefined || Object.keys(schema.paths).length === 0) {
27
+ if (
28
+ schema?.openapi === '3.0.0' &&
29
+ (schema.paths === undefined || Object.keys(schema.paths).length === 0)
30
+ ) {
27
31
  throw new Error('No paths defined.');
32
+ } else if (
33
+ schema?.openapi === '3.1.0' &&
34
+ (schema.paths === undefined || Object.keys(schema.paths).length === 0) &&
35
+ (schema.webhooks === undefined || Object.keys(schema.webhooks).length === 0)
36
+ ) {
37
+ throw new Error('No paths or webhooks defined.');
28
38
  }
29
39
 
30
40
  const nav: GroupsConfig = [];
@@ -32,22 +42,43 @@ export async function generateOpenApiPagesForDocsConfig(
32
42
  const writePromises: Promise<void>[] = [];
33
43
  const pagesAcc: Record<string, DecoratedNavigationPage> = {};
34
44
 
35
- Object.entries(schema.paths).forEach(([path, pathItemObject]) => {
36
- if (!pathItemObject || typeof pathItemObject !== 'object') {
37
- return;
38
- }
39
- processOpenApiPath<GroupsConfig, DecoratedGroupsConfig>(
40
- path,
41
- pathItemObject,
42
- schema as OpenAPI.Document,
43
- nav,
44
- decoratedNav,
45
- writePromises,
46
- pagesAcc,
47
- opts ?? {},
48
- findNavGroup
49
- );
50
- });
45
+ if (schema?.paths) {
46
+ Object.entries(schema.paths).forEach(([path, pathItemObject]) => {
47
+ if (!pathItemObject || typeof pathItemObject !== 'object') {
48
+ return;
49
+ }
50
+ processOpenApiPath<GroupsConfig, DecoratedGroupsConfig>(
51
+ path,
52
+ pathItemObject,
53
+ schema as OpenAPI.Document,
54
+ nav,
55
+ decoratedNav,
56
+ writePromises,
57
+ pagesAcc,
58
+ opts ?? {},
59
+ findNavGroup
60
+ );
61
+ });
62
+ }
63
+
64
+ if (schema?.webhooks) {
65
+ Object.entries(schema.webhooks).forEach(([webhook, webhookObject]) => {
66
+ if (!webhookObject || typeof webhookObject !== 'object') {
67
+ return;
68
+ }
69
+ processOpenApiWebhook<GroupsConfig, DecoratedGroupsConfig>(
70
+ webhook,
71
+ webhookObject,
72
+ schema as OpenAPI.Document,
73
+ nav,
74
+ decoratedNav,
75
+ writePromises,
76
+ pagesAcc,
77
+ opts ?? {},
78
+ findNavGroup
79
+ );
80
+ });
81
+ }
51
82
 
52
83
  await Promise.all(writePromises);
53
84