@mintlify/common 1.0.804 → 1.0.806

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,7 +1,8 @@
1
1
  import { parseApiTargetFromMetadata } from '../api-reference/parseApiTargetFromMetadata.js';
2
- import { removeLeadingSlash } from '../fs/removeLeadingSlash.js';
2
+ import { normalizeRelativePath } from '../fs/normalizeRelativePath.js';
3
3
  import { isAbsoluteUrl } from '../isAbsoluteUrl.js';
4
4
  export const getMatchingOpenApiFile = ({ metadata, refs, files, }) => {
5
+ var _a, _b;
5
6
  const target = parseApiTargetFromMetadata(metadata);
6
7
  if (!target || target.type === 'asyncapi') {
7
8
  return undefined;
@@ -17,41 +18,36 @@ export const getMatchingOpenApiFile = ({ metadata, refs, files, }) => {
17
18
  targetPath = `#/components/schemas/${target.name}`;
18
19
  }
19
20
  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;
21
+ if (!target.filename) {
22
+ return matchingUuids[0];
27
23
  }
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
- }
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;
36
42
  }
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
- }
43
+ if (!exactFilenameMatch && ref.filename === filename) {
44
+ exactFilenameMatch = uuid;
45
+ }
46
+ if (!substringFilenameMatch && ref.filename.includes(filename)) {
47
+ substringFilenameMatch = uuid;
49
48
  }
50
49
  }
51
- else {
52
- match = matchingUuids[0];
53
- }
54
- return match;
50
+ return (_b = (_a = substringOriginalMatch !== null && substringOriginalMatch !== void 0 ? substringOriginalMatch : exactFilenameMatch) !== null && _a !== void 0 ? _a : substringFilenameMatch) !== null && _b !== void 0 ? _b : matchingUuids[0];
55
51
  };
56
52
  const findAllMatchingFileUuids = ({ refs, targetPath, }) => {
57
53
  const matchingUuids = [];