swagger-typescript-api 13.7.2 → 13.9.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.
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +18 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +18 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{src-m02XHGVc.mjs → src-BvHLNUAw.mjs} +147 -14
- package/dist/src-BvHLNUAw.mjs.map +1 -0
- package/dist/{src-UwNroIF-.cjs → src-HisTG6gD.cjs} +147 -14
- package/dist/src-HisTG6gD.cjs.map +1 -0
- package/package.json +6 -6
- package/dist/src-UwNroIF-.cjs.map +0 -1
- package/dist/src-m02XHGVc.mjs.map +0 -1
|
@@ -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.
|
|
211
|
+
var version = "13.9.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
|
|
@@ -714,6 +714,23 @@ var SchemaComponentsMap = class {
|
|
|
714
714
|
parseRef = (ref) => {
|
|
715
715
|
return ref.split("/");
|
|
716
716
|
};
|
|
717
|
+
getByLocalFragmentRef($ref) {
|
|
718
|
+
if (!$ref.startsWith("#")) return null;
|
|
719
|
+
const [, rawFragment = ""] = $ref.split("#");
|
|
720
|
+
const fragment = rawFragment.startsWith("/") ? rawFragment.slice(1) : rawFragment;
|
|
721
|
+
if (!fragment || fragment.includes("/")) return null;
|
|
722
|
+
let fragmentName = fragment;
|
|
723
|
+
try {
|
|
724
|
+
fragmentName = decodeURIComponent(fragment);
|
|
725
|
+
} catch {}
|
|
726
|
+
const matchingComponents = this._data.filter((component) => {
|
|
727
|
+
if (!component.$ref.startsWith("#")) return false;
|
|
728
|
+
const [, rawPointer = ""] = component.$ref.split("#");
|
|
729
|
+
const componentName = (rawPointer.startsWith("/") ? rawPointer.slice(1) : rawPointer).split("/").filter(Boolean).at(-1);
|
|
730
|
+
return component.typeName === fragmentName || componentName === fragmentName;
|
|
731
|
+
});
|
|
732
|
+
return matchingComponents.length === 1 ? matchingComponents[0] : null;
|
|
733
|
+
}
|
|
717
734
|
createComponentDraft($ref, rawTypeData) {
|
|
718
735
|
if (yummies_type_guard.typeGuard.isObject(rawTypeData) && rawTypeData.typeName && rawTypeData.rawTypeData && rawTypeData.$ref) return rawTypeData;
|
|
719
736
|
const parsed = this.parseRef($ref);
|
|
@@ -746,7 +763,7 @@ var SchemaComponentsMap = class {
|
|
|
746
763
|
return this._data.filter((it) => componentNames.some((componentName) => it.$ref.startsWith(`#/components/${componentName}`)));
|
|
747
764
|
}
|
|
748
765
|
get = ($ref) => {
|
|
749
|
-
const localFound = this._data.find((c) => c.$ref === $ref) || null;
|
|
766
|
+
const localFound = this._data.find((c) => c.$ref === $ref) || this.getByLocalFragmentRef($ref) || null;
|
|
750
767
|
if (localFound != null) return localFound;
|
|
751
768
|
const { resolvedSwaggerSchema } = this.config;
|
|
752
769
|
if (resolvedSwaggerSchema.isLocalRef($ref)) return null;
|
|
@@ -2616,6 +2633,129 @@ var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
|
|
|
2616
2633
|
stripHash(urlOrPath) {
|
|
2617
2634
|
return urlOrPath.split("#")[0] || urlOrPath;
|
|
2618
2635
|
}
|
|
2636
|
+
/**
|
|
2637
|
+
* GitLab REST "get raw file from repository" URLs encode the whole repo-relative
|
|
2638
|
+
* file path as a single path segment, so resolving `./other.yaml` must rebuild
|
|
2639
|
+
* that segment instead of relying on URL resolution rules.
|
|
2640
|
+
*
|
|
2641
|
+
* We only apply this when the base URL matches GitLab's documented API shape
|
|
2642
|
+
* (`/api/v…/projects/…/repository/files/…/raw`), not for arbitrary hosts that
|
|
2643
|
+
* happen to contain similar path fragments.
|
|
2644
|
+
*
|
|
2645
|
+
* @see https://docs.gitlab.com/ee/api/repository_files.html#get-raw-file-from-repository
|
|
2646
|
+
*/
|
|
2647
|
+
createGitlabRepositoryFileUrl(relativePath, baseUrl) {
|
|
2648
|
+
if (!relativePath || this.isHttpUrl(relativePath) || relativePath.startsWith("/")) return null;
|
|
2649
|
+
try {
|
|
2650
|
+
const parsedBaseUrl = new URL(baseUrl);
|
|
2651
|
+
const [, beforeApi, apiRepoFilesPrefix, encodedFilePath, suffix] = parsedBaseUrl.pathname.match(/^(.*?)(\/api\/v\d+\/projects\/[^/]+\/repository\/files\/)(.+)(\/raw)$/) || [];
|
|
2652
|
+
if (!apiRepoFilesPrefix || !encodedFilePath || !suffix) return null;
|
|
2653
|
+
const prefix = `${beforeApi ?? ""}${apiRepoFilesPrefix}`;
|
|
2654
|
+
const currentFilePath = decodeURIComponent(encodedFilePath);
|
|
2655
|
+
const nextFilePath = node_path.default.posix.normalize(node_path.default.posix.join(node_path.default.posix.dirname(currentFilePath), relativePath));
|
|
2656
|
+
parsedBaseUrl.pathname = `${prefix}${encodeURIComponent(nextFilePath)}${suffix}`;
|
|
2657
|
+
parsedBaseUrl.hash = "";
|
|
2658
|
+
return parsedBaseUrl.toString();
|
|
2659
|
+
} catch (e) {
|
|
2660
|
+
consola.default.debug(e);
|
|
2661
|
+
return null;
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
splitGithubRefAndFilePath(rest) {
|
|
2665
|
+
const segments = rest.split("/").filter(Boolean);
|
|
2666
|
+
if (segments.length < 2) return null;
|
|
2667
|
+
if (segments[0] === "refs" && segments[1] === "heads" && segments.length >= 4) return {
|
|
2668
|
+
ref: `${segments[0]}/${segments[1]}/${segments[2]}`,
|
|
2669
|
+
pathSegments: segments.slice(3)
|
|
2670
|
+
};
|
|
2671
|
+
if (segments[0] === "refs" && segments[1] === "tags" && segments.length >= 4) return {
|
|
2672
|
+
ref: `${segments[0]}/${segments[1]}/${segments[2]}`,
|
|
2673
|
+
pathSegments: segments.slice(3)
|
|
2674
|
+
};
|
|
2675
|
+
const first = segments[0];
|
|
2676
|
+
if (!first) return null;
|
|
2677
|
+
if (first && first.length === 40 && /^[0-9a-f]+$/i.test(first)) return {
|
|
2678
|
+
ref: first,
|
|
2679
|
+
pathSegments: segments.slice(1)
|
|
2680
|
+
};
|
|
2681
|
+
return {
|
|
2682
|
+
ref: first,
|
|
2683
|
+
pathSegments: segments.slice(1)
|
|
2684
|
+
};
|
|
2685
|
+
}
|
|
2686
|
+
buildRawGithubusercontentUrl({ owner, repo, ref, repoRelativeFilePath }) {
|
|
2687
|
+
const refSegments = ref.split("/").filter(Boolean);
|
|
2688
|
+
const fileSegments = repoRelativeFilePath.split("/").filter(Boolean);
|
|
2689
|
+
return `https://raw.githubusercontent.com${[
|
|
2690
|
+
"",
|
|
2691
|
+
owner,
|
|
2692
|
+
repo,
|
|
2693
|
+
...refSegments,
|
|
2694
|
+
...fileSegments
|
|
2695
|
+
].join("/")}`;
|
|
2696
|
+
}
|
|
2697
|
+
resolveGithubRepositoryRelativeFilePath(relativePath, tail) {
|
|
2698
|
+
const split = this.splitGithubRefAndFilePath(tail);
|
|
2699
|
+
if (!split || split.pathSegments.length === 0) return null;
|
|
2700
|
+
const currentFilePath = split.pathSegments.join("/");
|
|
2701
|
+
const nextFilePath = node_path.default.posix.normalize(node_path.default.posix.join(node_path.default.posix.dirname(currentFilePath), relativePath));
|
|
2702
|
+
if (nextFilePath.startsWith("..")) return null;
|
|
2703
|
+
return {
|
|
2704
|
+
ref: split.ref,
|
|
2705
|
+
repoRelativeFilePath: nextFilePath
|
|
2706
|
+
};
|
|
2707
|
+
}
|
|
2708
|
+
createGithubRepositoryFileUrl(relativePath, baseUrl) {
|
|
2709
|
+
if (!relativePath || this.isHttpUrl(relativePath) || relativePath.startsWith("/")) return null;
|
|
2710
|
+
try {
|
|
2711
|
+
const parsed = new URL(baseUrl);
|
|
2712
|
+
const host = parsed.hostname.toLowerCase();
|
|
2713
|
+
if (host === "raw.githubusercontent.com") {
|
|
2714
|
+
const [, owner, repo, tail] = parsed.pathname.match(/^\/([^/]+)\/([^/]+)\/(.+)$/) || [];
|
|
2715
|
+
if (!owner || !repo || !tail) return null;
|
|
2716
|
+
const resolved = this.resolveGithubRepositoryRelativeFilePath(relativePath, tail);
|
|
2717
|
+
if (!resolved) return null;
|
|
2718
|
+
const out = new URL(this.buildRawGithubusercontentUrl({
|
|
2719
|
+
owner,
|
|
2720
|
+
repo,
|
|
2721
|
+
ref: resolved.ref,
|
|
2722
|
+
repoRelativeFilePath: resolved.repoRelativeFilePath
|
|
2723
|
+
}));
|
|
2724
|
+
out.search = parsed.search;
|
|
2725
|
+
out.hash = "";
|
|
2726
|
+
return out.toString();
|
|
2727
|
+
}
|
|
2728
|
+
if (host === "github.com" || host === "www.github.com") {
|
|
2729
|
+
const blob = parsed.pathname.match(/^\/([^/]+)\/([^/]+)\/blob\/(.+)$/);
|
|
2730
|
+
const raw = parsed.pathname.match(/^\/([^/]+)\/([^/]+)\/raw\/(.+)$/);
|
|
2731
|
+
const [, owner, repo, tail] = blob || raw || [];
|
|
2732
|
+
if (!owner || !repo || !tail) return null;
|
|
2733
|
+
const resolved = this.resolveGithubRepositoryRelativeFilePath(relativePath, tail);
|
|
2734
|
+
if (!resolved) return null;
|
|
2735
|
+
return this.buildRawGithubusercontentUrl({
|
|
2736
|
+
owner,
|
|
2737
|
+
repo,
|
|
2738
|
+
ref: resolved.ref,
|
|
2739
|
+
repoRelativeFilePath: resolved.repoRelativeFilePath
|
|
2740
|
+
});
|
|
2741
|
+
}
|
|
2742
|
+
return null;
|
|
2743
|
+
} catch (e) {
|
|
2744
|
+
consola.default.debug(e);
|
|
2745
|
+
return null;
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
resolveAbsoluteUrl(pathOrUrl, baseUrl) {
|
|
2749
|
+
try {
|
|
2750
|
+
if (this.isHttpUrl(pathOrUrl)) return this.stripHash(pathOrUrl);
|
|
2751
|
+
const gitlabUrl = this.createGitlabRepositoryFileUrl(pathOrUrl, baseUrl);
|
|
2752
|
+
const githubUrl = this.createGithubRepositoryFileUrl(pathOrUrl, baseUrl);
|
|
2753
|
+
return this.stripHash(gitlabUrl ?? githubUrl ?? new URL(pathOrUrl, baseUrl).toString());
|
|
2754
|
+
} catch (e) {
|
|
2755
|
+
consola.default.debug("failed to resolve absolute url", e);
|
|
2756
|
+
return pathOrUrl;
|
|
2757
|
+
}
|
|
2758
|
+
}
|
|
2619
2759
|
extractRefsFromSchema(schema) {
|
|
2620
2760
|
const refs = /* @__PURE__ */ new Set();
|
|
2621
2761
|
const walk = (node) => {
|
|
@@ -2664,12 +2804,7 @@ var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
|
|
|
2664
2804
|
if (normalizedRef.startsWith("#")) continue;
|
|
2665
2805
|
const [externalPath = ""] = normalizedRef.split("#");
|
|
2666
2806
|
if (!externalPath) continue;
|
|
2667
|
-
|
|
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
|
-
}
|
|
2807
|
+
const absoluteUrl = this.resolveAbsoluteUrl(externalPath, currentUrl);
|
|
2673
2808
|
if (absoluteUrl && !visited.has(absoluteUrl)) queue.push(absoluteUrl);
|
|
2674
2809
|
}
|
|
2675
2810
|
}
|
|
@@ -2689,11 +2824,9 @@ var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
|
|
|
2689
2824
|
consola.default.debug(e);
|
|
2690
2825
|
}
|
|
2691
2826
|
const results = /* @__PURE__ */ new Set();
|
|
2692
|
-
for (const base of bases)
|
|
2693
|
-
const absolutePath =
|
|
2694
|
-
results.add(pointer ? `${absolutePath}#${pointer}` : absolutePath);
|
|
2695
|
-
} catch (e) {
|
|
2696
|
-
consola.default.debug(e);
|
|
2827
|
+
for (const base of bases) {
|
|
2828
|
+
const absolutePath = this.resolveAbsoluteUrl(relativePath, base);
|
|
2829
|
+
if (absolutePath) results.add(pointer ? `${absolutePath}#${pointer}` : absolutePath);
|
|
2697
2830
|
}
|
|
2698
2831
|
return [...results];
|
|
2699
2832
|
}
|
|
@@ -3903,4 +4036,4 @@ Object.defineProperty(exports, "version", {
|
|
|
3903
4036
|
}
|
|
3904
4037
|
});
|
|
3905
4038
|
|
|
3906
|
-
//# sourceMappingURL=src-
|
|
4039
|
+
//# sourceMappingURL=src-HisTG6gD.cjs.map
|