@mintlify/common 1.0.803 → 1.0.804
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,64 @@
|
|
|
1
|
+
import { parseApiTargetFromMetadata } from '../api-reference/parseApiTargetFromMetadata.js';
|
|
2
|
+
import { removeLeadingSlash } from '../fs/removeLeadingSlash.js';
|
|
3
|
+
import { isAbsoluteUrl } from '../isAbsoluteUrl.js';
|
|
4
|
+
export const getMatchingOpenApiFile = ({ metadata, refs, files, }) => {
|
|
5
|
+
const target = parseApiTargetFromMetadata(metadata);
|
|
6
|
+
if (!target || target.type === 'asyncapi') {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
let targetPath = '';
|
|
10
|
+
if (target.type === 'operation') {
|
|
11
|
+
targetPath = `${target.endpoint}/${target.method}`;
|
|
12
|
+
// Want to make it explicit when we're doing what here, even
|
|
13
|
+
// if the conditional check is unnecessary.
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
15
|
+
}
|
|
16
|
+
else if (target.type === 'schema') {
|
|
17
|
+
targetPath = `#/components/schemas/${target.name}`;
|
|
18
|
+
}
|
|
19
|
+
const matchingUuids = findAllMatchingFileUuids({ refs, targetPath });
|
|
20
|
+
let filename = undefined;
|
|
21
|
+
let match = undefined;
|
|
22
|
+
if (target.filename) {
|
|
23
|
+
const trimmedFilename = isAbsoluteUrl(target.filename)
|
|
24
|
+
? target.filename
|
|
25
|
+
: removeLeadingSlash(target.filename);
|
|
26
|
+
filename = trimmedFilename;
|
|
27
|
+
}
|
|
28
|
+
// match by original file location > filename > first match
|
|
29
|
+
if (filename) {
|
|
30
|
+
// try original file location match
|
|
31
|
+
if (files[filename]) {
|
|
32
|
+
const matchingUuid = files[filename];
|
|
33
|
+
if (matchingUuid && matchingUuids.includes(matchingUuid)) {
|
|
34
|
+
match = matchingUuid;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// try filename match
|
|
39
|
+
for (const uuid of matchingUuids) {
|
|
40
|
+
if (refs[uuid] && refs[uuid].filename === filename) {
|
|
41
|
+
match = uuid;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// filename is just wrong, return first match
|
|
46
|
+
if (!match) {
|
|
47
|
+
match = matchingUuids[0];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
match = matchingUuids[0];
|
|
53
|
+
}
|
|
54
|
+
return match;
|
|
55
|
+
};
|
|
56
|
+
const findAllMatchingFileUuids = ({ refs, targetPath, }) => {
|
|
57
|
+
const matchingUuids = [];
|
|
58
|
+
for (const [uuid, value] of Object.entries(refs)) {
|
|
59
|
+
if (value.refs[targetPath]) {
|
|
60
|
+
matchingUuids.push(uuid);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return matchingUuids;
|
|
64
|
+
};
|
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';
|