swagger-typescript-api 13.11.0 → 13.11.2
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 +11 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +11 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{src-C6CxNImi.cjs → src-B2ssuwoK.cjs} +39 -4
- package/dist/src-B2ssuwoK.cjs.map +1 -0
- package/dist/{src-CxQXlsuV.mjs → src-C0d8cMi-.mjs} +39 -4
- package/dist/src-C0d8cMi-.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/src-C6CxNImi.cjs.map +0 -1
- package/dist/src-CxQXlsuV.mjs.map +0 -1
|
@@ -169,7 +169,7 @@ var ComponentTypeNameResolver = class extends NameResolver {
|
|
|
169
169
|
//#endregion
|
|
170
170
|
//#region package.json
|
|
171
171
|
var name = "swagger-typescript-api";
|
|
172
|
-
var version = "13.11.
|
|
172
|
+
var version = "13.11.2";
|
|
173
173
|
var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
|
|
174
174
|
//#endregion
|
|
175
175
|
//#region src/constants.ts
|
|
@@ -740,9 +740,32 @@ var SchemaComponentsMap = class {
|
|
|
740
740
|
if (!rawTypeData || typeof rawTypeData !== "object") return false;
|
|
741
741
|
return Object.keys(rawTypeData).length === 1 && typeof rawTypeData.$ref === "string";
|
|
742
742
|
}
|
|
743
|
+
extractComponentSchemaNameFromRef(ref) {
|
|
744
|
+
const [, rawPointer = ""] = ref.split("#");
|
|
745
|
+
if (!rawPointer) return null;
|
|
746
|
+
const pointerParts = (rawPointer.startsWith("/") ? rawPointer.slice(1) : rawPointer).split("/").filter(Boolean);
|
|
747
|
+
if (pointerParts.length < 2) return null;
|
|
748
|
+
const collection = pointerParts.at(-2);
|
|
749
|
+
if (collection !== "schemas" && collection !== "definitions") return null;
|
|
750
|
+
return this.normalizeTypeNameFromFile(pointerParts.at(-1) || "");
|
|
751
|
+
}
|
|
752
|
+
findExistingComponentBySchemaFragment(ref, typeName) {
|
|
753
|
+
const fragmentSchemaName = this.extractComponentSchemaNameFromRef(ref);
|
|
754
|
+
if (!fragmentSchemaName || fragmentSchemaName !== typeName) return null;
|
|
755
|
+
const localRef = this.createRef([
|
|
756
|
+
"components",
|
|
757
|
+
"schemas",
|
|
758
|
+
typeName
|
|
759
|
+
]);
|
|
760
|
+
const byLocalRef = this._data.find((component) => component.$ref === localRef);
|
|
761
|
+
if (byLocalRef) return byLocalRef;
|
|
762
|
+
const matching = this._data.filter((component) => component.typeName === typeName);
|
|
763
|
+
return matching.length === 1 ? matching[0] : null;
|
|
764
|
+
}
|
|
743
765
|
preferExistingSchemaNameForExternalRef(typeName, refDetails) {
|
|
744
766
|
if (!this.config.preferExistingSchemaNamesForExternalRefs) return false;
|
|
745
|
-
|
|
767
|
+
if (pascalCase(refDetails.externalOpenapiFileName || "External") === typeName) return true;
|
|
768
|
+
return this.findExistingComponentBySchemaFragment(refDetails.ref, typeName) != null;
|
|
746
769
|
}
|
|
747
770
|
createComponentDraft($ref, rawTypeData) {
|
|
748
771
|
if (typeGuard.isObject(rawTypeData) && rawTypeData.typeName && rawTypeData.rawTypeData && rawTypeData.$ref) return rawTypeData;
|
|
@@ -806,9 +829,13 @@ var SchemaComponentsMap = class {
|
|
|
806
829
|
}
|
|
807
830
|
const componentDraft = this.createComponentDraft(resolvedRef, resolvedTypeData);
|
|
808
831
|
componentDraft.typeName = this.config.hooks.onFormatExternalTypeName?.(componentDraft.typeName, refDetails) || componentDraft.typeName;
|
|
832
|
+
if (this.config.preferExistingSchemaNamesForExternalRefs) {
|
|
833
|
+
const existingByFragment = this.findExistingComponentBySchemaFragment(refDetails.ref, componentDraft.typeName);
|
|
834
|
+
if (existingByFragment) return existingByFragment;
|
|
835
|
+
}
|
|
809
836
|
if (this._data.some((component) => component.typeName === componentDraft.typeName)) {
|
|
810
837
|
if (this.preferExistingSchemaNameForExternalRef(componentDraft.typeName, refDetails)) {
|
|
811
|
-
const existingComponent = this._data.find((component) => component.typeName === componentDraft.typeName);
|
|
838
|
+
const existingComponent = this.findExistingComponentBySchemaFragment(refDetails.ref, componentDraft.typeName) ?? this._data.find((component) => component.typeName === componentDraft.typeName);
|
|
812
839
|
if (existingComponent) return existingComponent;
|
|
813
840
|
}
|
|
814
841
|
componentDraft.typeName = this.config.hooks.onFixDuplicateExternalTypeName?.(componentDraft.typeName, refDetails, this._data.map((it) => it.typeName)) ?? `${pascalCase(refDetails.externalOpenapiFileName || "External")}${componentDraft.typeName}`;
|
|
@@ -3631,6 +3658,14 @@ var CodeGenProcess = class {
|
|
|
3631
3658
|
return parsed;
|
|
3632
3659
|
});
|
|
3633
3660
|
this.schemaRoutes.attachSchema(resolvedSwaggerSchema, parsedSchemas);
|
|
3661
|
+
if (!this.config.preferExistingSchemaNamesForExternalRefs) {
|
|
3662
|
+
this.typeNameFormatter.precommit(this.schemaComponentsMap.getComponents().map((component) => component.typeName));
|
|
3663
|
+
for (const component of componentsToParse) {
|
|
3664
|
+
component.typeData = null;
|
|
3665
|
+
delete component.$prepared;
|
|
3666
|
+
component.typeData = this.schemaParserFabric.parseSchema(component.rawTypeData, component.typeName);
|
|
3667
|
+
}
|
|
3668
|
+
}
|
|
3634
3669
|
const rawConfiguration = {
|
|
3635
3670
|
apiConfig: this.createApiConfig(resolvedSwaggerSchema.usageSchema),
|
|
3636
3671
|
config: this.config,
|
|
@@ -4025,4 +4060,4 @@ async function generateApi(config) {
|
|
|
4025
4060
|
//#endregion
|
|
4026
4061
|
export { SCHEMA_TYPES as a, constants_exports as c, version as d, RequestContentKind as i, description as l, generateTemplates as n, CodeGenConfig as o, TemplatesGenConfig as r, HTTP_CLIENT as s, generateApi as t, name as u };
|
|
4027
4062
|
|
|
4028
|
-
//# sourceMappingURL=src-
|
|
4063
|
+
//# sourceMappingURL=src-C0d8cMi-.mjs.map
|