swagger-typescript-api 13.10.0 → 13.11.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 +7 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +7 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +15 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +15 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{src-B2z6JCvN.cjs → src-C6CxNImi.cjs} +89 -7
- package/dist/{src-B2z6JCvN.cjs.map → src-C6CxNImi.cjs.map} +1 -1
- package/dist/{src-djU9KRKm.mjs → src-CxQXlsuV.mjs} +89 -7
- package/dist/{src-djU9KRKm.mjs.map → src-CxQXlsuV.mjs.map} +1 -1
- package/package.json +3 -3
- package/templates/base/content-type-accessors.ejs +18 -0
- package/templates/base/http-clients/axios-http-client.ejs +5 -2
- package/templates/base/http-clients/fetch-http-client.ejs +10 -7
- package/templates/default/procedure-call.ejs +1 -7
- package/templates/modular/api.ejs +4 -0
- package/templates/modular/procedure-call.ejs +1 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swagger-typescript-api",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.11.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,7 +46,7 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@apidevtools/swagger-parser": "12.1.0",
|
|
48
48
|
"@biomejs/js-api": "4.0.0",
|
|
49
|
-
"@biomejs/wasm-nodejs": "2.4.
|
|
49
|
+
"@biomejs/wasm-nodejs": "2.4.16",
|
|
50
50
|
"@types/swagger-schema-official": "^2.0.25",
|
|
51
51
|
"c12": "^3.3.3",
|
|
52
52
|
"citty": "^0.2.1",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"yummies": "7.19.4"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@biomejs/biome": "2.4.
|
|
66
|
+
"@biomejs/biome": "2.4.16",
|
|
67
67
|
"@changesets/changelog-github": "0.7.0",
|
|
68
68
|
"@changesets/cli": "2.31.0",
|
|
69
69
|
"@tsconfig/node20": "20.1.9",
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<%
|
|
2
|
+
const { config } = it;
|
|
3
|
+
const isUnion = config.enumStyle === "union";
|
|
4
|
+
|
|
5
|
+
// camelCase keys (Json, FormData, …) are used by http-client templates as CT.Json, CT.FormData, …
|
|
6
|
+
// They mirror the ContentType property names so the access pattern is identical regardless of enumStyle.
|
|
7
|
+
const v = {
|
|
8
|
+
Json: isUnion ? '"application/json"' : "ContentType.Json",
|
|
9
|
+
JsonApi: isUnion ? '"application/vnd.api+json"' : "ContentType.JsonApi",
|
|
10
|
+
FormData: isUnion ? '"multipart/form-data"' : "ContentType.FormData",
|
|
11
|
+
UrlEncoded: isUnion ? '"application/x-www-form-urlencoded"' : "ContentType.UrlEncoded",
|
|
12
|
+
Text: isUnion ? '"text/plain"' : "ContentType.Text",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// UPPER_SNAKE aliases (JSON, FORM_DATA, …) are used by procedure-call templates as
|
|
16
|
+
// requestContentKind["JSON"], matching the CONTENT_KIND constants produced by schema-routes.ts.
|
|
17
|
+
return { ...v, JSON: v.Json, JSON_API: v.JsonApi, FORM_DATA: v.FormData, URL_ENCODED: v.UrlEncoded, TEXT: v.Text };
|
|
18
|
+
%>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<%
|
|
2
2
|
const { apiConfig, generateResponses, config } = it;
|
|
3
|
+
const CT = includeFile("@base/content-type-accessors", { config });
|
|
3
4
|
%>
|
|
4
5
|
|
|
5
6
|
import type { AxiosInstance, AxiosRequestConfig, HeadersDefaults, ResponseType, AxiosResponse } from "axios";
|
|
@@ -39,6 +40,8 @@ export const ContentType = {
|
|
|
39
40
|
Text: "text/plain",
|
|
40
41
|
} as const;
|
|
41
42
|
export type ContentType = (typeof ContentType)[keyof typeof ContentType];
|
|
43
|
+
<% } else if (config.enumStyle === "union") { %>
|
|
44
|
+
export type ContentType = "application/json" | "application/vnd.api+json" | "multipart/form-data" | "application/x-www-form-urlencoded" | "text/plain";
|
|
42
45
|
<% } else { %>
|
|
43
46
|
export enum ContentType {
|
|
44
47
|
Json = "application/json",
|
|
@@ -127,11 +130,11 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
127
130
|
const requestParams = this.mergeRequestParams(params, secureParams);
|
|
128
131
|
const responseFormat = (format || this.format) || undefined;
|
|
129
132
|
|
|
130
|
-
if (type ===
|
|
133
|
+
if (type === <%~ CT.FormData %> && body && body !== null && typeof body === "object") {
|
|
131
134
|
body = this.createFormData(body as Record<string, unknown>);
|
|
132
135
|
}
|
|
133
136
|
|
|
134
|
-
if (type ===
|
|
137
|
+
if (type === <%~ CT.Text %> && body && body !== null && typeof body !== "string") {
|
|
135
138
|
body = JSON.stringify(body);
|
|
136
139
|
}
|
|
137
140
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<%
|
|
2
2
|
const { apiConfig, generateResponses, config } = it;
|
|
3
|
+
const CT = includeFile("@base/content-type-accessors", { config });
|
|
3
4
|
%>
|
|
4
5
|
|
|
5
6
|
export type QueryParamsType = Record<string | number, any>;
|
|
@@ -50,6 +51,8 @@ export const ContentType = {
|
|
|
50
51
|
Text: "text/plain",
|
|
51
52
|
} as const;
|
|
52
53
|
export type ContentType = (typeof ContentType)[keyof typeof ContentType];
|
|
54
|
+
<% } else if (config.enumStyle === "union") { %>
|
|
55
|
+
export type ContentType = "application/json" | "application/vnd.api+json" | "multipart/form-data" | "application/x-www-form-urlencoded" | "text/plain";
|
|
53
56
|
<% } else { %>
|
|
54
57
|
export enum ContentType {
|
|
55
58
|
Json = "application/json",
|
|
@@ -114,10 +117,10 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
114
117
|
}
|
|
115
118
|
|
|
116
119
|
private contentFormatters: Record<ContentType, (input: any) => any> = {
|
|
117
|
-
[
|
|
118
|
-
[
|
|
119
|
-
[
|
|
120
|
-
[
|
|
120
|
+
[<%~ CT.Json %>]: (input:any) => input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
|
|
121
|
+
[<%~ CT.JsonApi %>]: (input:any) => input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
|
|
122
|
+
[<%~ CT.Text %>]: (input:any) => input !== null && typeof input !== "string" ? JSON.stringify(input) : input,
|
|
123
|
+
[<%~ CT.FormData %>]: (input: any) => {
|
|
121
124
|
if (input instanceof FormData) {
|
|
122
125
|
return input;
|
|
123
126
|
}
|
|
@@ -135,7 +138,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
135
138
|
return formData;
|
|
136
139
|
}, new FormData());
|
|
137
140
|
},
|
|
138
|
-
[
|
|
141
|
+
[<%~ CT.UrlEncoded %>]: (input: any) => this.toQueryString(input),
|
|
139
142
|
}
|
|
140
143
|
|
|
141
144
|
protected mergeRequestParams(params1: RequestParams, params2?: RequestParams): RequestParams {
|
|
@@ -192,7 +195,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
192
195
|
const secureParams = ((typeof secure === 'boolean' ? secure : this.baseApiParams.secure) && this.securityWorker && await this.securityWorker(this.securityData)) || {};
|
|
193
196
|
const requestParams = this.mergeRequestParams(params, secureParams);
|
|
194
197
|
const queryString = query && this.toQueryString(query);
|
|
195
|
-
const payloadFormatter = this.contentFormatters[type ||
|
|
198
|
+
const payloadFormatter = this.contentFormatters[type || <%~ CT.Json %>];
|
|
196
199
|
const responseFormat = format || requestParams.format;
|
|
197
200
|
|
|
198
201
|
return this.customFetch(
|
|
@@ -201,7 +204,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
201
204
|
...requestParams,
|
|
202
205
|
headers: {
|
|
203
206
|
...(requestParams.headers || {}),
|
|
204
|
-
...(type && type !==
|
|
207
|
+
...(type && type !== <%~ CT.FormData %> ? { "Content-Type": type } : {}),
|
|
205
208
|
},
|
|
206
209
|
signal: (cancelToken ? this.createAbortSignal(cancelToken) : requestParams.signal) || null,
|
|
207
210
|
body: typeof body === "undefined" || body === null ? null : payloadFormatter(body),
|
|
@@ -53,13 +53,7 @@ const wrapperArgs = _
|
|
|
53
53
|
.join(', ')
|
|
54
54
|
|
|
55
55
|
// RequestParams["type"]
|
|
56
|
-
const requestContentKind = {
|
|
57
|
-
"JSON": "ContentType.Json",
|
|
58
|
-
"JSON_API": "ContentType.JsonApi",
|
|
59
|
-
"URL_ENCODED": "ContentType.UrlEncoded",
|
|
60
|
-
"FORM_DATA": "ContentType.FormData",
|
|
61
|
-
"TEXT": "ContentType.Text",
|
|
62
|
-
}
|
|
56
|
+
const requestContentKind = includeFile("@base/content-type-accessors", { config });
|
|
63
57
|
// RequestParams["format"]
|
|
64
58
|
const responseContentKind = {
|
|
65
59
|
"JSON": '"json"',
|
|
@@ -8,7 +8,11 @@ const dataContracts = _.map(modelTypes, "name");
|
|
|
8
8
|
|
|
9
9
|
<% if (config.httpClientType === config.constants.HTTP_CLIENT.AXIOS) { %> import type { AxiosRequestConfig, AxiosResponse } from "axios"; <% } %>
|
|
10
10
|
|
|
11
|
+
<% if (config.enumStyle === "union") { %>
|
|
12
|
+
import { HttpClient, RequestParams, type ContentType, HttpResponse } from "./<%~ config.fileNames.httpClient %>";
|
|
13
|
+
<% } else { %>
|
|
11
14
|
import { HttpClient, RequestParams, ContentType, HttpResponse } from "./<%~ config.fileNames.httpClient %>";
|
|
15
|
+
<% } %>
|
|
12
16
|
<% if (dataContracts.length) { %>
|
|
13
17
|
import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %>"
|
|
14
18
|
<% } %>
|
|
@@ -53,13 +53,7 @@ const wrapperArgs = _
|
|
|
53
53
|
.join(', ')
|
|
54
54
|
|
|
55
55
|
// RequestParams["type"]
|
|
56
|
-
const requestContentKind = {
|
|
57
|
-
"JSON": "ContentType.Json",
|
|
58
|
-
"JSON_API": "ContentType.JsonApi",
|
|
59
|
-
"URL_ENCODED": "ContentType.UrlEncoded",
|
|
60
|
-
"FORM_DATA": "ContentType.FormData",
|
|
61
|
-
"TEXT": "ContentType.Text",
|
|
62
|
-
}
|
|
56
|
+
const requestContentKind = includeFile("@base/content-type-accessors", { config });
|
|
63
57
|
// RequestParams["format"]
|
|
64
58
|
const responseContentKind = {
|
|
65
59
|
"JSON": '"json"',
|