swagger-typescript-api 12.0.4 → 13.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.
Files changed (75) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1 -1
  3. package/cli/constants.js +3 -3
  4. package/cli/execute.js +52 -31
  5. package/cli/index.d.ts +1 -2
  6. package/cli/index.js +18 -17
  7. package/cli/operations/display-help.js +51 -29
  8. package/cli/parse-args.js +3 -3
  9. package/cli/process-option.js +28 -20
  10. package/index.d.ts +99 -7
  11. package/index.js +158 -136
  12. package/package.json +35 -30
  13. package/src/code-formatter.js +28 -13
  14. package/src/code-gen-process.js +367 -264
  15. package/src/commands/generate-templates/configuration.js +2 -2
  16. package/src/commands/generate-templates/index.js +1 -2
  17. package/src/commands/generate-templates/templates-gen-process.js +62 -35
  18. package/src/component-type-name-resolver.js +44 -0
  19. package/src/configuration.js +166 -98
  20. package/src/constants.js +28 -22
  21. package/src/index.js +3 -4
  22. package/src/schema-components-map.js +39 -23
  23. package/src/schema-parser/base-schema-parsers/array.js +43 -0
  24. package/src/schema-parser/base-schema-parsers/complex.js +51 -0
  25. package/src/schema-parser/base-schema-parsers/discriminator.js +301 -0
  26. package/src/schema-parser/base-schema-parsers/enum.js +158 -0
  27. package/src/schema-parser/base-schema-parsers/object.js +105 -0
  28. package/src/schema-parser/base-schema-parsers/primitive.js +63 -0
  29. package/src/schema-parser/complex-schema-parsers/all-of.js +26 -0
  30. package/src/schema-parser/complex-schema-parsers/any-of.js +34 -0
  31. package/src/schema-parser/complex-schema-parsers/not.js +9 -0
  32. package/src/schema-parser/complex-schema-parsers/one-of.js +27 -0
  33. package/src/schema-parser/mono-schema-parser.js +48 -0
  34. package/src/schema-parser/schema-formatters.js +58 -44
  35. package/src/schema-parser/schema-parser-fabric.js +131 -0
  36. package/src/schema-parser/schema-parser.js +212 -361
  37. package/src/schema-parser/schema-utils.js +158 -33
  38. package/src/schema-parser/util/enum-key-resolver.js +26 -0
  39. package/src/{schema-parser → schema-routes}/schema-routes.js +472 -203
  40. package/src/schema-routes/util/specific-arg-name-resolver.js +26 -0
  41. package/src/schema-walker.js +93 -0
  42. package/src/swagger-schema-resolver.js +61 -28
  43. package/src/templates-worker.js +240 -0
  44. package/src/translators/javascript.js +83 -0
  45. package/src/translators/translator.js +35 -0
  46. package/src/{type-name.js → type-name-formatter.js} +35 -20
  47. package/src/util/file-system.js +30 -14
  48. package/src/util/id.js +2 -2
  49. package/src/util/internal-case.js +1 -1
  50. package/src/util/logger.js +46 -20
  51. package/src/util/name-resolver.js +50 -58
  52. package/src/util/object-assign.js +7 -3
  53. package/src/util/pascal-case.js +1 -1
  54. package/src/util/request.js +5 -5
  55. package/src/util/sort-by-property.js +17 -0
  56. package/templates/base/data-contract-jsdoc.ejs +37 -37
  57. package/templates/base/data-contracts.ejs +40 -28
  58. package/templates/base/enum-data-contract.ejs +12 -12
  59. package/templates/base/http-client.ejs +2 -2
  60. package/templates/base/http-clients/axios-http-client.ejs +139 -138
  61. package/templates/base/http-clients/fetch-http-client.ejs +224 -224
  62. package/templates/base/interface-data-contract.ejs +10 -10
  63. package/templates/base/object-field-jsdoc.ejs +28 -28
  64. package/templates/base/route-docs.ejs +30 -30
  65. package/templates/base/route-name.ejs +42 -42
  66. package/templates/base/route-type.ejs +22 -21
  67. package/templates/base/type-data-contract.ejs +15 -15
  68. package/templates/default/api.ejs +69 -65
  69. package/templates/default/procedure-call.ejs +100 -100
  70. package/templates/default/route-types.ejs +32 -28
  71. package/templates/modular/api.ejs +28 -28
  72. package/templates/modular/procedure-call.ejs +100 -100
  73. package/templates/modular/route-types.ejs +18 -18
  74. package/src/templates.js +0 -177
  75. package/src/translators/JavaScript.js +0 -60
@@ -1,43 +1,43 @@
1
- <%
2
- const { routeInfo, utils } = it;
3
- const {
4
- operationId,
5
- method,
6
- route,
7
- moduleName,
8
- responsesTypes,
9
- description,
10
- tags,
11
- summary,
12
- pathArgs,
13
- } = routeInfo;
14
- const { _, fmtToJSDocLine, require } = utils;
15
-
16
- const methodAliases = {
17
- get: (pathName, hasPathInserts) =>
18
- _.camelCase(`${pathName}_${hasPathInserts ? "detail" : "list"}`),
19
- post: (pathName, hasPathInserts) => _.camelCase(`${pathName}_create`),
20
- put: (pathName, hasPathInserts) => _.camelCase(`${pathName}_update`),
21
- patch: (pathName, hasPathInserts) => _.camelCase(`${pathName}_partial_update`),
22
- delete: (pathName, hasPathInserts) => _.camelCase(`${pathName}_delete`),
23
- };
24
-
25
- const createCustomOperationId = (method, route, moduleName) => {
26
- const hasPathInserts = /\{(\w){1,}\}/g.test(route);
27
- const splitedRouteBySlash = _.compact(_.replace(route, /\{(\w){1,}\}/g, "").split("/"));
28
- const routeParts = (splitedRouteBySlash.length > 1
29
- ? splitedRouteBySlash.splice(1)
30
- : splitedRouteBySlash
31
- ).join("_");
32
- return routeParts.length > 3 && methodAliases[method]
33
- ? methodAliases[method](routeParts, hasPathInserts)
34
- : _.camelCase(_.lowerCase(method) + "_" + [moduleName].join("_")) || "index";
35
- };
36
-
37
- if (operationId)
38
- return _.camelCase(operationId);
39
- if (route === "/")
40
- return _.camelCase(`${_.lowerCase(method)}Root`);
41
-
42
- return createCustomOperationId(method, route, moduleName);
1
+ <%
2
+ const { routeInfo, utils } = it;
3
+ const {
4
+ operationId,
5
+ method,
6
+ route,
7
+ moduleName,
8
+ responsesTypes,
9
+ description,
10
+ tags,
11
+ summary,
12
+ pathArgs,
13
+ } = routeInfo;
14
+ const { _, fmtToJSDocLine, require } = utils;
15
+
16
+ const methodAliases = {
17
+ get: (pathName, hasPathInserts) =>
18
+ _.camelCase(`${pathName}_${hasPathInserts ? "detail" : "list"}`),
19
+ post: (pathName, hasPathInserts) => _.camelCase(`${pathName}_create`),
20
+ put: (pathName, hasPathInserts) => _.camelCase(`${pathName}_update`),
21
+ patch: (pathName, hasPathInserts) => _.camelCase(`${pathName}_partial_update`),
22
+ delete: (pathName, hasPathInserts) => _.camelCase(`${pathName}_delete`),
23
+ };
24
+
25
+ const createCustomOperationId = (method, route, moduleName) => {
26
+ const hasPathInserts = /\{(\w){1,}\}/g.test(route);
27
+ const splitedRouteBySlash = _.compact(_.replace(route, /\{(\w){1,}\}/g, "").split("/"));
28
+ const routeParts = (splitedRouteBySlash.length > 1
29
+ ? splitedRouteBySlash.splice(1)
30
+ : splitedRouteBySlash
31
+ ).join("_");
32
+ return routeParts.length > 3 && methodAliases[method]
33
+ ? methodAliases[method](routeParts, hasPathInserts)
34
+ : _.camelCase(_.lowerCase(method) + "_" + [moduleName].join("_")) || "index";
35
+ };
36
+
37
+ if (operationId)
38
+ return _.camelCase(operationId);
39
+ if (route === "/")
40
+ return _.camelCase(`${_.lowerCase(method)}Root`);
41
+
42
+ return createCustomOperationId(method, route, moduleName);
43
43
  %>
@@ -1,22 +1,23 @@
1
- <%
2
- const { route, utils, config } = it;
3
- const { _, pascalCase, require } = utils;
4
- const { query, payload, pathParams, headers } = route.request;
5
-
6
- const routeDocs = includeFile("@base/route-docs", { config, route, utils });
7
- const routeNamespace = pascalCase(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 { _, pascalCase, require } = utils;
4
+ const { query, payload, pathParams, headers } = route.request;
5
+
6
+ const routeDocs = includeFile("@base/route-docs", { config, route, utils });
7
+ const routeNamespace = pascalCase(route.routeName.usage);
8
+
9
+ %>
10
+
11
+ /**
12
+ <%~ routeDocs.description %>
13
+
14
+ <%~ routeDocs.lines %>
15
+
16
+ */
17
+ export namespace <%~ routeNamespace %> {
18
+ export type RequestParams = <%~ (pathParams && pathParams.type) || '{}' %>;
19
+ export type RequestQuery = <%~ (query && query.type) || '{}' %>;
20
+ export type RequestBody = <%~ (payload && payload.type) || 'never' %>;
21
+ export type RequestHeaders = <%~ (headers && headers.type) || '{}' %>;
22
+ export type ResponseBody = <%~ route.response.type %>;
22
23
  }
@@ -1,15 +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
+ <%
2
+ const { contract, utils } = it;
3
+ const { formatDescription, require, _ } = utils;
4
+
5
+ %>
6
+ <% if (contract.$content.length) { %>
7
+ export type <%~ contract.name %> = {
8
+ <% for (const field of contract.$content) { %>
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,65 +1,69 @@
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
+ <%
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 type { 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
+ <% if (routes.outOfModule) { %>
51
+ <% for (const route of routes.outOfModule) { %>
52
+
53
+ <%~ includeFile('./procedure-call.ejs', { ...it, route }) %>
54
+
55
+ <% } %>
56
+ <% } %>
57
+
58
+ <% if (routes.combined) { %>
59
+ <% for (const { routes: combinedRoutes = [], moduleName } of routes.combined) { %>
60
+ <%~ moduleName %> = {
61
+ <% for (const route of combinedRoutes) { %>
62
+
63
+ <%~ includeFile('./procedure-call.ejs', { ...it, route }) %>
64
+
65
+ <% } %>
66
+ }
67
+ <% } %>
68
+ <% } %>
69
+ }
@@ -1,100 +1,100 @@
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
- "TEXT": "ContentType.Text",
54
- }
55
- // RequestParams["format"]
56
- const responseContentKind = {
57
- "JSON": '"json"',
58
- "IMAGE": '"blob"',
59
- "FORM_DATA": isFetchTemplate ? '"formData"' : '"document"'
60
- }
61
-
62
- const bodyTmpl = _.get(payload, "name") || null;
63
- const queryTmpl = (query != null && queryName) || null;
64
- const bodyContentKindTmpl = requestContentKind[requestBodyInfo.contentKind] || null;
65
- const responseFormatTmpl = responseContentKind[responseBodyInfo.success && responseBodyInfo.success.schema && responseBodyInfo.success.schema.contentKind] || null;
66
- const securityTmpl = security ? 'true' : null;
67
-
68
- const describeReturnType = () => {
69
- if (!config.toJS) return "";
70
-
71
- switch(config.httpClientType) {
72
- case HTTP_CLIENT.AXIOS: {
73
- return `Promise<AxiosResponse<${type}>>`
74
- }
75
- default: {
76
- return `Promise<HttpResponse<${type}, ${errorType}>`
77
- }
78
- }
79
- }
80
-
81
- %>
82
- /**
83
- <%~ routeDocs.description %>
84
-
85
- *<% /* Here you can add some other JSDoc tags */ %>
86
-
87
- <%~ routeDocs.lines %>
88
-
89
- */
90
- <%~ route.routeName.usage %><%~ route.namespace ? ': ' : ' = ' %>(<%~ wrapperArgs %>)<%~ config.toJS ? `: ${describeReturnType()}` : "" %> =>
91
- <%~ config.singleHttpClient ? 'this.http.request' : 'this.request' %><<%~ type %>, <%~ errorType %>>({
92
- path: `<%~ path %>`,
93
- method: '<%~ _.upperCase(method) %>',
94
- <%~ queryTmpl ? `query: ${queryTmpl},` : '' %>
95
- <%~ bodyTmpl ? `body: ${bodyTmpl},` : '' %>
96
- <%~ securityTmpl ? `secure: ${securityTmpl},` : '' %>
97
- <%~ bodyContentKindTmpl ? `type: ${bodyContentKindTmpl},` : '' %>
98
- <%~ responseFormatTmpl ? `format: ${responseFormatTmpl},` : '' %>
99
- ...<%~ _.get(requestConfigParam, "name") %>,
100
- })<%~ 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
+ "TEXT": "ContentType.Text",
54
+ }
55
+ // RequestParams["format"]
56
+ const responseContentKind = {
57
+ "JSON": '"json"',
58
+ "IMAGE": '"blob"',
59
+ "FORM_DATA": isFetchTemplate ? '"formData"' : '"document"'
60
+ }
61
+
62
+ const bodyTmpl = _.get(payload, "name") || null;
63
+ const queryTmpl = (query != null && queryName) || null;
64
+ const bodyContentKindTmpl = requestContentKind[requestBodyInfo.contentKind] || null;
65
+ const responseFormatTmpl = responseContentKind[responseBodyInfo.success && responseBodyInfo.success.schema && responseBodyInfo.success.schema.contentKind] || null;
66
+ const securityTmpl = security ? 'true' : null;
67
+
68
+ const describeReturnType = () => {
69
+ if (!config.toJS) return "";
70
+
71
+ switch(config.httpClientType) {
72
+ case HTTP_CLIENT.AXIOS: {
73
+ return `Promise<AxiosResponse<${type}>>`
74
+ }
75
+ default: {
76
+ return `Promise<HttpResponse<${type}, ${errorType}>`
77
+ }
78
+ }
79
+ }
80
+
81
+ %>
82
+ /**
83
+ <%~ routeDocs.description %>
84
+
85
+ *<% /* Here you can add some other JSDoc tags */ %>
86
+
87
+ <%~ routeDocs.lines %>
88
+
89
+ */
90
+ <%~ route.routeName.usage %><%~ route.namespace ? ': ' : ' = ' %>(<%~ wrapperArgs %>)<%~ config.toJS ? `: ${describeReturnType()}` : "" %> =>
91
+ <%~ config.singleHttpClient ? 'this.http.request' : 'this.request' %><<%~ type %>, <%~ errorType %>>({
92
+ path: `<%~ path %>`,
93
+ method: '<%~ _.upperCase(method) %>',
94
+ <%~ queryTmpl ? `query: ${queryTmpl},` : '' %>
95
+ <%~ bodyTmpl ? `body: ${bodyTmpl},` : '' %>
96
+ <%~ securityTmpl ? `secure: ${securityTmpl},` : '' %>
97
+ <%~ bodyContentKindTmpl ? `type: ${bodyContentKindTmpl},` : '' %>
98
+ <%~ responseFormatTmpl ? `format: ${responseFormatTmpl},` : '' %>
99
+ ...<%~ _.get(requestConfigParam, "name") %>,
100
+ })<%~ route.namespace ? ',' : '' %>
@@ -1,28 +1,32 @@
1
- <%
2
- const { utils, config, routes, modelTypes } = it;
3
- const { _, pascalCase } = 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 <%~ pascalCase(moduleName) %> {
23
- <% routes.forEach((route) => { %>
24
- <%~ includeFile('@base/route-type.ejs', { ...it, route }) %>
25
- <% }) %>
26
- }
27
-
28
- <% }) %>
1
+ <%
2
+ const { utils, config, routes, modelTypes } = it;
3
+ const { _, pascalCase } = 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
+ <% if (routes.outOfModule) { %>
16
+ <% for (const { routes: outOfModuleRoutes = [] } of routes.outOfModule) { %>
17
+ <% for (const route of outOfModuleRoutes) { %>
18
+ <%~ includeFile('@base/route-type.ejs', { ...it, route }) %>
19
+ <% } %>
20
+ <% } %>
21
+ <% } %>
22
+
23
+ <% if (routes.combined) { %>
24
+ <% for (const { routes: combinedRoutes = [], moduleName } of routes.combined) { %>
25
+ export namespace <%~ pascalCase(moduleName) %> {
26
+ <% for (const route of combinedRoutes) { %>
27
+ <%~ includeFile('@base/route-type.ejs', { ...it, route }) %>
28
+ <% } %>
29
+ }
30
+
31
+ <% } %>
32
+ <% } %>
@@ -1,28 +1,28 @@
1
- <%
2
- const { utils, route, config, modelTypes } = it;
3
- const { _, pascalCase, require } = utils;
4
- const apiClassName = pascalCase(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
- }
1
+ <%
2
+ const { utils, route, config, modelTypes } = it;
3
+ const { _, pascalCase, require } = utils;
4
+ const apiClassName = pascalCase(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 type { 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
+ <% for (const route of routes) { %>
26
+ <%~ includeFile('./procedure-call.ejs', { ...it, route }) %>
27
+ <% } %>
28
+ }