@mintlify/common 1.0.1356 → 1.0.1357

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.
@@ -1,3 +1,12 @@
1
1
  import { NavigationEntry } from '@mintlify/models';
2
+ import type { OpenApiSlugSource } from '@mintlify/validation';
2
3
  export declare const prepareStringToBeValidFilename: (str?: string) => string | undefined;
3
4
  export declare const generateUniqueFilenameWithoutExtension: (pages: NavigationEntry[] | Readonly<Record<string, unknown>>, base: string) => string;
5
+ export type { OpenApiSlugSource };
6
+ export declare const operationIdToSlug: (operationId?: string) => string | undefined;
7
+ export declare const getOperationSlugBase: ({ slugSource, operationId, summary, fallback, }: {
8
+ slugSource: OpenApiSlugSource | undefined;
9
+ operationId: string | undefined;
10
+ summary: string | undefined;
11
+ fallback: () => string;
12
+ }) => string;
@@ -26,3 +26,23 @@ export const generateUniqueFilenameWithoutExtension = (pages, base) => {
26
26
  }
27
27
  return filename.toLowerCase();
28
28
  };
29
+ export const operationIdToSlug = (operationId) => {
30
+ if (!operationId)
31
+ return undefined;
32
+ const slug = operationId
33
+ .replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
34
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
35
+ .replace(/[^A-Za-z0-9]+/g, '-')
36
+ .replace(/^-+|-+$/g, '')
37
+ .toLowerCase();
38
+ return slug.length > 0 ? slug : undefined;
39
+ };
40
+ export const getOperationSlugBase = ({ slugSource, operationId, summary, fallback, }) => {
41
+ var _a;
42
+ if (slugSource === 'operationId') {
43
+ const fromOperationId = operationIdToSlug(operationId);
44
+ if (fromOperationId)
45
+ return fromOperationId;
46
+ }
47
+ return (_a = prepareStringToBeValidFilename(summary)) !== null && _a !== void 0 ? _a : fallback();
48
+ };
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import type { PageMetaTags } from '@mintlify/models';
7
7
  import { type DocumentV3 } from '@mintlify/validation';
8
+ import { type OpenApiSlugSource } from './filenameUtils.js';
8
9
  import { type OpenApiTagGroup } from './tagHierarchy.js';
9
10
  /**
10
11
  * Build MDX content string matching what createOpenApiFrontmatter produces in prebuild.
@@ -50,5 +51,7 @@ export type GenerateOpenApiPagesOptions = {
50
51
  outputDirectory?: string;
51
52
  /** Optional API version string */
52
53
  version?: string;
54
+ /** What the last slug segment is derived from; defaults to the operation summary */
55
+ slug?: OpenApiSlugSource;
53
56
  };
54
57
  export declare function generateOpenApiPages(opts: GenerateOpenApiPagesOptions): GeneratedApiPage[];
@@ -4,7 +4,7 @@ import { optionallyAddLeadingSlash } from '../fs/optionallySlash.js';
4
4
  import { mergePageGroups } from '../navigation/groupAccess.js';
5
5
  import { slugToTitle } from '../slug/slugToTitle.js';
6
6
  import { buildOpenApiMetaTag } from './buildOpenApiMetaTag.js';
7
- import { prepareStringToBeValidFilename, generateUniqueFilenameWithoutExtension, } from './filenameUtils.js';
7
+ import { prepareStringToBeValidFilename, generateUniqueFilenameWithoutExtension, getOperationSlugBase, } from './filenameUtils.js';
8
8
  import { getOpenApiTitleAndDescription } from './getOpenApiTitleAndDescription.js';
9
9
  import { createOpenApiBadgeResolver, createOpenApiTagResolver, isOpenApi32, } from './tagHierarchy.js';
10
10
  /**
@@ -74,8 +74,8 @@ function getXMintGroups(pathObject, operationObject) {
74
74
  }
75
75
  export function generateOpenApiPages(opts) {
76
76
  var _a, _b, _c, _d, _e, _f, _g, _h;
77
- var _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
78
- const { spec, specFilePath, outputDirectory } = opts;
77
+ var _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
78
+ const { spec, specFilePath, outputDirectory, slug: slugSource } = opts;
79
79
  const outDir = outputDirectory !== null && outputDirectory !== void 0 ? outputDirectory : DEFAULT_OUTPUT_DIR;
80
80
  const openApiFilePathFromRoot = optionallyAddLeadingSlash(specFilePath);
81
81
  const pages = [];
@@ -108,8 +108,13 @@ export function generateOpenApiPages(opts) {
108
108
  const tagPath = resolveTags(operation.tags);
109
109
  const tagName = (_a = tagPath.at(-1)) === null || _a === void 0 ? void 0 : _a.name;
110
110
  const groupName = (_b = tagPath.at(-1)) === null || _b === void 0 ? void 0 : _b.label;
111
- let title = (_m = prepareStringToBeValidFilename(operation.summary)) !== null && _m !== void 0 ? _m : `${method.toLowerCase()}-${prepareStringToBeValidFilename(apiPath)}`;
112
- let folder = (_o = prepareStringToBeValidFilename(tagName)) !== null && _o !== void 0 ? _o : '';
111
+ let title = getOperationSlugBase({
112
+ slugSource,
113
+ operationId: operation.operationId,
114
+ summary: operation.summary,
115
+ fallback: () => `${method.toLowerCase()}-${prepareStringToBeValidFilename(apiPath)}`,
116
+ });
117
+ let folder = (_m = prepareStringToBeValidFilename(tagName)) !== null && _m !== void 0 ? _m : '';
113
118
  let base = posixJoin(outDir, folder, title);
114
119
  if (xMint === null || xMint === void 0 ? void 0 : xMint.href) {
115
120
  const href = xMint.href.startsWith('/') ? xMint.href.slice(1) : xMint.href;
@@ -134,7 +139,7 @@ export function generateOpenApiPages(opts) {
134
139
  if (badge !== undefined && (xMintMetadata === null || xMintMetadata === void 0 ? void 0 : xMintMetadata.tag) === undefined) {
135
140
  xMintMetadata = Object.assign(Object.assign({}, xMintMetadata), { tag: badge });
136
141
  }
137
- const page = Object.assign(Object.assign({ title: (_q = (_p = xMintMetadata === null || xMintMetadata === void 0 ? void 0 : xMintMetadata.title) !== null && _p !== void 0 ? _p : titleTag) !== null && _q !== void 0 ? _q : slugToTitle(filenameWithoutExtension), description: (_r = xMintMetadata === null || xMintMetadata === void 0 ? void 0 : xMintMetadata.description) !== null && _r !== void 0 ? _r : description, deprecated: (_s = xMintMetadata === null || xMintMetadata === void 0 ? void 0 : xMintMetadata.deprecated) !== null && _s !== void 0 ? _s : operation.deprecated, openapi: openapiMetaTag, href: posixResolve('/', filenameWithoutExtension), method, path: apiPath, tag: groupName }, (nestedTags ? { tagPath } : {})), { hidden: operation['x-hidden'] === true, xMintMetadata, xMintContent: xMint === null || xMint === void 0 ? void 0 : xMint.content, version: opts.version });
142
+ const page = Object.assign(Object.assign({ title: (_p = (_o = xMintMetadata === null || xMintMetadata === void 0 ? void 0 : xMintMetadata.title) !== null && _o !== void 0 ? _o : titleTag) !== null && _p !== void 0 ? _p : slugToTitle(filenameWithoutExtension), description: (_q = xMintMetadata === null || xMintMetadata === void 0 ? void 0 : xMintMetadata.description) !== null && _q !== void 0 ? _q : description, deprecated: (_r = xMintMetadata === null || xMintMetadata === void 0 ? void 0 : xMintMetadata.deprecated) !== null && _r !== void 0 ? _r : operation.deprecated, openapi: openapiMetaTag, href: posixResolve('/', filenameWithoutExtension), method, path: apiPath, tag: groupName }, (nestedTags ? { tagPath } : {})), { hidden: operation['x-hidden'] === true, xMintMetadata, xMintContent: xMint === null || xMint === void 0 ? void 0 : xMint.content, version: opts.version });
138
143
  pages.push(page);
139
144
  }
140
145
  }
@@ -148,7 +153,7 @@ export function generateOpenApiPages(opts) {
148
153
  if (!webhookObject || typeof webhookObject !== 'object')
149
154
  continue;
150
155
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
151
- const pathItem = ((_t = resolvePathItemReference(webhookObject, spec.components)) !== null && _t !== void 0 ? _t : webhookObject);
156
+ const pathItem = ((_s = resolvePathItemReference(webhookObject, spec.components)) !== null && _s !== void 0 ? _s : webhookObject);
152
157
  for (const [, pathOperation] of getPathItemOperations(pathItem)) {
153
158
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
154
159
  const operation = pathOperation;
@@ -158,8 +163,14 @@ export function generateOpenApiPages(opts) {
158
163
  const tagPath = resolveTags(operation.tags);
159
164
  const tagName = (_c = tagPath.at(-1)) === null || _c === void 0 ? void 0 : _c.name;
160
165
  const groupName = (_d = tagPath.at(-1)) === null || _d === void 0 ? void 0 : _d.label;
161
- let title = (_u = prepareStringToBeValidFilename(operation.summary)) !== null && _u !== void 0 ? _u : `${prepareStringToBeValidFilename(webhook)}`;
162
- let folder = (_v = prepareStringToBeValidFilename(tagName)) !== null && _v !== void 0 ? _v : '';
166
+ const summaryTitle = prepareStringToBeValidFilename(operation.summary);
167
+ let title = getOperationSlugBase({
168
+ slugSource,
169
+ operationId: operation.operationId,
170
+ summary: operation.summary,
171
+ fallback: () => `${prepareStringToBeValidFilename(webhook)}`,
172
+ });
173
+ let folder = (_t = prepareStringToBeValidFilename(tagName)) !== null && _t !== void 0 ? _t : '';
163
174
  let base = posixJoin(outDir, folder, title);
164
175
  if (xMint === null || xMint === void 0 ? void 0 : xMint.href) {
165
176
  const href = xMint.href.startsWith('/') ? xMint.href.slice(1) : xMint.href;
@@ -178,7 +189,7 @@ export function generateOpenApiPages(opts) {
178
189
  const badge = resolveBadge(operation.tags);
179
190
  const xMintMetadata = badge !== undefined && ((_e = xMint === null || xMint === void 0 ? void 0 : xMint.metadata) === null || _e === void 0 ? void 0 : _e.tag) === undefined
180
191
  ? Object.assign(Object.assign({}, xMint === null || xMint === void 0 ? void 0 : xMint.metadata), { tag: badge }) : xMint === null || xMint === void 0 ? void 0 : xMint.metadata;
181
- const page = Object.assign(Object.assign({ title: (_w = (_f = xMint === null || xMint === void 0 ? void 0 : xMint.metadata) === null || _f === void 0 ? void 0 : _f.title) !== null && _w !== void 0 ? _w : slugToTitle(filenameWithoutExtension), description: (_x = (_g = xMint === null || xMint === void 0 ? void 0 : xMint.metadata) === null || _g === void 0 ? void 0 : _g.description) !== null && _x !== void 0 ? _x : operation.description, deprecated: (_y = (_h = xMint === null || xMint === void 0 ? void 0 : xMint.metadata) === null || _h === void 0 ? void 0 : _h.deprecated) !== null && _y !== void 0 ? _y : operation.deprecated, openapi: openapiMetaTag, href: posixResolve('/', filenameWithoutExtension), method: 'webhook', path: webhook, tag: groupName }, (nestedTags ? { tagPath } : {})), { hidden: operation['x-hidden'] === true, isWebhook: true, xMintMetadata, xMintContent: xMint === null || xMint === void 0 ? void 0 : xMint.content, version: opts.version });
192
+ const page = Object.assign(Object.assign({ title: (_u = (_f = xMint === null || xMint === void 0 ? void 0 : xMint.metadata) === null || _f === void 0 ? void 0 : _f.title) !== null && _u !== void 0 ? _u : slugToTitle(slugSource === 'operationId' && summaryTitle ? summaryTitle : filenameWithoutExtension), description: (_v = (_g = xMint === null || xMint === void 0 ? void 0 : xMint.metadata) === null || _g === void 0 ? void 0 : _g.description) !== null && _v !== void 0 ? _v : operation.description, deprecated: (_w = (_h = xMint === null || xMint === void 0 ? void 0 : xMint.metadata) === null || _h === void 0 ? void 0 : _h.deprecated) !== null && _w !== void 0 ? _w : operation.deprecated, openapi: openapiMetaTag, href: posixResolve('/', filenameWithoutExtension), method: 'webhook', path: webhook, tag: groupName }, (nestedTags ? { tagPath } : {})), { hidden: operation['x-hidden'] === true, isWebhook: true, xMintMetadata, xMintContent: xMint === null || xMint === void 0 ? void 0 : xMint.content, version: opts.version });
182
193
  pages.push(page);
183
194
  }
184
195
  }
@@ -14,7 +14,7 @@ export { getMatchingOpenApiFile, type ApiReferenceMapping, type FileToUuidMap, t
14
14
  export { parseApiString } from './parseApiString.js';
15
15
  export { findOpenApiPath } from './findOpenApiPath.js';
16
16
  export { openApiMetaTagToEndpointRef } from './endpointRef.js';
17
- export { prepareStringToBeValidFilename, generateUniqueFilenameWithoutExtension, } from './filenameUtils.js';
17
+ export { prepareStringToBeValidFilename, generateUniqueFilenameWithoutExtension, getOperationSlugBase, operationIdToSlug, type OpenApiSlugSource, } from './filenameUtils.js';
18
18
  export { findNavGroup, DEFAULT_API_GROUP_NAME, DEFAULT_WEBSOCKETS_GROUP_NAME, } from './findNavGroup.js';
19
19
  export { generateOpenApiPages, buildGeneratedMdxContent, type GeneratedApiPage, type GenerateOpenApiPagesOptions, } from './generateOpenApiPages.js';
20
20
  export { getTagDisplayName } from './getTagDisplayName.js';
@@ -14,7 +14,7 @@ export { getMatchingOpenApiFile, } from './getMatchingOpenApiFile.js';
14
14
  export { parseApiString } from './parseApiString.js';
15
15
  export { findOpenApiPath } from './findOpenApiPath.js';
16
16
  export { openApiMetaTagToEndpointRef } from './endpointRef.js';
17
- export { prepareStringToBeValidFilename, generateUniqueFilenameWithoutExtension, } from './filenameUtils.js';
17
+ export { prepareStringToBeValidFilename, generateUniqueFilenameWithoutExtension, getOperationSlugBase, operationIdToSlug, } from './filenameUtils.js';
18
18
  export { findNavGroup, DEFAULT_API_GROUP_NAME, DEFAULT_WEBSOCKETS_GROUP_NAME, } from './findNavGroup.js';
19
19
  export { generateOpenApiPages, buildGeneratedMdxContent, } from './generateOpenApiPages.js';
20
20
  export { getTagDisplayName } from './getTagDisplayName.js';