@mintlify/common 1.0.857 → 1.0.859

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,17 @@
1
+ /**
2
+ * Look up an OpenAPI path from a `paths` or `webhooks` object, tolerating
3
+ * trailing-slash mismatches. Returns the spec's original key and path item.
4
+ *
5
+ * Exact matches always win: if the spec declares both `/users` and `/users/`,
6
+ * a reference to either resolves to the correctly keyed operation. Only when
7
+ * there is no exact match do we fall back to a canonicalized (trailing-slash
8
+ * insensitive) lookup.
9
+ *
10
+ * Typed loosely on purpose — the OpenAPI type definitions vary between v3 and
11
+ * v3.1 in ways that confuse generic constraints, but at this layer we only
12
+ * care about identifying the matching key/value pair.
13
+ */
14
+ export declare function findOpenApiPath<T = unknown>(paths: Record<string, any> | undefined, endpoint: string): {
15
+ pathKey: string;
16
+ pathItem: T;
17
+ } | undefined;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Canonicalize an OpenAPI path for comparison: strip a trailing slash except on
3
+ * the root `/`. Used only for lookup — the original spec key is preserved in the
4
+ * return value so downstream callers render the URL the spec declared.
5
+ */
6
+ function canonicalize(path) {
7
+ if (path.length > 1 && path.endsWith('/')) {
8
+ return path.slice(0, -1);
9
+ }
10
+ return path;
11
+ }
12
+ /**
13
+ * Look up an OpenAPI path from a `paths` or `webhooks` object, tolerating
14
+ * trailing-slash mismatches. Returns the spec's original key and path item.
15
+ *
16
+ * Exact matches always win: if the spec declares both `/users` and `/users/`,
17
+ * a reference to either resolves to the correctly keyed operation. Only when
18
+ * there is no exact match do we fall back to a canonicalized (trailing-slash
19
+ * insensitive) lookup.
20
+ *
21
+ * Typed loosely on purpose — the OpenAPI type definitions vary between v3 and
22
+ * v3.1 in ways that confuse generic constraints, but at this layer we only
23
+ * care about identifying the matching key/value pair.
24
+ */
25
+ export function findOpenApiPath(
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ paths, endpoint) {
28
+ if (!paths)
29
+ return undefined;
30
+ const exact = paths[endpoint];
31
+ if (exact && typeof exact === 'object') {
32
+ return { pathKey: endpoint, pathItem: exact };
33
+ }
34
+ const target = canonicalize(endpoint);
35
+ for (const [specKey, pathItem] of Object.entries(paths)) {
36
+ if (!pathItem || typeof pathItem !== 'object')
37
+ continue;
38
+ if (canonicalize(specKey) === target) {
39
+ return { pathKey: specKey, pathItem: pathItem };
40
+ }
41
+ }
42
+ return undefined;
43
+ }
@@ -1,6 +1,6 @@
1
+ import { findOpenApiPath } from './findOpenApiPath.js';
1
2
  import { potentiallyParseOpenApiString } from './parseOpenApiString.js';
2
3
  export const getOpenApiOperationMethodAndEndpoint = (endpointStr, openApiFiles) => {
3
- var _a;
4
4
  const potentiallyParsedOpenApiString = potentiallyParseOpenApiString(endpointStr);
5
5
  if (potentiallyParsedOpenApiString == undefined) {
6
6
  return undefined;
@@ -8,13 +8,15 @@ export const getOpenApiOperationMethodAndEndpoint = (endpointStr, openApiFiles)
8
8
  const { endpoint, method, filename } = potentiallyParsedOpenApiString;
9
9
  let path = undefined;
10
10
  let apiFile = undefined;
11
+ let matchedEndpoint = endpoint;
11
12
  for (const file of openApiFiles) {
12
13
  const openApiFile = file.spec;
13
- const openApiPath = (_a = openApiFile.paths) === null || _a === void 0 ? void 0 : _a[endpoint];
14
+ const match = findOpenApiPath(openApiFile.paths, endpoint);
14
15
  const filenameMatches = !filename || filename === file.filename || filename === file.originalFileLocation;
15
- if (openApiPath && filenameMatches) {
16
- path = openApiPath;
16
+ if (match && filenameMatches) {
17
+ path = match.pathItem;
17
18
  apiFile = openApiFile;
19
+ matchedEndpoint = match.pathKey;
18
20
  }
19
21
  }
20
22
  if (path == null || apiFile == null) {
@@ -27,7 +29,7 @@ export const getOpenApiOperationMethodAndEndpoint = (endpointStr, openApiFiles)
27
29
  const { method: finalMethod, operation } = operationResponse;
28
30
  return {
29
31
  method: finalMethod,
30
- endpoint,
32
+ endpoint: matchedEndpoint,
31
33
  operation,
32
34
  path,
33
35
  };
@@ -8,6 +8,7 @@ export { buildOpenApiMetaTag } from './buildOpenApiMetaTag.js';
8
8
  export { registerXMintContent, getXMintContent, getAllXMintContent } from './contentRegistry.js';
9
9
  export { getMatchingOpenApiFile, type ApiReferenceMapping, type FileToUuidMap, type UuidToRefsMap, } from './getMatchingOpenApiFile.js';
10
10
  export { parseApiString } from './parseApiString.js';
11
+ export { findOpenApiPath } from './findOpenApiPath.js';
11
12
  export { openApiMetaTagToEndpointRef } from './endpointRef.js';
12
13
  export { prepareStringToBeValidFilename, generateUniqueFilenameWithoutExtension, } from './filenameUtils.js';
13
14
  export { findNavGroup, DEFAULT_API_GROUP_NAME, DEFAULT_WEBSOCKETS_GROUP_NAME, } from './findNavGroup.js';
@@ -8,6 +8,7 @@ export { buildOpenApiMetaTag } from './buildOpenApiMetaTag.js';
8
8
  export { registerXMintContent, getXMintContent, getAllXMintContent } from './contentRegistry.js';
9
9
  export { getMatchingOpenApiFile, } from './getMatchingOpenApiFile.js';
10
10
  export { parseApiString } from './parseApiString.js';
11
+ export { findOpenApiPath } from './findOpenApiPath.js';
11
12
  export { openApiMetaTagToEndpointRef } from './endpointRef.js';
12
13
  export { prepareStringToBeValidFilename, generateUniqueFilenameWithoutExtension, } from './filenameUtils.js';
13
14
  export { findNavGroup, DEFAULT_API_GROUP_NAME, DEFAULT_WEBSOCKETS_GROUP_NAME, } from './findNavGroup.js';