swagger-typescript-api 13.12.6 → 13.13.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 +19 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +19 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +28 -5
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +28 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{src-BY6Hz6vz.cjs → src-66lzgISA.cjs} +25 -9
- package/dist/src-66lzgISA.cjs.map +1 -0
- package/dist/{src-Dex5t5WU.mjs → src-DXotSN2p.mjs} +25 -9
- package/dist/src-DXotSN2p.mjs.map +1 -0
- package/package.json +1 -1
- package/templates/default/procedure-call.ejs +13 -1
- package/templates/default/route-types.ejs +1 -1
- package/templates/modular/api.ejs +7 -6
- package/templates/modular/procedure-call.ejs +13 -1
- package/templates/modular/route-types.ejs +1 -1
- package/dist/src-BY6Hz6vz.cjs.map +0 -1
- package/dist/src-Dex5t5WU.mjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swagger-typescript-api",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.13.0",
|
|
4
4
|
"description": "Generate the API client for Fetch or Axios from an OpenAPI Specification",
|
|
5
5
|
"homepage": "https://github.com/acacode/swagger-typescript-api",
|
|
6
6
|
"bugs": "https://github.com/acacode/swagger-typescript-api/issues",
|
|
@@ -46,9 +46,21 @@ const rawWrapperArgs = config.extractRequestParams ?
|
|
|
46
46
|
requestConfigParam,
|
|
47
47
|
])
|
|
48
48
|
|
|
49
|
+
// Before sorting, promote any optional arg that has a defaultValue and is
|
|
50
|
+
// followed by a required arg to "positionally required". The sort still pushes
|
|
51
|
+
// truly-optional (`?:`) args to the end, but defaultable args ahead of a
|
|
52
|
+
// required arg stay in declaration order, so callers' positional arguments
|
|
53
|
+
// don't silently shift when a previously-required query becomes optional.
|
|
54
|
+
const positionedWrapperArgs = rawWrapperArgs.map((arg, i) => {
|
|
55
|
+
if (arg.optional && arg.defaultValue && rawWrapperArgs.slice(i + 1).some(a => !a.optional)) {
|
|
56
|
+
return { ...arg, optional: false };
|
|
57
|
+
}
|
|
58
|
+
return arg;
|
|
59
|
+
})
|
|
60
|
+
|
|
49
61
|
const wrapperArgs = _
|
|
50
62
|
// Sort by optionality
|
|
51
|
-
.sortBy(
|
|
63
|
+
.sortBy(positionedWrapperArgs, [o => o.optional])
|
|
52
64
|
.map(argToTmpl)
|
|
53
65
|
.join(', ')
|
|
54
66
|
|
|
@@ -5,7 +5,7 @@ const dataContracts = config.modular ? _.map(modelTypes, "name") : [];
|
|
|
5
5
|
%>
|
|
6
6
|
|
|
7
7
|
<% if (dataContracts.length) { %>
|
|
8
|
-
import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %>"
|
|
8
|
+
import <%~ config.typeOnlyImports ? "type " : "" %>{ <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %><%~ config.importFileExtension %>"
|
|
9
9
|
<% } %>
|
|
10
10
|
|
|
11
11
|
<%
|
|
@@ -4,17 +4,18 @@ const { _, pascalCase, require } = utils;
|
|
|
4
4
|
const apiClassName = pascalCase(route.moduleName);
|
|
5
5
|
const routes = route.routes;
|
|
6
6
|
const dataContracts = _.map(modelTypes, "name");
|
|
7
|
+
const importExt = config.importFileExtension;
|
|
8
|
+
const typeModifier = config.typeOnlyImports ? "type " : "";
|
|
9
|
+
// ContentType is a pure type only for the "union" style; otherwise it is a runtime value.
|
|
10
|
+
const contentTypeSpecifier = config.enumStyle === "union" ? "type ContentType" : "ContentType";
|
|
11
|
+
const httpClientSpecifiers = ["HttpClient", `${typeModifier}RequestParams`, contentTypeSpecifier, `${typeModifier}HttpResponse`].join(", ");
|
|
7
12
|
%>
|
|
8
13
|
|
|
9
14
|
<% if (config.httpClientType === config.constants.HTTP_CLIENT.AXIOS) { %> import type { AxiosRequestConfig, AxiosResponse } from "axios"; <% } %>
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
import { HttpClient, RequestParams, type ContentType, HttpResponse } from "./<%~ config.fileNames.httpClient %>";
|
|
13
|
-
<% } else { %>
|
|
14
|
-
import { HttpClient, RequestParams, ContentType, HttpResponse } from "./<%~ config.fileNames.httpClient %>";
|
|
15
|
-
<% } %>
|
|
16
|
+
import { <%~ httpClientSpecifiers %> } from "./<%~ config.fileNames.httpClient %><%~ importExt %>";
|
|
16
17
|
<% if (dataContracts.length) { %>
|
|
17
|
-
import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %>"
|
|
18
|
+
import <%~ typeModifier %>{ <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %><%~ importExt %>"
|
|
18
19
|
<% } %>
|
|
19
20
|
|
|
20
21
|
export class <%= apiClassName %><SecurityDataType = unknown><% if (!config.singleHttpClient) { %> extends HttpClient<SecurityDataType> <% } %> {
|
|
@@ -46,9 +46,21 @@ const rawWrapperArgs = config.extractRequestParams ?
|
|
|
46
46
|
requestConfigParam,
|
|
47
47
|
])
|
|
48
48
|
|
|
49
|
+
// Before sorting, promote any optional arg that has a defaultValue and is
|
|
50
|
+
// followed by a required arg to "positionally required". The sort still pushes
|
|
51
|
+
// truly-optional (`?:`) args to the end, but defaultable args ahead of a
|
|
52
|
+
// required arg stay in declaration order, so callers' positional arguments
|
|
53
|
+
// don't silently shift when a previously-required query becomes optional.
|
|
54
|
+
const positionedWrapperArgs = rawWrapperArgs.map((arg, i) => {
|
|
55
|
+
if (arg.optional && arg.defaultValue && rawWrapperArgs.slice(i + 1).some(a => !a.optional)) {
|
|
56
|
+
return { ...arg, optional: false };
|
|
57
|
+
}
|
|
58
|
+
return arg;
|
|
59
|
+
})
|
|
60
|
+
|
|
49
61
|
const wrapperArgs = _
|
|
50
62
|
// Sort by optionality
|
|
51
|
-
.sortBy(
|
|
63
|
+
.sortBy(positionedWrapperArgs, [o => o.optional])
|
|
52
64
|
.map(argToTmpl)
|
|
53
65
|
.join(', ')
|
|
54
66
|
|
|
@@ -6,7 +6,7 @@ const dataContracts = config.modular ? _.map(modelTypes, "name") : [];
|
|
|
6
6
|
|
|
7
7
|
%>
|
|
8
8
|
<% if (dataContracts.length) { %>
|
|
9
|
-
import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %>"
|
|
9
|
+
import <%~ config.typeOnlyImports ? "type " : "" %>{ <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %><%~ config.importFileExtension %>"
|
|
10
10
|
<% } %>
|
|
11
11
|
|
|
12
12
|
export namespace <%~ pascalCase(moduleName) %> {
|