swagger-typescript-api 13.9.3 → 13.10.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 +8 -2
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +8 -2
- package/dist/cli.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +10 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{src-BeBS6icj.cjs → src-B2z6JCvN.cjs} +19 -6
- package/dist/src-B2z6JCvN.cjs.map +1 -0
- package/dist/{src-D2qG03ZJ.mjs → src-djU9KRKm.mjs} +19 -6
- package/dist/src-djU9KRKm.mjs.map +1 -0
- package/package.json +3 -3
- package/templates/base/data-contracts.ejs +10 -0
- package/templates/base/enum-data-contract.ejs +6 -1
- package/templates/base/http-clients/axios-http-client.ejs +11 -0
- package/templates/base/http-clients/fetch-http-client.ejs +11 -0
- package/templates/default/procedure-call.ejs +2 -1
- package/templates/modular/procedure-call.ejs +2 -1
- package/dist/src-BeBS6icj.cjs.map +0 -1
- package/dist/src-D2qG03ZJ.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.10.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",
|
|
@@ -68,12 +68,12 @@
|
|
|
68
68
|
"@changesets/cli": "2.31.0",
|
|
69
69
|
"@tsconfig/node20": "20.1.9",
|
|
70
70
|
"@tsconfig/strictest": "2.0.8",
|
|
71
|
-
"@types/node": "25.9.
|
|
71
|
+
"@types/node": "25.9.1",
|
|
72
72
|
"@types/swagger2openapi": "7.0.4",
|
|
73
73
|
"axios": "1.16.1",
|
|
74
74
|
"tsdown": "0.21.10",
|
|
75
75
|
"typedoc": "0.28.19",
|
|
76
|
-
"vitest": "4.1.
|
|
76
|
+
"vitest": "4.1.7"
|
|
77
77
|
},
|
|
78
78
|
"engines": {
|
|
79
79
|
"node": ">=20"
|
|
@@ -25,6 +25,16 @@ const dataContractTemplates = {
|
|
|
25
25
|
type: (contract) => {
|
|
26
26
|
return `type ${contract.name}${buildGenerics(contract)} = ${contract.content}`;
|
|
27
27
|
},
|
|
28
|
+
const: (contract) => {
|
|
29
|
+
const entries = contract.$content
|
|
30
|
+
.map(({ key, value }) => ` ${key}: ${value}`)
|
|
31
|
+
.join(',\n');
|
|
32
|
+
const typeExport = contract.internal ? '' : 'export ';
|
|
33
|
+
return (
|
|
34
|
+
`const ${contract.name} = {\n${entries},\n} as const\n` +
|
|
35
|
+
`${typeExport}type ${contract.name} = (typeof ${contract.name})[keyof typeof ${contract.name}]`
|
|
36
|
+
);
|
|
37
|
+
},
|
|
28
38
|
}
|
|
29
39
|
%>
|
|
30
40
|
|
|
@@ -3,7 +3,12 @@ const { contract, utils, config } = it;
|
|
|
3
3
|
const { formatDescription, require, _ } = utils;
|
|
4
4
|
const { name, $content } = contract;
|
|
5
5
|
%>
|
|
6
|
-
<% if (config.
|
|
6
|
+
<% if (config.enumStyle === "const") { %>
|
|
7
|
+
export const <%~ name %> = {
|
|
8
|
+
<%~ _.map($content, ({ key, value }) => `${key}: ${value}`).join(",\n ") %>
|
|
9
|
+
} as const;
|
|
10
|
+
export type <%~ name %> = (typeof <%~ name %>)[keyof typeof <%~ name %>];
|
|
11
|
+
<% } else if (config.enumStyle === "union") { %>
|
|
7
12
|
export type <%~ name %> = <%~ _.map($content, ({ value }) => value).join(" | ") %>
|
|
8
13
|
<% } else { %>
|
|
9
14
|
export enum <%~ name %> {
|
|
@@ -30,6 +30,16 @@ export interface ApiConfig<SecurityDataType = unknown> extends Omit<AxiosRequest
|
|
|
30
30
|
format?: ResponseType;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
<% if (config.enumStyle === "const") { %>
|
|
34
|
+
export const ContentType = {
|
|
35
|
+
Json: "application/json",
|
|
36
|
+
JsonApi: "application/vnd.api+json",
|
|
37
|
+
FormData: "multipart/form-data",
|
|
38
|
+
UrlEncoded: "application/x-www-form-urlencoded",
|
|
39
|
+
Text: "text/plain",
|
|
40
|
+
} as const;
|
|
41
|
+
export type ContentType = (typeof ContentType)[keyof typeof ContentType];
|
|
42
|
+
<% } else { %>
|
|
33
43
|
export enum ContentType {
|
|
34
44
|
Json = "application/json",
|
|
35
45
|
JsonApi = "application/vnd.api+json",
|
|
@@ -37,6 +47,7 @@ export enum ContentType {
|
|
|
37
47
|
UrlEncoded = "application/x-www-form-urlencoded",
|
|
38
48
|
Text = "text/plain",
|
|
39
49
|
}
|
|
50
|
+
<% } %>
|
|
40
51
|
|
|
41
52
|
export class HttpClient<SecurityDataType = unknown> {
|
|
42
53
|
public instance: AxiosInstance;
|
|
@@ -41,6 +41,16 @@ export interface HttpResponse<D extends unknown, E extends unknown = unknown> ex
|
|
|
41
41
|
|
|
42
42
|
type CancelToken = Symbol | string | number;
|
|
43
43
|
|
|
44
|
+
<% if (config.enumStyle === "const") { %>
|
|
45
|
+
export const ContentType = {
|
|
46
|
+
Json: "application/json",
|
|
47
|
+
JsonApi: "application/vnd.api+json",
|
|
48
|
+
FormData: "multipart/form-data",
|
|
49
|
+
UrlEncoded: "application/x-www-form-urlencoded",
|
|
50
|
+
Text: "text/plain",
|
|
51
|
+
} as const;
|
|
52
|
+
export type ContentType = (typeof ContentType)[keyof typeof ContentType];
|
|
53
|
+
<% } else { %>
|
|
44
54
|
export enum ContentType {
|
|
45
55
|
Json = "application/json",
|
|
46
56
|
JsonApi = "application/vnd.api+json",
|
|
@@ -48,6 +58,7 @@ export enum ContentType {
|
|
|
48
58
|
UrlEncoded = "application/x-www-form-urlencoded",
|
|
49
59
|
Text = "text/plain",
|
|
50
60
|
}
|
|
61
|
+
<% } %>
|
|
51
62
|
|
|
52
63
|
export class HttpClient<SecurityDataType = unknown> {
|
|
53
64
|
public baseUrl: string = "<%~ apiConfig.baseUrl %>";
|
|
@@ -31,8 +31,9 @@ const rawWrapperArgs = config.extractRequestParams ?
|
|
|
31
31
|
_.compact([
|
|
32
32
|
requestParams && {
|
|
33
33
|
name: extractedRequestParamsName,
|
|
34
|
-
optional:
|
|
34
|
+
optional: route.request.requestParamsOptional,
|
|
35
35
|
type: getInlineParseContent(requestParams),
|
|
36
|
+
defaultValue: route.request.requestParamsOptional ? '{}' : undefined,
|
|
36
37
|
},
|
|
37
38
|
...(!requestParams ? pathParams : []),
|
|
38
39
|
payload,
|
|
@@ -31,8 +31,9 @@ const rawWrapperArgs = config.extractRequestParams ?
|
|
|
31
31
|
_.compact([
|
|
32
32
|
requestParams && {
|
|
33
33
|
name: extractedRequestParamsName,
|
|
34
|
-
optional:
|
|
34
|
+
optional: route.request.requestParamsOptional,
|
|
35
35
|
type: getInlineParseContent(requestParams),
|
|
36
|
+
defaultValue: route.request.requestParamsOptional ? '{}' : undefined,
|
|
36
37
|
},
|
|
37
38
|
...(!requestParams ? pathParams : []),
|
|
38
39
|
payload,
|