swagger-typescript-api 10.0.1 → 10.0.3
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/LICENSE +21 -21
- package/README.md +288 -262
- package/index.d.ts +11 -1
- package/index.js +2 -0
- package/package.json +119 -114
- package/src/components.js +3 -5
- package/src/config.js +6 -0
- package/src/constants.js +7 -0
- package/src/files.js +6 -6
- package/src/formatFileContent.js +13 -6
- package/src/index.js +8 -7
- package/src/logger.js +9 -0
- package/src/modelNames.js +1 -5
- package/src/modelTypes.js +7 -6
- package/src/output.js +22 -23
- package/src/render/utils/index.js +9 -1
- package/src/routes.js +4 -1
- package/src/schema.js +87 -64
- package/src/swagger.js +4 -1
- package/src/templates.js +46 -23
- package/src/translators/JavaScript.js +3 -14
- package/src/typeFormatters.js +81 -35
- package/src/utils/resolveName.js +1 -4
- package/templates/README.md +17 -13
- package/templates/base/README.md +7 -7
- package/templates/base/data-contract-jsdoc.ejs +32 -0
- package/templates/base/data-contracts.ejs +28 -0
- package/templates/base/enum-data-contract.ejs +15 -0
- package/templates/base/{http-client.eta → http-client.ejs} +2 -2
- package/templates/base/http-clients/{axios-http-client.eta → axios-http-client.ejs} +133 -145
- package/templates/base/http-clients/{fetch-http-client.eta → fetch-http-client.ejs} +222 -222
- package/templates/base/interface-data-contract.ejs +10 -0
- package/templates/base/object-field-jsdoc.ejs +28 -0
- package/templates/base/{route-docs.eta → route-docs.ejs} +30 -31
- package/templates/base/{route-name.eta → route-name.ejs} +42 -42
- package/templates/base/{route-type.eta → route-type.ejs} +21 -21
- package/templates/base/type-data-contract.ejs +15 -0
- package/templates/default/README.md +6 -6
- package/templates/default/{api.eta → api.ejs} +65 -65
- package/templates/default/{procedure-call.eta → procedure-call.ejs} +99 -99
- package/templates/default/{route-types.eta → route-types.ejs} +28 -28
- package/templates/modular/README.md +6 -6
- package/templates/modular/{api.eta → api.ejs} +28 -28
- package/templates/modular/{procedure-call.eta → procedure-call.ejs} +99 -99
- package/templates/modular/{route-types.eta → route-types.ejs} +18 -18
- package/CHANGELOG.md +0 -872
- package/templates/base/data-contracts.eta +0 -45
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
<%
|
|
2
|
-
const { route, utils, config } = it;
|
|
3
|
-
const { _, classNameCase, require } = utils;
|
|
4
|
-
const { query, payload, pathParams, headers } = route.request;
|
|
5
|
-
|
|
6
|
-
const routeDocs = includeFile("@base/route-docs", { config, route, utils });
|
|
7
|
-
const routeNamespace = classNameCase(route.routeName.usage);
|
|
8
|
-
|
|
9
|
-
%>
|
|
10
|
-
/**
|
|
11
|
-
<%~ routeDocs.description %>
|
|
12
|
-
|
|
13
|
-
<%~ routeDocs.lines %>
|
|
14
|
-
|
|
15
|
-
*/
|
|
16
|
-
export namespace <%~ routeNamespace %> {
|
|
17
|
-
export type RequestParams = <%~ (pathParams && pathParams.type) || '{}' %>;
|
|
18
|
-
export type RequestQuery = <%~ (query && query.type) || '{}' %>;
|
|
19
|
-
export type RequestBody = <%~ (payload && payload.type) || 'never' %>;
|
|
20
|
-
export type RequestHeaders = <%~ (headers && headers.type) || '{}' %>;
|
|
21
|
-
export type ResponseBody = <%~ route.response.type %>;
|
|
1
|
+
<%
|
|
2
|
+
const { route, utils, config } = it;
|
|
3
|
+
const { _, classNameCase, require } = utils;
|
|
4
|
+
const { query, payload, pathParams, headers } = route.request;
|
|
5
|
+
|
|
6
|
+
const routeDocs = includeFile("@base/route-docs", { config, route, utils });
|
|
7
|
+
const routeNamespace = classNameCase(route.routeName.usage);
|
|
8
|
+
|
|
9
|
+
%>
|
|
10
|
+
/**
|
|
11
|
+
<%~ routeDocs.description %>
|
|
12
|
+
|
|
13
|
+
<%~ routeDocs.lines %>
|
|
14
|
+
|
|
15
|
+
*/
|
|
16
|
+
export namespace <%~ routeNamespace %> {
|
|
17
|
+
export type RequestParams = <%~ (pathParams && pathParams.type) || '{}' %>;
|
|
18
|
+
export type RequestQuery = <%~ (query && query.type) || '{}' %>;
|
|
19
|
+
export type RequestBody = <%~ (payload && payload.type) || 'never' %>;
|
|
20
|
+
export type RequestHeaders = <%~ (headers && headers.type) || '{}' %>;
|
|
21
|
+
export type ResponseBody = <%~ route.response.type %>;
|
|
22
22
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<%
|
|
2
|
+
const { contract, utils } = it;
|
|
3
|
+
const { formatDescription, require, _ } = utils;
|
|
4
|
+
|
|
5
|
+
%>
|
|
6
|
+
<% if (contract.$content.length) { %>
|
|
7
|
+
export type <%~ contract.name %> = {
|
|
8
|
+
<% _.forEach(contract.$content, (field) => { %>
|
|
9
|
+
<%~ includeFile('@base/object-field-jsdoc.ejs', { ...it, field }) %>
|
|
10
|
+
<%~ field.field %>;
|
|
11
|
+
<% }) %>
|
|
12
|
+
}<%~ utils.isNeedToAddNull(contract) ? ' | null' : ''%>
|
|
13
|
+
<% } else { %>
|
|
14
|
+
export type <%~ contract.name %> = Record<string, any>;
|
|
15
|
+
<% } %>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# swagger-typescript-api
|
|
2
|
-
|
|
3
|
-
# templates/default
|
|
4
|
-
|
|
5
|
-
This templates use for single api file (without `--modular` option)
|
|
6
|
-
|
|
1
|
+
# swagger-typescript-api
|
|
2
|
+
|
|
3
|
+
# templates/default
|
|
4
|
+
|
|
5
|
+
This templates use for single api file (without `--modular` option)
|
|
6
|
+
|
|
7
7
|
path prefix `@default`
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
<%
|
|
2
|
-
const { apiConfig, routes, utils, config } = it;
|
|
3
|
-
const { info, servers, externalDocs } = apiConfig;
|
|
4
|
-
const { _, require, formatDescription } = utils;
|
|
5
|
-
|
|
6
|
-
const server = (servers && servers[0]) || { url: "" };
|
|
7
|
-
|
|
8
|
-
const descriptionLines = _.compact([
|
|
9
|
-
`@title ${info.title || "No title"}`,
|
|
10
|
-
info.version && `@version ${info.version}`,
|
|
11
|
-
info.license && `@license ${_.compact([
|
|
12
|
-
info.license.name,
|
|
13
|
-
info.license.url && `(${info.license.url})`,
|
|
14
|
-
]).join(" ")}`,
|
|
15
|
-
info.termsOfService && `@termsOfService ${info.termsOfService}`,
|
|
16
|
-
server.url && `@baseUrl ${server.url}`,
|
|
17
|
-
externalDocs.url && `@externalDocs ${externalDocs.url}`,
|
|
18
|
-
info.contact && `@contact ${_.compact([
|
|
19
|
-
info.contact.name,
|
|
20
|
-
info.contact.email && `<${info.contact.email}>`,
|
|
21
|
-
info.contact.url && `(${info.contact.url})`,
|
|
22
|
-
]).join(" ")}`,
|
|
23
|
-
info.description && " ",
|
|
24
|
-
info.description && _.replace(formatDescription(info.description), /\n/g, "\n * "),
|
|
25
|
-
]);
|
|
26
|
-
|
|
27
|
-
%>
|
|
28
|
-
|
|
29
|
-
<% if (config.httpClientType === config.constants.HTTP_CLIENT.AXIOS) { %> import { AxiosRequestConfig, AxiosResponse } from "axios"; <% } %>
|
|
30
|
-
|
|
31
|
-
<% if (descriptionLines.length) { %>
|
|
32
|
-
/**
|
|
33
|
-
<% descriptionLines.forEach((descriptionLine) => { %>
|
|
34
|
-
* <%~ descriptionLine %>
|
|
35
|
-
|
|
36
|
-
<% }) %>
|
|
37
|
-
*/
|
|
38
|
-
<% } %>
|
|
39
|
-
export class <%~ config.apiClassName %><SecurityDataType extends unknown><% if (!config.singleHttpClient) { %> extends HttpClient<SecurityDataType> <% } %> {
|
|
40
|
-
|
|
41
|
-
<% if(config.singleHttpClient) { %>
|
|
42
|
-
http: HttpClient<SecurityDataType>;
|
|
43
|
-
|
|
44
|
-
constructor (http: HttpClient<SecurityDataType>) {
|
|
45
|
-
this.http = http;
|
|
46
|
-
}
|
|
47
|
-
<% } %>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
<% routes.outOfModule && routes.outOfModule.forEach((route) => { %>
|
|
51
|
-
|
|
52
|
-
<%~ includeFile('./procedure-call.
|
|
53
|
-
|
|
54
|
-
<% }) %>
|
|
55
|
-
|
|
56
|
-
<% routes.combined && routes.combined.forEach(({ routes = [], moduleName }) => { %>
|
|
57
|
-
<%~ moduleName %> = {
|
|
58
|
-
<% routes.forEach((route) => { %>
|
|
59
|
-
|
|
60
|
-
<%~ includeFile('./procedure-call.
|
|
61
|
-
|
|
62
|
-
<% }) %>
|
|
63
|
-
}
|
|
64
|
-
<% }) %>
|
|
65
|
-
}
|
|
1
|
+
<%
|
|
2
|
+
const { apiConfig, routes, utils, config } = it;
|
|
3
|
+
const { info, servers, externalDocs } = apiConfig;
|
|
4
|
+
const { _, require, formatDescription } = utils;
|
|
5
|
+
|
|
6
|
+
const server = (servers && servers[0]) || { url: "" };
|
|
7
|
+
|
|
8
|
+
const descriptionLines = _.compact([
|
|
9
|
+
`@title ${info.title || "No title"}`,
|
|
10
|
+
info.version && `@version ${info.version}`,
|
|
11
|
+
info.license && `@license ${_.compact([
|
|
12
|
+
info.license.name,
|
|
13
|
+
info.license.url && `(${info.license.url})`,
|
|
14
|
+
]).join(" ")}`,
|
|
15
|
+
info.termsOfService && `@termsOfService ${info.termsOfService}`,
|
|
16
|
+
server.url && `@baseUrl ${server.url}`,
|
|
17
|
+
externalDocs.url && `@externalDocs ${externalDocs.url}`,
|
|
18
|
+
info.contact && `@contact ${_.compact([
|
|
19
|
+
info.contact.name,
|
|
20
|
+
info.contact.email && `<${info.contact.email}>`,
|
|
21
|
+
info.contact.url && `(${info.contact.url})`,
|
|
22
|
+
]).join(" ")}`,
|
|
23
|
+
info.description && " ",
|
|
24
|
+
info.description && _.replace(formatDescription(info.description), /\n/g, "\n * "),
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
%>
|
|
28
|
+
|
|
29
|
+
<% if (config.httpClientType === config.constants.HTTP_CLIENT.AXIOS) { %> import { AxiosRequestConfig, AxiosResponse } from "axios"; <% } %>
|
|
30
|
+
|
|
31
|
+
<% if (descriptionLines.length) { %>
|
|
32
|
+
/**
|
|
33
|
+
<% descriptionLines.forEach((descriptionLine) => { %>
|
|
34
|
+
* <%~ descriptionLine %>
|
|
35
|
+
|
|
36
|
+
<% }) %>
|
|
37
|
+
*/
|
|
38
|
+
<% } %>
|
|
39
|
+
export class <%~ config.apiClassName %><SecurityDataType extends unknown><% if (!config.singleHttpClient) { %> extends HttpClient<SecurityDataType> <% } %> {
|
|
40
|
+
|
|
41
|
+
<% if(config.singleHttpClient) { %>
|
|
42
|
+
http: HttpClient<SecurityDataType>;
|
|
43
|
+
|
|
44
|
+
constructor (http: HttpClient<SecurityDataType>) {
|
|
45
|
+
this.http = http;
|
|
46
|
+
}
|
|
47
|
+
<% } %>
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
<% routes.outOfModule && routes.outOfModule.forEach((route) => { %>
|
|
51
|
+
|
|
52
|
+
<%~ includeFile('./procedure-call.ejs', { ...it, route }) %>
|
|
53
|
+
|
|
54
|
+
<% }) %>
|
|
55
|
+
|
|
56
|
+
<% routes.combined && routes.combined.forEach(({ routes = [], moduleName }) => { %>
|
|
57
|
+
<%~ moduleName %> = {
|
|
58
|
+
<% routes.forEach((route) => { %>
|
|
59
|
+
|
|
60
|
+
<%~ includeFile('./procedure-call.ejs', { ...it, route }) %>
|
|
61
|
+
|
|
62
|
+
<% }) %>
|
|
63
|
+
}
|
|
64
|
+
<% }) %>
|
|
65
|
+
}
|
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
<%
|
|
2
|
-
const { utils, route, config } = it;
|
|
3
|
-
const { requestBodyInfo, responseBodyInfo, specificArgNameResolver } = route;
|
|
4
|
-
const { _, getInlineParseContent, getParseContent, parseSchema, getComponentByRef, require } = utils;
|
|
5
|
-
const { parameters, path, method, payload, query, formData, security, requestParams } = route.request;
|
|
6
|
-
const { type, errorType, contentTypes } = route.response;
|
|
7
|
-
const { HTTP_CLIENT, RESERVED_REQ_PARAMS_ARG_NAMES } = config.constants;
|
|
8
|
-
const routeDocs = includeFile("@base/route-docs", { config, route, utils });
|
|
9
|
-
const queryName = (query && query.name) || "query";
|
|
10
|
-
const pathParams = _.values(parameters);
|
|
11
|
-
const pathParamsNames = _.map(pathParams, "name");
|
|
12
|
-
|
|
13
|
-
const isFetchTemplate = config.httpClientType === HTTP_CLIENT.FETCH;
|
|
14
|
-
|
|
15
|
-
const requestConfigParam = {
|
|
16
|
-
name: specificArgNameResolver.resolve(RESERVED_REQ_PARAMS_ARG_NAMES),
|
|
17
|
-
optional: true,
|
|
18
|
-
type: "RequestParams",
|
|
19
|
-
defaultValue: "{}",
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const argToTmpl = ({ name, optional, type, defaultValue }) => `${name}${!defaultValue && optional ? '?' : ''}: ${type}${defaultValue ? ` = ${defaultValue}` : ''}`;
|
|
23
|
-
|
|
24
|
-
const rawWrapperArgs = config.extractRequestParams ?
|
|
25
|
-
_.compact([
|
|
26
|
-
requestParams && {
|
|
27
|
-
name: pathParams.length ? `{ ${_.join(pathParamsNames, ", ")}, ...${queryName} }` : queryName,
|
|
28
|
-
optional: false,
|
|
29
|
-
type: getInlineParseContent(requestParams),
|
|
30
|
-
},
|
|
31
|
-
...(!requestParams ? pathParams : []),
|
|
32
|
-
payload,
|
|
33
|
-
requestConfigParam,
|
|
34
|
-
]) :
|
|
35
|
-
_.compact([
|
|
36
|
-
...pathParams,
|
|
37
|
-
query,
|
|
38
|
-
payload,
|
|
39
|
-
requestConfigParam,
|
|
40
|
-
])
|
|
41
|
-
|
|
42
|
-
const wrapperArgs = _
|
|
43
|
-
// Sort by optionality
|
|
44
|
-
.sortBy(rawWrapperArgs, [o => o.optional])
|
|
45
|
-
.map(argToTmpl)
|
|
46
|
-
.join(', ')
|
|
47
|
-
|
|
48
|
-
// RequestParams["type"]
|
|
49
|
-
const requestContentKind = {
|
|
50
|
-
"JSON": "ContentType.Json",
|
|
51
|
-
"URL_ENCODED": "ContentType.UrlEncoded",
|
|
52
|
-
"FORM_DATA": "ContentType.FormData",
|
|
53
|
-
}
|
|
54
|
-
// RequestParams["format"]
|
|
55
|
-
const responseContentKind = {
|
|
56
|
-
"JSON": '"json"',
|
|
57
|
-
"IMAGE": '"blob"',
|
|
58
|
-
"FORM_DATA": isFetchTemplate ? '"formData"' : '"document"'
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const bodyTmpl = _.get(payload, "name") || null;
|
|
62
|
-
const queryTmpl = (query != null && queryName) || null;
|
|
63
|
-
const bodyContentKindTmpl = requestContentKind[requestBodyInfo.contentKind] || null;
|
|
64
|
-
const responseFormatTmpl = responseContentKind[responseBodyInfo.success && responseBodyInfo.success.schema && responseBodyInfo.success.schema.contentKind] || null;
|
|
65
|
-
const securityTmpl = security ? 'true' : null;
|
|
66
|
-
|
|
67
|
-
const describeReturnType = () => {
|
|
68
|
-
if (!config.toJS) return "";
|
|
69
|
-
|
|
70
|
-
switch(config.httpClientType) {
|
|
71
|
-
case HTTP_CLIENT.AXIOS: {
|
|
72
|
-
return `Promise<AxiosResponse<${type}>>`
|
|
73
|
-
}
|
|
74
|
-
default: {
|
|
75
|
-
return `Promise<HttpResponse<${type}, ${errorType}>`
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
%>
|
|
81
|
-
/**
|
|
82
|
-
<%~ routeDocs.description %>
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
<%~ routeDocs.lines %>
|
|
87
|
-
|
|
88
|
-
*/
|
|
89
|
-
<%~ route.routeName.usage %><%~ route.namespace ? ': ' : ' = ' %>(<%~ wrapperArgs %>)<%~ config.toJS ? `: ${describeReturnType()}` : "" %> =>
|
|
90
|
-
<%~ config.singleHttpClient ? 'this.http.request' : 'this.request' %><<%~ type %>, <%~ errorType %>>({
|
|
91
|
-
path: `<%~ path %>`,
|
|
92
|
-
method: '<%~ _.upperCase(method) %>',
|
|
93
|
-
<%~ queryTmpl ? `query: ${queryTmpl},` : '' %>
|
|
94
|
-
<%~ bodyTmpl ? `body: ${bodyTmpl},` : '' %>
|
|
95
|
-
<%~ securityTmpl ? `secure: ${securityTmpl},` : '' %>
|
|
96
|
-
<%~ bodyContentKindTmpl ? `type: ${bodyContentKindTmpl},` : '' %>
|
|
97
|
-
<%~ responseFormatTmpl ? `format: ${responseFormatTmpl},` : '' %>
|
|
98
|
-
...<%~ _.get(requestConfigParam, "name") %>,
|
|
99
|
-
})<%~ route.namespace ? ',' : '' %>
|
|
1
|
+
<%
|
|
2
|
+
const { utils, route, config } = it;
|
|
3
|
+
const { requestBodyInfo, responseBodyInfo, specificArgNameResolver } = route;
|
|
4
|
+
const { _, getInlineParseContent, getParseContent, parseSchema, getComponentByRef, require } = utils;
|
|
5
|
+
const { parameters, path, method, payload, query, formData, security, requestParams } = route.request;
|
|
6
|
+
const { type, errorType, contentTypes } = route.response;
|
|
7
|
+
const { HTTP_CLIENT, RESERVED_REQ_PARAMS_ARG_NAMES } = config.constants;
|
|
8
|
+
const routeDocs = includeFile("@base/route-docs", { config, route, utils });
|
|
9
|
+
const queryName = (query && query.name) || "query";
|
|
10
|
+
const pathParams = _.values(parameters);
|
|
11
|
+
const pathParamsNames = _.map(pathParams, "name");
|
|
12
|
+
|
|
13
|
+
const isFetchTemplate = config.httpClientType === HTTP_CLIENT.FETCH;
|
|
14
|
+
|
|
15
|
+
const requestConfigParam = {
|
|
16
|
+
name: specificArgNameResolver.resolve(RESERVED_REQ_PARAMS_ARG_NAMES),
|
|
17
|
+
optional: true,
|
|
18
|
+
type: "RequestParams",
|
|
19
|
+
defaultValue: "{}",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const argToTmpl = ({ name, optional, type, defaultValue }) => `${name}${!defaultValue && optional ? '?' : ''}: ${type}${defaultValue ? ` = ${defaultValue}` : ''}`;
|
|
23
|
+
|
|
24
|
+
const rawWrapperArgs = config.extractRequestParams ?
|
|
25
|
+
_.compact([
|
|
26
|
+
requestParams && {
|
|
27
|
+
name: pathParams.length ? `{ ${_.join(pathParamsNames, ", ")}, ...${queryName} }` : queryName,
|
|
28
|
+
optional: false,
|
|
29
|
+
type: getInlineParseContent(requestParams),
|
|
30
|
+
},
|
|
31
|
+
...(!requestParams ? pathParams : []),
|
|
32
|
+
payload,
|
|
33
|
+
requestConfigParam,
|
|
34
|
+
]) :
|
|
35
|
+
_.compact([
|
|
36
|
+
...pathParams,
|
|
37
|
+
query,
|
|
38
|
+
payload,
|
|
39
|
+
requestConfigParam,
|
|
40
|
+
])
|
|
41
|
+
|
|
42
|
+
const wrapperArgs = _
|
|
43
|
+
// Sort by optionality
|
|
44
|
+
.sortBy(rawWrapperArgs, [o => o.optional])
|
|
45
|
+
.map(argToTmpl)
|
|
46
|
+
.join(', ')
|
|
47
|
+
|
|
48
|
+
// RequestParams["type"]
|
|
49
|
+
const requestContentKind = {
|
|
50
|
+
"JSON": "ContentType.Json",
|
|
51
|
+
"URL_ENCODED": "ContentType.UrlEncoded",
|
|
52
|
+
"FORM_DATA": "ContentType.FormData",
|
|
53
|
+
}
|
|
54
|
+
// RequestParams["format"]
|
|
55
|
+
const responseContentKind = {
|
|
56
|
+
"JSON": '"json"',
|
|
57
|
+
"IMAGE": '"blob"',
|
|
58
|
+
"FORM_DATA": isFetchTemplate ? '"formData"' : '"document"'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const bodyTmpl = _.get(payload, "name") || null;
|
|
62
|
+
const queryTmpl = (query != null && queryName) || null;
|
|
63
|
+
const bodyContentKindTmpl = requestContentKind[requestBodyInfo.contentKind] || null;
|
|
64
|
+
const responseFormatTmpl = responseContentKind[responseBodyInfo.success && responseBodyInfo.success.schema && responseBodyInfo.success.schema.contentKind] || null;
|
|
65
|
+
const securityTmpl = security ? 'true' : null;
|
|
66
|
+
|
|
67
|
+
const describeReturnType = () => {
|
|
68
|
+
if (!config.toJS) return "";
|
|
69
|
+
|
|
70
|
+
switch(config.httpClientType) {
|
|
71
|
+
case HTTP_CLIENT.AXIOS: {
|
|
72
|
+
return `Promise<AxiosResponse<${type}>>`
|
|
73
|
+
}
|
|
74
|
+
default: {
|
|
75
|
+
return `Promise<HttpResponse<${type}, ${errorType}>`
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
%>
|
|
81
|
+
/**
|
|
82
|
+
<%~ routeDocs.description %>
|
|
83
|
+
|
|
84
|
+
*<% /* Here you can add some other JSDoc tags */ %>
|
|
85
|
+
|
|
86
|
+
<%~ routeDocs.lines %>
|
|
87
|
+
|
|
88
|
+
*/
|
|
89
|
+
<%~ route.routeName.usage %><%~ route.namespace ? ': ' : ' = ' %>(<%~ wrapperArgs %>)<%~ config.toJS ? `: ${describeReturnType()}` : "" %> =>
|
|
90
|
+
<%~ config.singleHttpClient ? 'this.http.request' : 'this.request' %><<%~ type %>, <%~ errorType %>>({
|
|
91
|
+
path: `<%~ path %>`,
|
|
92
|
+
method: '<%~ _.upperCase(method) %>',
|
|
93
|
+
<%~ queryTmpl ? `query: ${queryTmpl},` : '' %>
|
|
94
|
+
<%~ bodyTmpl ? `body: ${bodyTmpl},` : '' %>
|
|
95
|
+
<%~ securityTmpl ? `secure: ${securityTmpl},` : '' %>
|
|
96
|
+
<%~ bodyContentKindTmpl ? `type: ${bodyContentKindTmpl},` : '' %>
|
|
97
|
+
<%~ responseFormatTmpl ? `format: ${responseFormatTmpl},` : '' %>
|
|
98
|
+
...<%~ _.get(requestConfigParam, "name") %>,
|
|
99
|
+
})<%~ route.namespace ? ',' : '' %>
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
<%
|
|
2
|
-
const { utils, config, routes, modelTypes } = it;
|
|
3
|
-
const { _, classNameCase } = utils;
|
|
4
|
-
const dataContracts = config.modular ? _.map(modelTypes, "name") : [];
|
|
5
|
-
%>
|
|
6
|
-
|
|
7
|
-
<% if (dataContracts.length) { %>
|
|
8
|
-
import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %>"
|
|
9
|
-
<% } %>
|
|
10
|
-
|
|
11
|
-
<%
|
|
12
|
-
/* TODO: outOfModule, combined should be attributes of route, which will allow to avoid duplication of code */
|
|
13
|
-
%>
|
|
14
|
-
|
|
15
|
-
<% routes.outOfModule && routes.outOfModule.forEach(({ routes = [] }) => { %>
|
|
16
|
-
<% routes.forEach((route) => { %>
|
|
17
|
-
<%~ includeFile('@base/route-type.
|
|
18
|
-
<% }) %>
|
|
19
|
-
<% }) %>
|
|
20
|
-
|
|
21
|
-
<% routes.combined && routes.combined.forEach(({ routes = [], moduleName }) => { %>
|
|
22
|
-
export namespace <%~ classNameCase(moduleName) %> {
|
|
23
|
-
<% routes.forEach((route) => { %>
|
|
24
|
-
<%~ includeFile('@base/route-type.
|
|
25
|
-
<% }) %>
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
<% }) %>
|
|
1
|
+
<%
|
|
2
|
+
const { utils, config, routes, modelTypes } = it;
|
|
3
|
+
const { _, classNameCase } = utils;
|
|
4
|
+
const dataContracts = config.modular ? _.map(modelTypes, "name") : [];
|
|
5
|
+
%>
|
|
6
|
+
|
|
7
|
+
<% if (dataContracts.length) { %>
|
|
8
|
+
import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %>"
|
|
9
|
+
<% } %>
|
|
10
|
+
|
|
11
|
+
<%
|
|
12
|
+
/* TODO: outOfModule, combined should be attributes of route, which will allow to avoid duplication of code */
|
|
13
|
+
%>
|
|
14
|
+
|
|
15
|
+
<% routes.outOfModule && routes.outOfModule.forEach(({ routes = [] }) => { %>
|
|
16
|
+
<% routes.forEach((route) => { %>
|
|
17
|
+
<%~ includeFile('@base/route-type.ejs', { ...it, route }) %>
|
|
18
|
+
<% }) %>
|
|
19
|
+
<% }) %>
|
|
20
|
+
|
|
21
|
+
<% routes.combined && routes.combined.forEach(({ routes = [], moduleName }) => { %>
|
|
22
|
+
export namespace <%~ classNameCase(moduleName) %> {
|
|
23
|
+
<% routes.forEach((route) => { %>
|
|
24
|
+
<%~ includeFile('@base/route-type.ejs', { ...it, route }) %>
|
|
25
|
+
<% }) %>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
<% }) %>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# swagger-typescript-api
|
|
2
|
-
|
|
3
|
-
# templates/modular
|
|
4
|
-
|
|
5
|
-
This templates use for multiple api files (`--modular` option)
|
|
6
|
-
|
|
1
|
+
# swagger-typescript-api
|
|
2
|
+
|
|
3
|
+
# templates/modular
|
|
4
|
+
|
|
5
|
+
This templates use for multiple api files (`--modular` option)
|
|
6
|
+
|
|
7
7
|
path prefix `@modular`
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
<%
|
|
2
|
-
const { utils, route, config, modelTypes } = it;
|
|
3
|
-
const { _, classNameCase, require } = utils;
|
|
4
|
-
const apiClassName = classNameCase(route.moduleName);
|
|
5
|
-
const routes = route.routes;
|
|
6
|
-
const dataContracts = _.map(modelTypes, "name");
|
|
7
|
-
%>
|
|
8
|
-
|
|
9
|
-
<% if (config.httpClientType === config.constants.HTTP_CLIENT.AXIOS) { %> import { AxiosRequestConfig, AxiosResponse } from "axios"; <% } %>
|
|
10
|
-
|
|
11
|
-
import { HttpClient, RequestParams, ContentType, HttpResponse } from "./<%~ config.fileNames.httpClient %>";
|
|
12
|
-
<% if (dataContracts.length) { %>
|
|
13
|
-
import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %>"
|
|
14
|
-
<% } %>
|
|
15
|
-
|
|
16
|
-
export class <%= apiClassName %><SecurityDataType = unknown><% if (!config.singleHttpClient) { %> extends HttpClient<SecurityDataType> <% } %> {
|
|
17
|
-
<% if(config.singleHttpClient) { %>
|
|
18
|
-
http: HttpClient<SecurityDataType>;
|
|
19
|
-
|
|
20
|
-
constructor (http: HttpClient<SecurityDataType>) {
|
|
21
|
-
this.http = http;
|
|
22
|
-
}
|
|
23
|
-
<% } %>
|
|
24
|
-
|
|
25
|
-
<% routes.forEach((route) => { %>
|
|
26
|
-
<%~ includeFile('./procedure-call.
|
|
27
|
-
<% }) %>
|
|
28
|
-
}
|
|
1
|
+
<%
|
|
2
|
+
const { utils, route, config, modelTypes } = it;
|
|
3
|
+
const { _, classNameCase, require } = utils;
|
|
4
|
+
const apiClassName = classNameCase(route.moduleName);
|
|
5
|
+
const routes = route.routes;
|
|
6
|
+
const dataContracts = _.map(modelTypes, "name");
|
|
7
|
+
%>
|
|
8
|
+
|
|
9
|
+
<% if (config.httpClientType === config.constants.HTTP_CLIENT.AXIOS) { %> import { AxiosRequestConfig, AxiosResponse } from "axios"; <% } %>
|
|
10
|
+
|
|
11
|
+
import { HttpClient, RequestParams, ContentType, HttpResponse } from "./<%~ config.fileNames.httpClient %>";
|
|
12
|
+
<% if (dataContracts.length) { %>
|
|
13
|
+
import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %>"
|
|
14
|
+
<% } %>
|
|
15
|
+
|
|
16
|
+
export class <%= apiClassName %><SecurityDataType = unknown><% if (!config.singleHttpClient) { %> extends HttpClient<SecurityDataType> <% } %> {
|
|
17
|
+
<% if(config.singleHttpClient) { %>
|
|
18
|
+
http: HttpClient<SecurityDataType>;
|
|
19
|
+
|
|
20
|
+
constructor (http: HttpClient<SecurityDataType>) {
|
|
21
|
+
this.http = http;
|
|
22
|
+
}
|
|
23
|
+
<% } %>
|
|
24
|
+
|
|
25
|
+
<% routes.forEach((route) => { %>
|
|
26
|
+
<%~ includeFile('./procedure-call.ejs', { ...it, route }) %>
|
|
27
|
+
<% }) %>
|
|
28
|
+
}
|