@mintlify/common 1.0.803 → 1.0.805
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,21 @@
|
|
|
1
|
+
import { PageMetaTags } from '@mintlify/models';
|
|
2
|
+
import { RefUuidMap, UUID } from '@mintlify/validation';
|
|
3
|
+
export type FileToUuidMap = {
|
|
4
|
+
[originalFileLocation: string]: UUID;
|
|
5
|
+
};
|
|
6
|
+
export type UuidToRefsMap = {
|
|
7
|
+
[localUuid: UUID]: {
|
|
8
|
+
originalFileLocation: string;
|
|
9
|
+
filename: string;
|
|
10
|
+
refs: RefUuidMap;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type ApiReferenceMapping = {
|
|
14
|
+
files: FileToUuidMap;
|
|
15
|
+
refs: UuidToRefsMap;
|
|
16
|
+
};
|
|
17
|
+
export declare const getMatchingOpenApiFile: ({ metadata, refs, files, }: {
|
|
18
|
+
metadata: PageMetaTags;
|
|
19
|
+
refs: UuidToRefsMap;
|
|
20
|
+
files: FileToUuidMap;
|
|
21
|
+
}) => UUID | undefined;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { parseApiTargetFromMetadata } from '../api-reference/parseApiTargetFromMetadata.js';
|
|
2
|
+
import { normalizeRelativePath } from '../fs/normalizeRelativePath.js';
|
|
3
|
+
import { isAbsoluteUrl } from '../isAbsoluteUrl.js';
|
|
4
|
+
export const getMatchingOpenApiFile = ({ metadata, refs, files, }) => {
|
|
5
|
+
var _a, _b;
|
|
6
|
+
const target = parseApiTargetFromMetadata(metadata);
|
|
7
|
+
if (!target || target.type === 'asyncapi') {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
let targetPath = '';
|
|
11
|
+
if (target.type === 'operation') {
|
|
12
|
+
targetPath = `${target.endpoint}/${target.method}`;
|
|
13
|
+
// Want to make it explicit when we're doing what here, even
|
|
14
|
+
// if the conditional check is unnecessary.
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
16
|
+
}
|
|
17
|
+
else if (target.type === 'schema') {
|
|
18
|
+
targetPath = `#/components/schemas/${target.name}`;
|
|
19
|
+
}
|
|
20
|
+
const matchingUuids = findAllMatchingFileUuids({ refs, targetPath });
|
|
21
|
+
if (!target.filename) {
|
|
22
|
+
return matchingUuids[0];
|
|
23
|
+
}
|
|
24
|
+
const filename = isAbsoluteUrl(target.filename)
|
|
25
|
+
? target.filename
|
|
26
|
+
: normalizeRelativePath(target.filename);
|
|
27
|
+
// exact original file location match
|
|
28
|
+
const exactFileUuid = files[filename];
|
|
29
|
+
if (exactFileUuid && matchingUuids.includes(exactFileUuid)) {
|
|
30
|
+
return exactFileUuid;
|
|
31
|
+
}
|
|
32
|
+
// substring original location > exact filename match > substring filename
|
|
33
|
+
let substringOriginalMatch;
|
|
34
|
+
let exactFilenameMatch;
|
|
35
|
+
let substringFilenameMatch;
|
|
36
|
+
for (const uuid of matchingUuids) {
|
|
37
|
+
const ref = refs[uuid];
|
|
38
|
+
if (!ref)
|
|
39
|
+
continue;
|
|
40
|
+
if (!substringOriginalMatch && ref.originalFileLocation.includes(filename)) {
|
|
41
|
+
substringOriginalMatch = uuid;
|
|
42
|
+
}
|
|
43
|
+
if (!exactFilenameMatch && ref.filename === filename) {
|
|
44
|
+
exactFilenameMatch = uuid;
|
|
45
|
+
}
|
|
46
|
+
if (!substringFilenameMatch && ref.filename.includes(filename)) {
|
|
47
|
+
substringFilenameMatch = uuid;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return (_b = (_a = substringOriginalMatch !== null && substringOriginalMatch !== void 0 ? substringOriginalMatch : exactFilenameMatch) !== null && _a !== void 0 ? _a : substringFilenameMatch) !== null && _b !== void 0 ? _b : matchingUuids[0];
|
|
51
|
+
};
|
|
52
|
+
const findAllMatchingFileUuids = ({ refs, targetPath, }) => {
|
|
53
|
+
const matchingUuids = [];
|
|
54
|
+
for (const [uuid, value] of Object.entries(refs)) {
|
|
55
|
+
if (value.refs[targetPath]) {
|
|
56
|
+
matchingUuids.push(uuid);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return matchingUuids;
|
|
60
|
+
};
|
package/dist/openapi/index.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export { getOpenApiDocumentFromUrl } from './getOpenApiDocumentFromUrl.js';
|
|
|
7
7
|
export { prepOpenApiFrontmatter } from './prepOpenApiFrontmatter.js';
|
|
8
8
|
export { buildOpenApiMetaTag } from './buildOpenApiMetaTag.js';
|
|
9
9
|
export { registerXMintContent, getXMintContent, getAllXMintContent } from './contentRegistry.js';
|
|
10
|
+
export { getMatchingOpenApiFile, type ApiReferenceMapping, type FileToUuidMap, type UuidToRefsMap, } from './getMatchingOpenApiFile.js';
|
package/dist/openapi/index.js
CHANGED
|
@@ -7,3 +7,4 @@ export { getOpenApiDocumentFromUrl } from './getOpenApiDocumentFromUrl.js';
|
|
|
7
7
|
export { prepOpenApiFrontmatter } from './prepOpenApiFrontmatter.js';
|
|
8
8
|
export { buildOpenApiMetaTag } from './buildOpenApiMetaTag.js';
|
|
9
9
|
export { registerXMintContent, getXMintContent, getAllXMintContent } from './contentRegistry.js';
|
|
10
|
+
export { getMatchingOpenApiFile, } from './getMatchingOpenApiFile.js';
|