swaggie 1.9.0-dev.1 → 2.0.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/README.md +117 -31
- package/dist/browser.js +24 -5
- package/dist/cli.js +54 -7
- package/dist/gen/genMocks.js +453 -0
- package/dist/gen/genOperations.js +112 -20
- package/dist/gen/genTypes.js +6 -5
- package/dist/gen/header.js +0 -1
- package/dist/gen/index.js +14 -1
- package/dist/generated/bundledTemplates.js +17 -19
- package/dist/index.js +17 -1
- package/dist/swagger/operations.js +16 -7
- package/dist/swagger/typesExtractor.js +12 -11
- package/dist/types.d.ts +55 -5
- package/dist/utils/documentLoader.js +1 -3
- package/dist/utils/fileUtils.js +22 -0
- package/dist/utils/refResolver.js +9 -21
- package/dist/utils/templateEngine.js +18 -0
- package/dist/utils/templateManager.js +123 -14
- package/dist/utils/templateValidator.js +127 -0
- package/dist/utils/utils.js +19 -13
- package/package.json +5 -4
- package/templates/axios/operation.ejs +25 -21
- package/templates/fetch/operation.ejs +4 -0
- package/templates/ng1/operation.ejs +11 -3
- package/templates/ng2/baseClient.ejs +9 -49
- package/templates/ng2/client.ejs +3 -7
- package/templates/ng2/operation.ejs +34 -17
- package/templates/swr/baseClient.ejs +7 -0
- package/templates/swr/client.ejs +63 -0
- package/templates/swr/swrMutationOperation.ejs +32 -0
- package/templates/swr/swrOperation.ejs +18 -0
- package/templates/tsq/baseClient.ejs +1 -0
- package/templates/tsq/client.ejs +67 -0
- package/templates/tsq/mutationOperation.ejs +31 -0
- package/templates/tsq/queryOperation.ejs +19 -0
- package/templates/xior/operation.ejs +25 -21
- package/templates/swr-axios/barrel.ejs +0 -58
- package/templates/swr-axios/baseClient.ejs +0 -20
- package/templates/swr-axios/client.ejs +0 -21
- package/templates/swr-axios/operation.ejs +0 -40
- package/templates/swr-axios/swrOperation.ejs +0 -50
- package/templates/tsq-xior/barrel.ejs +0 -0
- package/templates/tsq-xior/baseClient.ejs +0 -14
- package/templates/tsq-xior/client.ejs +0 -22
- package/templates/tsq-xior/operation.ejs +0 -40
- package/templates/tsq-xior/queryOperation.ejs +0 -30
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import xior, { type XiorResponse, type XiorRequestConfig, encodeParams } from "xior";
|
|
2
|
-
import { QueryClient, type UseQueryOptions, useQuery } from '@tanstack/react-query';
|
|
3
|
-
|
|
4
|
-
export const queryClient = new QueryClient();
|
|
5
|
-
|
|
6
|
-
export const http = xior.create({
|
|
7
|
-
baseURL: '<%= it.baseUrl || '' %>',
|
|
8
|
-
paramsSerializer: (params: any) =>
|
|
9
|
-
encodeParams(params, true, null, {
|
|
10
|
-
allowDots: <%= it.allowDots %>,
|
|
11
|
-
arrayFormat: '<%= it.arrayFormat %>',
|
|
12
|
-
}),
|
|
13
|
-
});
|
|
14
|
-
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
<% } %>
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
<%~ it.jsDocs %>
|
|
2
|
-
|
|
3
|
-
<%= it.name %>(<% it.parameters.forEach((parameter) => { %>
|
|
4
|
-
<%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,
|
|
5
|
-
<% }); %>
|
|
6
|
-
$config?: XiorRequestConfig
|
|
7
|
-
): Promise<XiorResponse<<%~ it.returnType %>>> {
|
|
8
|
-
const url = `<%= it.url %>`;
|
|
9
|
-
|
|
10
|
-
return http.request<<%~ it.returnType %>>({
|
|
11
|
-
url: url,
|
|
12
|
-
method: '<%= it.method %>',
|
|
13
|
-
<% if(it.body) { %>
|
|
14
|
-
<% if(it.body.contentType === 'urlencoded') { %>
|
|
15
|
-
data: new URLSearchParams(<%= it.body.name %> as any),
|
|
16
|
-
<% } else { %>
|
|
17
|
-
data: <%= it.body.name %>,
|
|
18
|
-
<% } %>
|
|
19
|
-
<% } %>
|
|
20
|
-
<% if(it.query && it.query.length > 0) { %>
|
|
21
|
-
params: {
|
|
22
|
-
<% it.query.forEach((parameter) => { %>
|
|
23
|
-
'<%= parameter.originalName %>': <%= parameter.name %>,
|
|
24
|
-
<% }); %>
|
|
25
|
-
},
|
|
26
|
-
<% } %>
|
|
27
|
-
<% if(it.headers && it.headers.length > 0) { %>
|
|
28
|
-
headers: {
|
|
29
|
-
<% it.headers.forEach((parameter) => { %>
|
|
30
|
-
<% if (parameter.value) { %>
|
|
31
|
-
'<%= parameter.originalName %>': '<%= parameter.value %>',
|
|
32
|
-
<% } else { %>
|
|
33
|
-
'<%= parameter.originalName %>': <%= parameter.name %>,
|
|
34
|
-
<% } %>
|
|
35
|
-
<% }); %>
|
|
36
|
-
},
|
|
37
|
-
<% } %>
|
|
38
|
-
...$config,
|
|
39
|
-
});
|
|
40
|
-
},
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
<%
|
|
2
|
-
if (it.jsDocs) {
|
|
3
|
-
const additionalParams = ` * @param $config (optional) Additional configuration for TanStack Query
|
|
4
|
-
* @param $httpConfig (optional) Additional configuration for xior request (actually executes the request)`;
|
|
5
|
-
|
|
6
|
-
// Replace the closing */ with newline + additional params + closing */
|
|
7
|
-
const modifiedDocs = it.jsDocs.replace(/(\s*)\*\/\s*$/, `\n${additionalParams}\n */`);
|
|
8
|
-
-%>
|
|
9
|
-
<%~ modifiedDocs %>
|
|
10
|
-
<% } else { -%>
|
|
11
|
-
<%~ it.jsDocs %>
|
|
12
|
-
<% } %>
|
|
13
|
-
|
|
14
|
-
export function <%= it.rqOpName %><TData = <%~ it.returnType %>, TError = Error>(<% it.parameters.forEach((parameter) => { %>
|
|
15
|
-
<%= parameter.name %><%= parameter.skippable ? '?' : '' %>: <%~ parameter.type %> <%= parameter.optional ? (parameter.skippable ? '| null' : '| null | undefined') : '' %>,
|
|
16
|
-
<% }); %>
|
|
17
|
-
$config?: Omit<
|
|
18
|
-
UseQueryOptions<<%~ it.returnType %>, TError, TData>,
|
|
19
|
-
'queryKey' | 'queryFn'
|
|
20
|
-
>,
|
|
21
|
-
$httpConfig?: XiorRequestConfig
|
|
22
|
-
) {
|
|
23
|
-
return useQuery<<%~ it.returnType %>, TError, TData>({
|
|
24
|
-
queryKey: ['<%= it.clientName %>', '<%= it.opKey %>', <% it.parameters.forEach((parameter) => { %><%= parameter.name %>, <% }); %>],
|
|
25
|
-
queryFn: () => <%= it.clientName %>Client.<%= it.name %>(<% it.parameters.forEach((parameter) => { %>
|
|
26
|
-
<%= parameter.name %>, <% }); %>$httpConfig).then(res => res.data),
|
|
27
|
-
...$config
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
<%= it.rqOpName %>.queryKeys = ['<%= it.clientName %>', '<%= it.opKey %>'];
|