swagger-typescript-api 12.0.0 → 13.0.0-experimental-1
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 +8 -9
- package/index.d.ts +5 -1
- package/package.json +1 -1
- package/src/code-gen-process.js +76 -71
- package/src/configuration.js +1 -5
- package/src/schema-parser/schema-formatters.js +28 -23
- package/src/schema-parser/schema-parser.js +270 -200
- package/src/schema-parser/schema-processor.js +79 -0
- package/src/schema-parser/schema-routes.js +96 -82
- package/src/schema-parser/schema-utils.js +62 -1
- package/src/templates.js +19 -14
- package/src/{type-name.js → type-name-formatter.js} +2 -2
- package/src/util/request.js +5 -6
- package/templates/base/data-contracts.ejs +4 -5
- package/templates/base/http-client.ejs +1 -1
- package/templates/base/interface-data-contract.ejs +3 -3
- package/templates/base/route-type.ejs +1 -1
- package/templates/base/type-data-contract.ejs +3 -3
- package/templates/default/api.ejs +12 -9
- package/templates/default/procedure-call.ejs +2 -2
- package/templates/default/route-types.ejs +15 -11
- package/templates/modular/api.ejs +3 -3
- package/templates/modular/procedure-call.ejs +2 -2
- package/templates/modular/route-types.ejs +3 -3
|
@@ -3,8 +3,8 @@ const { contract, utils } = it;
|
|
|
3
3
|
const { formatDescription, require, _ } = utils;
|
|
4
4
|
%>
|
|
5
5
|
export interface <%~ contract.name %> {
|
|
6
|
-
<%
|
|
7
|
-
<%~ includeFile('@base/object-field-jsdoc.ejs', { ...it, field }) %>
|
|
6
|
+
<% for await (const field of contract.$content) { %>
|
|
7
|
+
<%~ await includeFile('@base/object-field-jsdoc.ejs', { ...it, field }) %>
|
|
8
8
|
<%~ field.name %><%~ field.isRequired ? '' : '?' %>: <%~ field.value %><%~ field.isNullable ? ' | null' : ''%>;
|
|
9
|
-
<% }
|
|
9
|
+
<% } %>
|
|
10
10
|
}
|
|
@@ -3,7 +3,7 @@ const { route, utils, config } = it;
|
|
|
3
3
|
const { _, pascalCase, require } = utils;
|
|
4
4
|
const { query, payload, pathParams, headers } = route.request;
|
|
5
5
|
|
|
6
|
-
const routeDocs = includeFile("@base/route-docs", { config, route, utils });
|
|
6
|
+
const routeDocs = await includeFile("@base/route-docs", { config, route, utils });
|
|
7
7
|
const routeNamespace = pascalCase(route.routeName.usage);
|
|
8
8
|
|
|
9
9
|
%>
|
|
@@ -5,10 +5,10 @@ const { formatDescription, require, _ } = utils;
|
|
|
5
5
|
%>
|
|
6
6
|
<% if (contract.$content.length) { %>
|
|
7
7
|
export type <%~ contract.name %> = {
|
|
8
|
-
<%
|
|
9
|
-
<%~ includeFile('@base/object-field-jsdoc.ejs', { ...it, field }) %>
|
|
8
|
+
<% for await (const field of contract.$content) { %>
|
|
9
|
+
<%~ await includeFile('@base/object-field-jsdoc.ejs', { ...it, field }) %>
|
|
10
10
|
<%~ field.field %>;
|
|
11
|
-
<% }
|
|
11
|
+
<% } %>
|
|
12
12
|
}<%~ utils.isNeedToAddNull(contract) ? ' | null' : ''%>
|
|
13
13
|
<% } else { %>
|
|
14
14
|
export type <%~ contract.name %> = Record<string, any>;
|
|
@@ -23,7 +23,6 @@ const descriptionLines = _.compact([
|
|
|
23
23
|
info.description && " ",
|
|
24
24
|
info.description && _.replace(formatDescription(info.description), /\n/g, "\n * "),
|
|
25
25
|
]);
|
|
26
|
-
|
|
27
26
|
%>
|
|
28
27
|
|
|
29
28
|
<% if (config.httpClientType === config.constants.HTTP_CLIENT.AXIOS) { %> import { AxiosRequestConfig, AxiosResponse } from "axios"; <% } %>
|
|
@@ -47,19 +46,23 @@ export class <%~ config.apiClassName %><SecurityDataType extends unknown><% if (
|
|
|
47
46
|
<% } %>
|
|
48
47
|
|
|
49
48
|
|
|
50
|
-
<%
|
|
49
|
+
<% if (routes.outOfModule) { %>
|
|
50
|
+
<% for await (const route of routes.outOfModule) { %>
|
|
51
51
|
|
|
52
|
-
<%~ includeFile('./procedure-call.ejs', { ...it, route }) %>
|
|
53
52
|
|
|
54
|
-
|
|
53
|
+
<%~ await includeFile('./procedure-call.ejs', { ...it, route }) %>
|
|
54
|
+
<% } %>
|
|
55
|
+
<% } %>
|
|
55
56
|
|
|
56
|
-
<%
|
|
57
|
+
<% if (routes.combined) { %>
|
|
58
|
+
<% for await (const { routes: combinedRoutes = [], moduleName } of routes.combined) { %>
|
|
57
59
|
<%~ moduleName %> = {
|
|
58
|
-
<%
|
|
60
|
+
<% for await (const route of combinedRoutes) { %>
|
|
59
61
|
|
|
60
|
-
<%~ includeFile('./procedure-call.ejs', { ...it, route }) %>
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
<%~ await includeFile('./procedure-call.ejs', { ...it, route }) %>
|
|
64
|
+
<% } %>
|
|
63
65
|
}
|
|
64
|
-
<% }
|
|
66
|
+
<% } %>
|
|
67
|
+
<% } %>
|
|
65
68
|
}
|
|
@@ -5,7 +5,7 @@ const { _, getInlineParseContent, getParseContent, parseSchema, getComponentByRe
|
|
|
5
5
|
const { parameters, path, method, payload, query, formData, security, requestParams } = route.request;
|
|
6
6
|
const { type, errorType, contentTypes } = route.response;
|
|
7
7
|
const { HTTP_CLIENT, RESERVED_REQ_PARAMS_ARG_NAMES } = config.constants;
|
|
8
|
-
const routeDocs = includeFile("@base/route-docs", { config, route, utils });
|
|
8
|
+
const routeDocs = await includeFile("@base/route-docs", { config, route, utils });
|
|
9
9
|
const queryName = (query && query.name) || "query";
|
|
10
10
|
const pathParams = _.values(parameters);
|
|
11
11
|
const pathParamsNames = _.map(pathParams, "name");
|
|
@@ -26,7 +26,7 @@ const rawWrapperArgs = config.extractRequestParams ?
|
|
|
26
26
|
requestParams && {
|
|
27
27
|
name: pathParams.length ? `{ ${_.join(pathParamsNames, ", ")}, ...${queryName} }` : queryName,
|
|
28
28
|
optional: false,
|
|
29
|
-
type: getInlineParseContent(requestParams),
|
|
29
|
+
type: await getInlineParseContent(requestParams),
|
|
30
30
|
},
|
|
31
31
|
...(!requestParams ? pathParams : []),
|
|
32
32
|
payload,
|
|
@@ -12,17 +12,21 @@ import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataCont
|
|
|
12
12
|
/* TODO: outOfModule, combined should be attributes of route, which will allow to avoid duplication of code */
|
|
13
13
|
%>
|
|
14
14
|
|
|
15
|
-
<% routes.outOfModule && routes.outOfModule.forEach(({ routes = [] }) => { %>
|
|
16
|
-
<% routes.forEach((route) => { %>
|
|
17
|
-
<%~ includeFile('@base/route-type.ejs', { ...it, route }) %>
|
|
18
|
-
<% }) %>
|
|
19
|
-
<% }) %>
|
|
20
15
|
|
|
21
|
-
<%
|
|
16
|
+
<% if (routes.outOfModule) { %>
|
|
17
|
+
<% for await (const route of routes.outOfModule) { %>
|
|
18
|
+
|
|
19
|
+
<%~ await includeFile('@base/route-type.ejs', { ...it, route }) %>
|
|
20
|
+
<% } %>
|
|
21
|
+
<% } %>
|
|
22
|
+
|
|
23
|
+
<% if (routes.combined) { %>
|
|
24
|
+
<% for await (const { routes: combinedRoutes = [], moduleName } of routes.combined) { %>
|
|
25
|
+
|
|
22
26
|
export namespace <%~ pascalCase(moduleName) %> {
|
|
23
|
-
<%
|
|
24
|
-
<%~ includeFile('@base/route-type.ejs', { ...it, route }) %>
|
|
25
|
-
<% }
|
|
27
|
+
<% for await (const route of combinedRoutes) { %>
|
|
28
|
+
<%~ await includeFile('@base/route-type.ejs', { ...it, route }) %>
|
|
29
|
+
<% } %>
|
|
26
30
|
}
|
|
27
|
-
|
|
28
|
-
<% }
|
|
31
|
+
<% } %>
|
|
32
|
+
<% } %>
|
|
@@ -22,7 +22,7 @@ export class <%= apiClassName %><SecurityDataType = unknown><% if (!config.singl
|
|
|
22
22
|
}
|
|
23
23
|
<% } %>
|
|
24
24
|
|
|
25
|
-
<%
|
|
26
|
-
|
|
27
|
-
<% }
|
|
25
|
+
<% for await (const route of routes) { %>
|
|
26
|
+
<%~ await includeFile('./procedure-call.ejs', { ...it, route }) %>
|
|
27
|
+
<% } %>
|
|
28
28
|
}
|
|
@@ -5,7 +5,7 @@ const { _, getInlineParseContent, getParseContent, parseSchema, getComponentByRe
|
|
|
5
5
|
const { parameters, path, method, payload, query, formData, security, requestParams } = route.request;
|
|
6
6
|
const { type, errorType, contentTypes } = route.response;
|
|
7
7
|
const { HTTP_CLIENT, RESERVED_REQ_PARAMS_ARG_NAMES } = config.constants;
|
|
8
|
-
const routeDocs = includeFile("@base/route-docs", { config, route, utils });
|
|
8
|
+
const routeDocs = await includeFile("@base/route-docs", { config, route, utils });
|
|
9
9
|
const queryName = (query && query.name) || "query";
|
|
10
10
|
const pathParams = _.values(parameters);
|
|
11
11
|
const pathParamsNames = _.map(pathParams, "name");
|
|
@@ -26,7 +26,7 @@ const rawWrapperArgs = config.extractRequestParams ?
|
|
|
26
26
|
requestParams && {
|
|
27
27
|
name: pathParams.length ? `{ ${_.join(pathParamsNames, ", ")}, ...${queryName} }` : queryName,
|
|
28
28
|
optional: false,
|
|
29
|
-
type: getInlineParseContent(requestParams),
|
|
29
|
+
type: await getInlineParseContent(requestParams),
|
|
30
30
|
},
|
|
31
31
|
...(!requestParams ? pathParams : []),
|
|
32
32
|
payload,
|
|
@@ -10,9 +10,9 @@ import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataCont
|
|
|
10
10
|
<% } %>
|
|
11
11
|
|
|
12
12
|
export namespace <%~ pascalCase(moduleName) %> {
|
|
13
|
-
<%
|
|
13
|
+
<% for await (const route of routes) { %>
|
|
14
14
|
|
|
15
|
-
<%~ includeFile('@base/route-type.ejs', { ...it, route }) %>
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
<%~ await includeFile('@base/route-type.ejs', { ...it, route }) %>
|
|
17
|
+
<% } %>
|
|
18
18
|
}
|