swagger-typescript-api 13.11.0 → 13.11.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/cli.cjs +2 -2
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/cli.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +9 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +9 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{src-CxQXlsuV.mjs → src-CdwLmxYh.mjs} +31 -4
- package/dist/src-CdwLmxYh.mjs.map +1 -0
- package/dist/{src-C6CxNImi.cjs → src-dL4yFLYT.cjs} +31 -4
- package/dist/src-dL4yFLYT.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/src-C6CxNImi.cjs.map +0 -1
- package/dist/src-CxQXlsuV.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.11.
|
|
211
|
+
var version = "13.11.1";
|
|
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
|
|
@@ -779,9 +779,32 @@ var SchemaComponentsMap = class {
|
|
|
779
779
|
if (!rawTypeData || typeof rawTypeData !== "object") return false;
|
|
780
780
|
return Object.keys(rawTypeData).length === 1 && typeof rawTypeData.$ref === "string";
|
|
781
781
|
}
|
|
782
|
+
extractComponentSchemaNameFromRef(ref) {
|
|
783
|
+
const [, rawPointer = ""] = ref.split("#");
|
|
784
|
+
if (!rawPointer) return null;
|
|
785
|
+
const pointerParts = (rawPointer.startsWith("/") ? rawPointer.slice(1) : rawPointer).split("/").filter(Boolean);
|
|
786
|
+
if (pointerParts.length < 2) return null;
|
|
787
|
+
const collection = pointerParts.at(-2);
|
|
788
|
+
if (collection !== "schemas" && collection !== "definitions") return null;
|
|
789
|
+
return this.normalizeTypeNameFromFile(pointerParts.at(-1) || "");
|
|
790
|
+
}
|
|
791
|
+
findExistingComponentBySchemaFragment(ref, typeName) {
|
|
792
|
+
const fragmentSchemaName = this.extractComponentSchemaNameFromRef(ref);
|
|
793
|
+
if (!fragmentSchemaName || fragmentSchemaName !== typeName) return null;
|
|
794
|
+
const localRef = this.createRef([
|
|
795
|
+
"components",
|
|
796
|
+
"schemas",
|
|
797
|
+
typeName
|
|
798
|
+
]);
|
|
799
|
+
const byLocalRef = this._data.find((component) => component.$ref === localRef);
|
|
800
|
+
if (byLocalRef) return byLocalRef;
|
|
801
|
+
const matching = this._data.filter((component) => component.typeName === typeName);
|
|
802
|
+
return matching.length === 1 ? matching[0] : null;
|
|
803
|
+
}
|
|
782
804
|
preferExistingSchemaNameForExternalRef(typeName, refDetails) {
|
|
783
805
|
if (!this.config.preferExistingSchemaNamesForExternalRefs) return false;
|
|
784
|
-
|
|
806
|
+
if (pascalCase(refDetails.externalOpenapiFileName || "External") === typeName) return true;
|
|
807
|
+
return this.findExistingComponentBySchemaFragment(refDetails.ref, typeName) != null;
|
|
785
808
|
}
|
|
786
809
|
createComponentDraft($ref, rawTypeData) {
|
|
787
810
|
if (yummies_type_guard.typeGuard.isObject(rawTypeData) && rawTypeData.typeName && rawTypeData.rawTypeData && rawTypeData.$ref) return rawTypeData;
|
|
@@ -845,9 +868,13 @@ var SchemaComponentsMap = class {
|
|
|
845
868
|
}
|
|
846
869
|
const componentDraft = this.createComponentDraft(resolvedRef, resolvedTypeData);
|
|
847
870
|
componentDraft.typeName = this.config.hooks.onFormatExternalTypeName?.(componentDraft.typeName, refDetails) || componentDraft.typeName;
|
|
871
|
+
if (this.config.preferExistingSchemaNamesForExternalRefs) {
|
|
872
|
+
const existingByFragment = this.findExistingComponentBySchemaFragment(refDetails.ref, componentDraft.typeName);
|
|
873
|
+
if (existingByFragment) return existingByFragment;
|
|
874
|
+
}
|
|
848
875
|
if (this._data.some((component) => component.typeName === componentDraft.typeName)) {
|
|
849
876
|
if (this.preferExistingSchemaNameForExternalRef(componentDraft.typeName, refDetails)) {
|
|
850
|
-
const existingComponent = this._data.find((component) => component.typeName === componentDraft.typeName);
|
|
877
|
+
const existingComponent = this.findExistingComponentBySchemaFragment(refDetails.ref, componentDraft.typeName) ?? this._data.find((component) => component.typeName === componentDraft.typeName);
|
|
851
878
|
if (existingComponent) return existingComponent;
|
|
852
879
|
}
|
|
853
880
|
componentDraft.typeName = this.config.hooks.onFixDuplicateExternalTypeName?.(componentDraft.typeName, refDetails, this._data.map((it) => it.typeName)) ?? `${pascalCase(refDetails.externalOpenapiFileName || "External")}${componentDraft.typeName}`;
|
|
@@ -4135,4 +4162,4 @@ Object.defineProperty(exports, "version", {
|
|
|
4135
4162
|
}
|
|
4136
4163
|
});
|
|
4137
4164
|
|
|
4138
|
-
//# sourceMappingURL=src-
|
|
4165
|
+
//# sourceMappingURL=src-dL4yFLYT.cjs.map
|