swagger-typescript-api 13.6.7 → 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--O_oZouc.mjs → src-DiFkAFgb.mjs} +42 -6
- package/dist/src-DiFkAFgb.mjs.map +1 -0
- package/dist/{src-CUhSthD5.cjs → src-DyV7bb1c.cjs} +42 -6
- package/dist/src-DyV7bb1c.cjs.map +1 -0
- package/package.json +4 -4
- package/dist/src--O_oZouc.mjs.map +0 -1
- package/dist/src-CUhSthD5.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");
|
|
@@ -207,7 +208,7 @@ var ComponentTypeNameResolver = class extends NameResolver {
|
|
|
207
208
|
//#endregion
|
|
208
209
|
//#region package.json
|
|
209
210
|
var name = "swagger-typescript-api";
|
|
210
|
-
var version = "13.6.
|
|
211
|
+
var version = "13.6.8";
|
|
211
212
|
var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
|
|
212
213
|
//#endregion
|
|
213
214
|
//#region src/constants.ts
|
|
@@ -667,9 +668,9 @@ var SchemaComponentsMap = class {
|
|
|
667
668
|
else this._data[refIndex] = usageComponent;
|
|
668
669
|
return usageComponent;
|
|
669
670
|
}
|
|
670
|
-
getComponents() {
|
|
671
|
+
getComponents = () => {
|
|
671
672
|
return this._data;
|
|
672
|
-
}
|
|
673
|
+
};
|
|
673
674
|
filter(...componentNames) {
|
|
674
675
|
return this._data.filter((it) => componentNames.some((componentName) => it.$ref.startsWith(`#/components/${componentName}`)));
|
|
675
676
|
}
|
|
@@ -1696,6 +1697,11 @@ const CONTENT_KIND = {
|
|
|
1696
1697
|
OTHER: "OTHER",
|
|
1697
1698
|
TEXT: "TEXT"
|
|
1698
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;
|
|
1699
1705
|
var SchemaRoutes = class {
|
|
1700
1706
|
schemaUtils;
|
|
1701
1707
|
FORM_DATA_TYPES = [];
|
|
@@ -1718,6 +1724,36 @@ var SchemaRoutes = class {
|
|
|
1718
1724
|
format: "binary"
|
|
1719
1725
|
})]);
|
|
1720
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
|
+
};
|
|
1721
1757
|
createRequestsMap = (resolvedSwaggerSchema, routesByMethod) => {
|
|
1722
1758
|
const parameters = (0, es_toolkit_compat.get)(routesByMethod, "parameters");
|
|
1723
1759
|
const result = {};
|
|
@@ -2070,7 +2106,7 @@ var SchemaRoutes = class {
|
|
|
2070
2106
|
};
|
|
2071
2107
|
extractResponseBodyIfItNeeded = (routeInfo, responseBodyInfo, routeName) => {
|
|
2072
2108
|
if (responseBodyInfo.responses.length && responseBodyInfo.success && responseBodyInfo.success.schema) {
|
|
2073
|
-
const typeName = this.
|
|
2109
|
+
const typeName = this.extractTypeNameWithoutSchemaKeyCollision(routeName.usage, {
|
|
2074
2110
|
suffixes: this.config.extractingOptions.responseBodySuffix,
|
|
2075
2111
|
resolver: this.config.extractingOptions.responseBodyNameResolver
|
|
2076
2112
|
});
|
|
@@ -2138,7 +2174,7 @@ var SchemaRoutes = class {
|
|
|
2138
2174
|
};
|
|
2139
2175
|
extractResponseErrorIfItNeeded = (routeInfo, responseBodyInfo, routeName) => {
|
|
2140
2176
|
if (responseBodyInfo.responses.length && responseBodyInfo.error.schemas && responseBodyInfo.error.schemas.length) {
|
|
2141
|
-
const typeName = this.
|
|
2177
|
+
const typeName = this.extractTypeNameWithoutSchemaKeyCollision(routeName.usage, {
|
|
2142
2178
|
suffixes: this.config.extractingOptions.responseErrorSuffix,
|
|
2143
2179
|
resolver: this.config.extractingOptions.responseErrorNameResolver
|
|
2144
2180
|
});
|
|
@@ -3700,4 +3736,4 @@ Object.defineProperty(exports, "version", {
|
|
|
3700
3736
|
}
|
|
3701
3737
|
});
|
|
3702
3738
|
|
|
3703
|
-
//# sourceMappingURL=src-
|
|
3739
|
+
//# sourceMappingURL=src-DyV7bb1c.cjs.map
|