@hey-api/json-schema-ref-parser 1.3.0 → 1.3.1

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.
package/dist/index.mjs CHANGED
@@ -751,10 +751,22 @@ const inventory$Ref = ({ $refKey, $refParent, $refs, indirections, inventory, in
751
751
  pointer = $refs._resolve($refPath, pathFromRoot, options);
752
752
  } catch (error) {
753
753
  if (error instanceof MissingPointerError) {
754
- console.warn(`Skipping unresolvable $ref: ${$refPath}`);
755
- return;
756
- }
757
- throw error;
754
+ const hash$1 = getHash($refPath);
755
+ if (hash$1) {
756
+ const baseFile = stripHash($refPath);
757
+ for (const filePath of Object.keys($refs._$refs)) {
758
+ if (filePath === baseFile) continue;
759
+ try {
760
+ pointer = $refs._resolve(filePath + hash$1, pathFromRoot, options);
761
+ if (pointer) break;
762
+ } catch {}
763
+ }
764
+ }
765
+ if (!pointer) {
766
+ console.warn(`Skipping unresolvable $ref: ${$refPath}`);
767
+ return;
768
+ }
769
+ } else throw error;
758
770
  }
759
771
  if (pointer) resolvedRefs.set($refPath, pointer);
760
772
  }
@@ -787,19 +799,23 @@ const inventory$Ref = ({ $refKey, $refParent, $refs, indirections, inventory, in
787
799
  };
788
800
  inventory.push(newEntry);
789
801
  inventoryLookup.add(newEntry);
790
- if (!existingEntry || external) crawl$1({
791
- $refs,
792
- indirections: indirections + 1,
793
- inventory,
794
- inventoryLookup,
795
- key: null,
796
- options,
797
- parent: pointer.value,
798
- path: pointer.path,
799
- pathFromRoot,
800
- resolvedRefs,
801
- visitedObjects
802
- });
802
+ if (!existingEntry || external) {
803
+ let crawlPath = pointer.path;
804
+ if (file !== stripHash($refPath)) crawlPath = file + getHash(pointer.path);
805
+ crawl$1({
806
+ $refs,
807
+ indirections: indirections + 1,
808
+ inventory,
809
+ inventoryLookup,
810
+ key: null,
811
+ options,
812
+ parent: pointer.value,
813
+ path: crawlPath,
814
+ pathFromRoot,
815
+ resolvedRefs,
816
+ visitedObjects
817
+ });
818
+ }
803
819
  };
804
820
  /**
805
821
  * Recursively crawls the given value, and inventories all JSON references.
@@ -1009,7 +1025,11 @@ function remap(parser, inventory) {
1009
1025
  if (mapped && typeof mapped === "string") proposedBase = mapped;
1010
1026
  }
1011
1027
  } catch {}
1012
- defName = uniqueName(container, `${proposedBase}_${lastToken(entry.hash)}`);
1028
+ const schemaName = lastToken(entry.hash);
1029
+ let proposed = schemaName;
1030
+ if (!usedNamesByObj.has(container)) usedNamesByObj.set(container, new Set(Object.keys(container || {})));
1031
+ if (usedNamesByObj.get(container).has(proposed)) proposed = `${proposedBase}_${schemaName}`;
1032
+ defName = uniqueName(container, proposed);
1013
1033
  namesForPrefix.set(targetKey, defName);
1014
1034
  container[defName] = entry.value;
1015
1035
  }
@@ -1864,12 +1884,25 @@ var $RefParser = class {
1864
1884
  merged.components[sec][newName] = cloneAndRewrite(val, refMap, tagMap, prefix, stripHash(sourcePath));
1865
1885
  }
1866
1886
  }
1887
+ const HTTP_METHODS = new Set([
1888
+ "delete",
1889
+ "get",
1890
+ "head",
1891
+ "options",
1892
+ "patch",
1893
+ "post",
1894
+ "put",
1895
+ "trace"
1896
+ ]);
1867
1897
  const srcPaths = schema.paths || {};
1868
- for (const [p, item] of Object.entries(srcPaths)) {
1869
- let targetPath = p;
1870
- if (merged.paths[p]) targetPath = `/${prefix}/${p.startsWith("/") ? p.substring(1) : p}`;
1871
- merged.paths[targetPath] = cloneAndRewrite(item, refMap, tagMap, prefix, stripHash(sourcePath));
1872
- }
1898
+ for (const [p, item] of Object.entries(srcPaths)) if (merged.paths[p]) {
1899
+ const hasMethodConflict = Object.keys(item).filter((k) => HTTP_METHODS.has(k)).some((m) => merged.paths[p][m] !== void 0);
1900
+ const rewritten = cloneAndRewrite(item, refMap, tagMap, prefix, stripHash(sourcePath));
1901
+ if (hasMethodConflict) {
1902
+ const trimmed = p.startsWith("/") ? p.substring(1) : p;
1903
+ merged.paths[`/${prefix}/${trimmed}`] = rewritten;
1904
+ } else Object.assign(merged.paths[p], rewritten);
1905
+ } else merged.paths[p] = cloneAndRewrite(item, refMap, tagMap, prefix, stripHash(sourcePath));
1873
1906
  }
1874
1907
  if (tags.length > 0) merged.tags = tags;
1875
1908
  const rootPath = this.schemaManySources[0] || cwd();