swaggie 1.0.1 → 1.0.2-test.2

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/README.md CHANGED
@@ -116,12 +116,13 @@ Sample configuration looks like this:
116
116
  The following templates are bundled with Swaggie:
117
117
 
118
118
  ```
119
- axios Default template. Recommended for React / Vue / similar frameworks. Uses axios
120
- xior Lightweight and modern alternative to axios. Uses [xior](https://github.com/suhaotian/xior#intro)
121
- swr-axios Template that embraces SRW for GET requests and as a fallback uses axios.
122
- fetch Template similar to axios, but with fetch API instead. Recommended for React / Vue / similar frameworks
123
- ng1 Template for Angular 1 (this is for the old one)
124
- ng2 Template for Angular 2+ (uses HttpClient, InjectionTokens, etc)
119
+ axios Default template. Recommended for React / Vue / similar frameworks. Uses axios
120
+ xior Lightweight and modern alternative to axios. Uses [xior](https://github.com/suhaotian/xior#intro)
121
+ swr-axios Template that embraces SRW for GET requests and as a fallback uses axios.
122
+ tanstack-query Template that uses TanStack Query for GET requests and as a fallback uses xior.
123
+ fetch Template similar to axios, but with fetch API instead. Recommended for React / Vue / similar frameworks
124
+ ng1 Template for Angular 1 (this is for the old one)
125
+ ng2 Template for Angular 2+ (uses HttpClient, InjectionTokens, etc)
125
126
  ```
126
127
 
127
128
  If you want to use your own template, you can use the path to your template for the `-t` parameter:
package/dist/types.d.ts CHANGED
@@ -29,7 +29,7 @@ export interface FullAppOptions extends ClientOptions {
29
29
  /** Path to the configuration file that contains actual config to be used */
30
30
  config?: string;
31
31
  }
32
- export type Template = 'axios' | 'fetch' | 'ng1' | 'ng2' | 'swr-axios' | 'xior';
32
+ export type Template = 'axios' | 'fetch' | 'ng1' | 'ng2' | 'swr-axios' | 'xior' | 'tanstack-query';
33
33
  export type HttpMethod = 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch';
34
34
  export type DateSupport = 'string' | 'Date';
35
35
  export type ArrayFormat = 'indices' | 'repeat' | 'brackets';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swaggie",
3
- "version": "1.0.1",
3
+ "version": "1.0.2-test.2",
4
4
  "description": "Generate TypeScript REST client code from an OpenAPI spec",
5
5
  "author": {
6
6
  "name": "Piotr Dabrowski",
@@ -51,21 +51,21 @@
51
51
  ],
52
52
  "dependencies": {
53
53
  "case": "^1.6.3",
54
- "commander": "^12.1.0",
55
- "eta": "^3.4.0",
54
+ "commander": "^13.1.0",
55
+ "eta": "^3.5.0",
56
56
  "js-yaml": "^4.1.0",
57
57
  "nanocolors": "^0.2.0",
58
- "undici": "^6.19.2"
58
+ "undici": "^7.3.0"
59
59
  },
60
60
  "devDependencies": {
61
- "@types/chai": "4.3.16",
61
+ "@types/chai": "5.0.1",
62
62
  "@types/js-yaml": "4.0.9",
63
- "@types/mocha": "10.0.7",
64
- "@types/node": "20.14.9",
65
- "chai": "4.4.1",
66
- "mocha": "10.6.0",
63
+ "@types/mocha": "10.0.10",
64
+ "@types/node": "22.13.1",
65
+ "chai": "5.1.2",
66
+ "mocha": "11.1.0",
67
67
  "openapi-types": "^12.1.3",
68
68
  "sucrase": "3.35.0",
69
- "typescript": "5.5.3"
69
+ "typescript": "5.7.3"
70
70
  }
71
71
  }
File without changes
@@ -0,0 +1,25 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ //----------------------
4
+ // <auto-generated>
5
+ // Generated using Swaggie (https://github.com/yhnavein/swaggie)
6
+ // Please avoid doing any manual changes in this file
7
+ // </auto-generated>
8
+ //----------------------
9
+ // ReSharper disable InconsistentNaming
10
+ // deno-lint-ignore-file
11
+
12
+ import xior, { type XiorResponse, type XiorRequestConfig, encodeParams } from "xior";
13
+ import { QueryClient, type UndefinedInitialDataOptions, useQuery } from '@tanstack/react-query';
14
+
15
+ export const queryClient = new QueryClient();
16
+
17
+ export const http = xior.create({
18
+ baseURL: '<%= it.baseUrl || '' %>',
19
+ paramsSerializer: (params) =>
20
+ encodeParams(params, true, null, {
21
+ allowDots: <%= it.allowDots %>,
22
+ arrayFormat: '<%= it.arrayFormat %>',
23
+ }),
24
+ });
25
+
@@ -0,0 +1,22 @@
1
+ export const <%= it.camelCaseName %>Client = {
2
+ <% it.operations.forEach((operation) => { %>
3
+ <%~ include('operation.ejs', operation); %>
4
+
5
+ <% }); %>
6
+ };
7
+
8
+
9
+ <% var getOperations = it.operations.filter((o) => o.method === 'GET');
10
+ if(getOperations.length > 0) { %>
11
+ <% getOperations.forEach((operation) => {
12
+ var opName = operation.name;
13
+ if(opName.toLowerCase().startsWith("get")) {
14
+ opName = opName.substring(3);
15
+ }
16
+ opName[0] = opName[0].toUpperCase();
17
+ var customName = "use" + it.clientName + opName;
18
+ var queryOperation = Object.assign({ rqOpName: customName, opKey: it.clientName + opName, clientName: it.camelCaseName }, operation); %>
19
+ <%~ include('queryOperation.ejs', queryOperation); %>
20
+
21
+ <% }); %>
22
+ <% } %>
@@ -0,0 +1,44 @@
1
+ /**
2
+ <% it.parameters.forEach((parameter) => { %>
3
+ * @param <%= parameter.name %> <%= parameter.optional ? '(optional)' : '' %> <%= parameter.name !== parameter.originalName ? `(API name: ${parameter.originalName})` : '' %>
4
+
5
+ <% }); -%>
6
+ */
7
+ <%= it.name %>(<% it.parameters.forEach((parameter) => { %>
8
+ <%= parameter.name %>: <%~ parameter.type %> <%= parameter.optional ? '| null | undefined' : '' %>,
9
+ <% }); %>
10
+ $config?: XiorRequestConfig
11
+ ): Promise<XiorResponse<<%~ it.returnType %>>> {
12
+ const url = `<%= it.url %>`;
13
+
14
+ return http.request<<%~ it.returnType %>>({
15
+ url: url,
16
+ method: '<%= it.method %>',
17
+ <% if(it.body) { %>
18
+ <% if(it.body.contentType === 'urlencoded') { %>
19
+ data: new URLSearchParams(<%= it.body.name %> as any),
20
+ <% } else { %>
21
+ data: <%= it.body.name %>,
22
+ <% } %>
23
+ <% } %>
24
+ <% if(it.query && it.query.length > 0) { %>
25
+ params: {
26
+ <% it.query.forEach((parameter) => { %>
27
+ '<%= parameter.originalName %>': <%= parameter.name %>,
28
+ <% }); %>
29
+ },
30
+ <% } %>
31
+ <% if(it.headers && it.headers.length > 0) { %>
32
+ headers: {
33
+ <% it.headers.forEach((parameter) => { %>
34
+ <% if (parameter.value) { %>
35
+ '<%= parameter.originalName %>': '<%= parameter.value %>',
36
+ <% } else { %>
37
+ '<%= parameter.originalName %>': <%= parameter.name %>,
38
+ <% } %>
39
+ <% }); %>
40
+ },
41
+ <% } %>
42
+ ...$config,
43
+ });
44
+ },
@@ -0,0 +1,21 @@
1
+ /**
2
+ <% it.parameters.forEach((parameter) => { %>
3
+ * @param <%= parameter.name %> <%= parameter.optional ? '(optional)' : '' %> <%= parameter.name !== parameter.originalName ? `(API name: ${parameter.originalName})` : '' %>
4
+
5
+ <% }); -%>
6
+ * @param $config (optional) Additional configuration for TanStack Query
7
+ * @param $httpConfig (optional) Additional configuration for xior request (actually executes the request)
8
+ */
9
+ export function <%= it.rqOpName %>(<% it.parameters.forEach((parameter) => { %>
10
+ <%= parameter.name %>: <%~ parameter.type %> <%= parameter.optional ? ' | null | undefined' : '' %>,
11
+ <% }); %>
12
+ $config?: UndefinedInitialDataOptions<<%~ it.returnType %>, Error, <%~ it.returnType %>>,
13
+ $httpConfig?: XiorRequestConfig
14
+ ) {
15
+ return useQuery({
16
+ queryKey: ['<%= it.clientName %>', '<%= it.opKey %>', <% it.query.forEach((parameter) => { %><%= parameter.name %>, <% }); %>],
17
+ queryFn: () => <%= it.clientName %>Client.<%= it.name %>(<% it.parameters.forEach((parameter) => { %>
18
+ <%= parameter.name %>, <% }); %>$httpConfig).then(res => res.data),
19
+ ...$config
20
+ });
21
+ }