swagger-typescript-api 13.6.6 → 13.6.8
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 +16 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +16 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{src-B-lBUhqS.mjs → src-DiFkAFgb.mjs} +48 -18
- package/dist/src-DiFkAFgb.mjs.map +1 -0
- package/dist/{src-BROE-dEG.cjs → src-DyV7bb1c.cjs} +48 -18
- package/dist/src-DyV7bb1c.cjs.map +1 -0
- package/package.json +5 -5
- package/dist/src-B-lBUhqS.mjs.map +0 -1
- package/dist/src-BROE-dEG.cjs.map +0 -1
|
@@ -43,6 +43,7 @@ let _biomejs_js_api = require("@biomejs/js-api");
|
|
|
43
43
|
let nanoid = require("nanoid");
|
|
44
44
|
nanoid = __toESM(nanoid);
|
|
45
45
|
let yummies_type_guard = require("yummies/type-guard");
|
|
46
|
+
let yummies_common = require("yummies/common");
|
|
46
47
|
let node_crypto = require("node:crypto");
|
|
47
48
|
node_crypto = __toESM(node_crypto);
|
|
48
49
|
let swagger2openapi = require("swagger2openapi");
|
|
@@ -182,12 +183,6 @@ var NameResolver = class {
|
|
|
182
183
|
}
|
|
183
184
|
};
|
|
184
185
|
//#endregion
|
|
185
|
-
//#region src/util/random.ts
|
|
186
|
-
const getRandomInt = (min = 0, max = 1) => {
|
|
187
|
-
if (min === max) return min;
|
|
188
|
-
return Math.round(Math.random() * (max - min) + min);
|
|
189
|
-
};
|
|
190
|
-
//#endregion
|
|
191
186
|
//#region src/component-type-name-resolver.ts
|
|
192
187
|
var ComponentTypeNameResolver = class extends NameResolver {
|
|
193
188
|
counter = 1;
|
|
@@ -195,12 +190,12 @@ var ComponentTypeNameResolver = class extends NameResolver {
|
|
|
195
190
|
countersByVariant = /* @__PURE__ */ new Map();
|
|
196
191
|
constructor(config, reservedNames) {
|
|
197
192
|
super(config, reservedNames, (variants) => {
|
|
198
|
-
const
|
|
199
|
-
if (
|
|
200
|
-
if (!this.countersByVariant.has(
|
|
201
|
-
const variantCounter = this.countersByVariant.get(
|
|
202
|
-
this.countersByVariant.set(
|
|
203
|
-
const dirtyResolvedName = `${
|
|
193
|
+
const baseVariant = (0, es_toolkit.uniq)((0, es_toolkit.compact)(variants)).sort((a, b) => a.localeCompare(b))[0];
|
|
194
|
+
if (baseVariant) {
|
|
195
|
+
if (!this.countersByVariant.has(baseVariant)) this.countersByVariant.set(baseVariant, 0);
|
|
196
|
+
const variantCounter = this.countersByVariant.get(baseVariant) + 1;
|
|
197
|
+
this.countersByVariant.set(baseVariant, variantCounter);
|
|
198
|
+
const dirtyResolvedName = `${baseVariant}${variantCounter}`;
|
|
204
199
|
consola.consola.debug("generated dirty resolved type name for component - ", dirtyResolvedName);
|
|
205
200
|
return dirtyResolvedName;
|
|
206
201
|
}
|
|
@@ -213,7 +208,7 @@ var ComponentTypeNameResolver = class extends NameResolver {
|
|
|
213
208
|
//#endregion
|
|
214
209
|
//#region package.json
|
|
215
210
|
var name = "swagger-typescript-api";
|
|
216
|
-
var version = "13.6.
|
|
211
|
+
var version = "13.6.8";
|
|
217
212
|
var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
|
|
218
213
|
//#endregion
|
|
219
214
|
//#region src/constants.ts
|
|
@@ -673,9 +668,9 @@ var SchemaComponentsMap = class {
|
|
|
673
668
|
else this._data[refIndex] = usageComponent;
|
|
674
669
|
return usageComponent;
|
|
675
670
|
}
|
|
676
|
-
getComponents() {
|
|
671
|
+
getComponents = () => {
|
|
677
672
|
return this._data;
|
|
678
|
-
}
|
|
673
|
+
};
|
|
679
674
|
filter(...componentNames) {
|
|
680
675
|
return this._data.filter((it) => componentNames.some((componentName) => it.$ref.startsWith(`#/components/${componentName}`)));
|
|
681
676
|
}
|
|
@@ -1702,6 +1697,11 @@ const CONTENT_KIND = {
|
|
|
1702
1697
|
OTHER: "OTHER",
|
|
1703
1698
|
TEXT: "TEXT"
|
|
1704
1699
|
};
|
|
1700
|
+
/**
|
|
1701
|
+
* When a colliding extract name is repeatedly resolved, cap iterations so a resolver
|
|
1702
|
+
* bug cannot loop forever. In practice 1–2 attempts are enough (suffix list is short).
|
|
1703
|
+
*/
|
|
1704
|
+
const MAX_EXTRACT_SCHEMA_KEY_COLLISION_ATTEMPTS = 32;
|
|
1705
1705
|
var SchemaRoutes = class {
|
|
1706
1706
|
schemaUtils;
|
|
1707
1707
|
FORM_DATA_TYPES = [];
|
|
@@ -1724,6 +1724,36 @@ var SchemaRoutes = class {
|
|
|
1724
1724
|
format: "binary"
|
|
1725
1725
|
})]);
|
|
1726
1726
|
}
|
|
1727
|
+
/**
|
|
1728
|
+
* `extractResponseBody` / `extractResponseError` call `createParsedComponent`, which
|
|
1729
|
+
* registers `#/components/schemas/<typeName>`. If that key already exists (e.g.
|
|
1730
|
+
* `MergeFluffyData` in definitions), the map entry would be overwritten unless we
|
|
1731
|
+
* pick another name via `resolveTypeName` after reserving the colliding one.
|
|
1732
|
+
*
|
|
1733
|
+
* `getComponents` may be missing in narrow unit tests that pass a stub map.
|
|
1734
|
+
*
|
|
1735
|
+
* `resolveTypeName` ends in `NameResolver.resolve`, which **reserves** the chosen
|
|
1736
|
+
* string when `shouldReserve` is true (default). So after a colliding first pick,
|
|
1737
|
+
* the next `resolveTypeName` skips that variant. The extra `reserve([typeName])`
|
|
1738
|
+
* is still needed when callers pass `shouldReserve: false` — then the first pick
|
|
1739
|
+
* is not auto-reserved and we must block it before retrying.
|
|
1740
|
+
*/
|
|
1741
|
+
extractTypeNameWithoutSchemaKeyCollision = (routeNameUsage, options) => {
|
|
1742
|
+
const refFor = (name) => this.schemaComponentsMap.createRef([
|
|
1743
|
+
"components",
|
|
1744
|
+
"schemas",
|
|
1745
|
+
name
|
|
1746
|
+
]);
|
|
1747
|
+
const existingComponents = (0, yummies_common.callFunction)(this.schemaComponentsMap.getComponents) ?? [];
|
|
1748
|
+
const collides = (name) => !!name && existingComponents.some((c) => c.$ref === refFor(name));
|
|
1749
|
+
let typeName = this.schemaUtils.resolveTypeName(routeNameUsage, options);
|
|
1750
|
+
for (let attempt = 0; attempt < MAX_EXTRACT_SCHEMA_KEY_COLLISION_ATTEMPTS; attempt++) {
|
|
1751
|
+
if (!collides(typeName)) break;
|
|
1752
|
+
this.config.componentTypeNameResolver.reserve([typeName]);
|
|
1753
|
+
typeName = this.schemaUtils.resolveTypeName(routeNameUsage, options);
|
|
1754
|
+
}
|
|
1755
|
+
return typeName;
|
|
1756
|
+
};
|
|
1727
1757
|
createRequestsMap = (resolvedSwaggerSchema, routesByMethod) => {
|
|
1728
1758
|
const parameters = (0, es_toolkit_compat.get)(routesByMethod, "parameters");
|
|
1729
1759
|
const result = {};
|
|
@@ -2076,7 +2106,7 @@ var SchemaRoutes = class {
|
|
|
2076
2106
|
};
|
|
2077
2107
|
extractResponseBodyIfItNeeded = (routeInfo, responseBodyInfo, routeName) => {
|
|
2078
2108
|
if (responseBodyInfo.responses.length && responseBodyInfo.success && responseBodyInfo.success.schema) {
|
|
2079
|
-
const typeName = this.
|
|
2109
|
+
const typeName = this.extractTypeNameWithoutSchemaKeyCollision(routeName.usage, {
|
|
2080
2110
|
suffixes: this.config.extractingOptions.responseBodySuffix,
|
|
2081
2111
|
resolver: this.config.extractingOptions.responseBodyNameResolver
|
|
2082
2112
|
});
|
|
@@ -2144,7 +2174,7 @@ var SchemaRoutes = class {
|
|
|
2144
2174
|
};
|
|
2145
2175
|
extractResponseErrorIfItNeeded = (routeInfo, responseBodyInfo, routeName) => {
|
|
2146
2176
|
if (responseBodyInfo.responses.length && responseBodyInfo.error.schemas && responseBodyInfo.error.schemas.length) {
|
|
2147
|
-
const typeName = this.
|
|
2177
|
+
const typeName = this.extractTypeNameWithoutSchemaKeyCollision(routeName.usage, {
|
|
2148
2178
|
suffixes: this.config.extractingOptions.responseErrorSuffix,
|
|
2149
2179
|
resolver: this.config.extractingOptions.responseErrorNameResolver
|
|
2150
2180
|
});
|
|
@@ -3706,4 +3736,4 @@ Object.defineProperty(exports, "version", {
|
|
|
3706
3736
|
}
|
|
3707
3737
|
});
|
|
3708
3738
|
|
|
3709
|
-
//# sourceMappingURL=src-
|
|
3739
|
+
//# sourceMappingURL=src-DyV7bb1c.cjs.map
|