swagger-typescript-api 13.12.5 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swagger-typescript-api",
3
- "version": "13.12.5",
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(rawWrapperArgs, [o => o.optional])
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
- <% if (config.enumStyle === "union") { %>
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(rawWrapperArgs, [o => o.optional])
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) %> {