swagger-typescript-api 12.0.3 → 12.0.4
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 +1 -0
- package/package.json +1 -2
- package/src/schema-parser/schema-parser.js +3 -3
- package/src/schema-parser/schema-routes.js +38 -18
- package/src/schema-parser/schema-utils.js +2 -1
- package/src/util/name-resolver.js +4 -4
- package/templates/base/data-contract-jsdoc.ejs +37 -37
- package/templates/base/data-contracts.ejs +28 -28
- package/templates/base/enum-data-contract.ejs +12 -12
- package/templates/base/http-client.ejs +2 -2
- package/templates/base/http-clients/axios-http-client.ejs +138 -138
- package/templates/base/http-clients/fetch-http-client.ejs +224 -224
- package/templates/base/interface-data-contract.ejs +10 -10
- package/templates/base/object-field-jsdoc.ejs +28 -28
- package/templates/base/route-docs.ejs +30 -30
- package/templates/base/route-name.ejs +42 -42
- package/templates/base/route-type.ejs +21 -21
- package/templates/base/type-data-contract.ejs +15 -15
- package/templates/default/api.ejs +65 -65
- package/templates/default/procedure-call.ejs +100 -100
- package/templates/default/route-types.ejs +28 -28
- package/templates/modular/api.ejs +28 -28
- package/templates/modular/procedure-call.ejs +100 -100
- package/templates/modular/route-types.ejs +18 -18
|
@@ -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 %> = (<%~ 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
|
-
})
|
|
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 %> = (<%~ 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
|
+
})
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
<%
|
|
2
|
-
const { utils, config, route, modelTypes } = it;
|
|
3
|
-
const { _, pascalCase } = utils;
|
|
4
|
-
const { routes, moduleName } = route;
|
|
5
|
-
const dataContracts = config.modular ? _.map(modelTypes, "name") : [];
|
|
6
|
-
|
|
7
|
-
%>
|
|
8
|
-
<% if (dataContracts.length) { %>
|
|
9
|
-
import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %>"
|
|
10
|
-
<% } %>
|
|
11
|
-
|
|
12
|
-
export namespace <%~ pascalCase(moduleName) %> {
|
|
13
|
-
<% _.forEach(routes, (route) => { %>
|
|
14
|
-
|
|
15
|
-
<%~ includeFile('@base/route-type.ejs', { ...it, route }) %>
|
|
16
|
-
|
|
17
|
-
<% }) %>
|
|
18
|
-
}
|
|
1
|
+
<%
|
|
2
|
+
const { utils, config, route, modelTypes } = it;
|
|
3
|
+
const { _, pascalCase } = utils;
|
|
4
|
+
const { routes, moduleName } = route;
|
|
5
|
+
const dataContracts = config.modular ? _.map(modelTypes, "name") : [];
|
|
6
|
+
|
|
7
|
+
%>
|
|
8
|
+
<% if (dataContracts.length) { %>
|
|
9
|
+
import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %>"
|
|
10
|
+
<% } %>
|
|
11
|
+
|
|
12
|
+
export namespace <%~ pascalCase(moduleName) %> {
|
|
13
|
+
<% _.forEach(routes, (route) => { %>
|
|
14
|
+
|
|
15
|
+
<%~ includeFile('@base/route-type.ejs', { ...it, route }) %>
|
|
16
|
+
|
|
17
|
+
<% }) %>
|
|
18
|
+
}
|