swagger-typescript-api 13.7.2 → 13.8.0

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.
@@ -208,7 +208,7 @@ var ComponentTypeNameResolver = class extends NameResolver {
208
208
  //#endregion
209
209
  //#region package.json
210
210
  var name = "swagger-typescript-api";
211
- var version = "13.7.2";
211
+ var version = "13.8.0";
212
212
  var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
213
213
  //#endregion
214
214
  //#region src/constants.ts
@@ -2616,6 +2616,129 @@ var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
2616
2616
  stripHash(urlOrPath) {
2617
2617
  return urlOrPath.split("#")[0] || urlOrPath;
2618
2618
  }
2619
+ /**
2620
+ * GitLab REST "get raw file from repository" URLs encode the whole repo-relative
2621
+ * file path as a single path segment, so resolving `./other.yaml` must rebuild
2622
+ * that segment instead of relying on URL resolution rules.
2623
+ *
2624
+ * We only apply this when the base URL matches GitLab's documented API shape
2625
+ * (`/api/v…/projects/…/repository/files/…/raw`), not for arbitrary hosts that
2626
+ * happen to contain similar path fragments.
2627
+ *
2628
+ * @see https://docs.gitlab.com/ee/api/repository_files.html#get-raw-file-from-repository
2629
+ */
2630
+ createGitlabRepositoryFileUrl(relativePath, baseUrl) {
2631
+ if (!relativePath || this.isHttpUrl(relativePath) || relativePath.startsWith("/")) return null;
2632
+ try {
2633
+ const parsedBaseUrl = new URL(baseUrl);
2634
+ const [, beforeApi, apiRepoFilesPrefix, encodedFilePath, suffix] = parsedBaseUrl.pathname.match(/^(.*?)(\/api\/v\d+\/projects\/[^/]+\/repository\/files\/)(.+)(\/raw)$/) || [];
2635
+ if (!apiRepoFilesPrefix || !encodedFilePath || !suffix) return null;
2636
+ const prefix = `${beforeApi ?? ""}${apiRepoFilesPrefix}`;
2637
+ const currentFilePath = decodeURIComponent(encodedFilePath);
2638
+ const nextFilePath = node_path.default.posix.normalize(node_path.default.posix.join(node_path.default.posix.dirname(currentFilePath), relativePath));
2639
+ parsedBaseUrl.pathname = `${prefix}${encodeURIComponent(nextFilePath)}${suffix}`;
2640
+ parsedBaseUrl.hash = "";
2641
+ return parsedBaseUrl.toString();
2642
+ } catch (e) {
2643
+ consola.default.debug(e);
2644
+ return null;
2645
+ }
2646
+ }
2647
+ splitGithubRefAndFilePath(rest) {
2648
+ const segments = rest.split("/").filter(Boolean);
2649
+ if (segments.length < 2) return null;
2650
+ if (segments[0] === "refs" && segments[1] === "heads" && segments.length >= 4) return {
2651
+ ref: `${segments[0]}/${segments[1]}/${segments[2]}`,
2652
+ pathSegments: segments.slice(3)
2653
+ };
2654
+ if (segments[0] === "refs" && segments[1] === "tags" && segments.length >= 4) return {
2655
+ ref: `${segments[0]}/${segments[1]}/${segments[2]}`,
2656
+ pathSegments: segments.slice(3)
2657
+ };
2658
+ const first = segments[0];
2659
+ if (!first) return null;
2660
+ if (first && first.length === 40 && /^[0-9a-f]+$/i.test(first)) return {
2661
+ ref: first,
2662
+ pathSegments: segments.slice(1)
2663
+ };
2664
+ return {
2665
+ ref: first,
2666
+ pathSegments: segments.slice(1)
2667
+ };
2668
+ }
2669
+ buildRawGithubusercontentUrl({ owner, repo, ref, repoRelativeFilePath }) {
2670
+ const refSegments = ref.split("/").filter(Boolean);
2671
+ const fileSegments = repoRelativeFilePath.split("/").filter(Boolean);
2672
+ return `https://raw.githubusercontent.com${[
2673
+ "",
2674
+ owner,
2675
+ repo,
2676
+ ...refSegments,
2677
+ ...fileSegments
2678
+ ].join("/")}`;
2679
+ }
2680
+ resolveGithubRepositoryRelativeFilePath(relativePath, tail) {
2681
+ const split = this.splitGithubRefAndFilePath(tail);
2682
+ if (!split || split.pathSegments.length === 0) return null;
2683
+ const currentFilePath = split.pathSegments.join("/");
2684
+ const nextFilePath = node_path.default.posix.normalize(node_path.default.posix.join(node_path.default.posix.dirname(currentFilePath), relativePath));
2685
+ if (nextFilePath.startsWith("..")) return null;
2686
+ return {
2687
+ ref: split.ref,
2688
+ repoRelativeFilePath: nextFilePath
2689
+ };
2690
+ }
2691
+ createGithubRepositoryFileUrl(relativePath, baseUrl) {
2692
+ if (!relativePath || this.isHttpUrl(relativePath) || relativePath.startsWith("/")) return null;
2693
+ try {
2694
+ const parsed = new URL(baseUrl);
2695
+ const host = parsed.hostname.toLowerCase();
2696
+ if (host === "raw.githubusercontent.com") {
2697
+ const [, owner, repo, tail] = parsed.pathname.match(/^\/([^/]+)\/([^/]+)\/(.+)$/) || [];
2698
+ if (!owner || !repo || !tail) return null;
2699
+ const resolved = this.resolveGithubRepositoryRelativeFilePath(relativePath, tail);
2700
+ if (!resolved) return null;
2701
+ const out = new URL(this.buildRawGithubusercontentUrl({
2702
+ owner,
2703
+ repo,
2704
+ ref: resolved.ref,
2705
+ repoRelativeFilePath: resolved.repoRelativeFilePath
2706
+ }));
2707
+ out.search = parsed.search;
2708
+ out.hash = "";
2709
+ return out.toString();
2710
+ }
2711
+ if (host === "github.com" || host === "www.github.com") {
2712
+ const blob = parsed.pathname.match(/^\/([^/]+)\/([^/]+)\/blob\/(.+)$/);
2713
+ const raw = parsed.pathname.match(/^\/([^/]+)\/([^/]+)\/raw\/(.+)$/);
2714
+ const [, owner, repo, tail] = blob || raw || [];
2715
+ if (!owner || !repo || !tail) return null;
2716
+ const resolved = this.resolveGithubRepositoryRelativeFilePath(relativePath, tail);
2717
+ if (!resolved) return null;
2718
+ return this.buildRawGithubusercontentUrl({
2719
+ owner,
2720
+ repo,
2721
+ ref: resolved.ref,
2722
+ repoRelativeFilePath: resolved.repoRelativeFilePath
2723
+ });
2724
+ }
2725
+ return null;
2726
+ } catch (e) {
2727
+ consola.default.debug(e);
2728
+ return null;
2729
+ }
2730
+ }
2731
+ resolveAbsoluteUrl(pathOrUrl, baseUrl) {
2732
+ try {
2733
+ if (this.isHttpUrl(pathOrUrl)) return this.stripHash(pathOrUrl);
2734
+ const gitlabUrl = this.createGitlabRepositoryFileUrl(pathOrUrl, baseUrl);
2735
+ const githubUrl = this.createGithubRepositoryFileUrl(pathOrUrl, baseUrl);
2736
+ return this.stripHash(gitlabUrl ?? githubUrl ?? new URL(pathOrUrl, baseUrl).toString());
2737
+ } catch (e) {
2738
+ consola.default.debug("failed to resolve absolute url", e);
2739
+ return pathOrUrl;
2740
+ }
2741
+ }
2619
2742
  extractRefsFromSchema(schema) {
2620
2743
  const refs = /* @__PURE__ */ new Set();
2621
2744
  const walk = (node) => {
@@ -2664,12 +2787,7 @@ var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
2664
2787
  if (normalizedRef.startsWith("#")) continue;
2665
2788
  const [externalPath = ""] = normalizedRef.split("#");
2666
2789
  if (!externalPath) continue;
2667
- let absoluteUrl = "";
2668
- try {
2669
- absoluteUrl = this.isHttpUrl(externalPath) ? this.stripHash(externalPath) : this.stripHash(new URL(externalPath, currentUrl).toString());
2670
- } catch (e) {
2671
- consola.default.debug(e);
2672
- }
2790
+ const absoluteUrl = this.resolveAbsoluteUrl(externalPath, currentUrl);
2673
2791
  if (absoluteUrl && !visited.has(absoluteUrl)) queue.push(absoluteUrl);
2674
2792
  }
2675
2793
  }
@@ -2689,11 +2807,9 @@ var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
2689
2807
  consola.default.debug(e);
2690
2808
  }
2691
2809
  const results = /* @__PURE__ */ new Set();
2692
- for (const base of bases) try {
2693
- const absolutePath = new URL(relativePath, base).toString();
2694
- results.add(pointer ? `${absolutePath}#${pointer}` : absolutePath);
2695
- } catch (e) {
2696
- consola.default.debug(e);
2810
+ for (const base of bases) {
2811
+ const absolutePath = this.resolveAbsoluteUrl(relativePath, base);
2812
+ if (absolutePath) results.add(pointer ? `${absolutePath}#${pointer}` : absolutePath);
2697
2813
  }
2698
2814
  return [...results];
2699
2815
  }
@@ -3903,4 +4019,4 @@ Object.defineProperty(exports, "version", {
3903
4019
  }
3904
4020
  });
3905
4021
 
3906
- //# sourceMappingURL=src-UwNroIF-.cjs.map
4022
+ //# sourceMappingURL=src-NUsiu5_Q.cjs.map