Skip to content

Commit 6e82ee2

Browse files
authored
Merge pull request #1261 from swagger-api/issue-1256
updated javascript es5 templates
2 parents 0f7eeb2 + 756917a commit 6e82ee2

9 files changed

+987
-872
lines changed

src/main/resources/handlebars/javascript/ApiClient.mustache

+576-564
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,118 @@
11
{{>licenseInfo}}
2+
(function(root, factory) {
3+
if (typeof define === 'function' && define.amd) {
4+
// AMD. Register as an anonymous module.
5+
define(['{{#invokerPackage}}{{&invokerPackage}}/{{/invokerPackage}}ApiClient'{{#imports}}, '{{#invokerPackage}}{{&invokerPackage}}/{{/invokerPackage}}{{#modelPackage}}{{&modelPackage}}/{{/modelPackage}}{{import}}'{{/imports}}], factory);
6+
} else if (typeof module === 'object' && module.exports) {
7+
// CommonJS-like environments that support module.exports, like Node.
8+
module.exports = factory(require('../ApiClient'){{#imports}}, require('../{{#modelPackage}}{{&modelPackage}}/{{/modelPackage}}{{import}}'){{/imports}});
9+
} else {
10+
// Browser globals (root is window)
11+
if (!root.{{&moduleName}}) {
12+
root.{{&moduleName}} = {};
13+
}
14+
root.{{&moduleName}}.{{&classname}} = factory(root.{{&moduleName}}.ApiClient{{#imports}}, root.{{&moduleName}}.{{import}}{{/imports}});
15+
}
16+
}(this, function(ApiClient{{#imports}}, {{import}}{{/imports}}) {
17+
'use strict';
218
3-
{{=< >=}}
4-
import ApiClient from "../ApiClient";
5-
<#imports>import <import> from '../<#modelPackage><&modelPackage>/</modelPackage><import>';
6-
</imports>
7-
8-
<#emitJSDoc>/**
9-
* <baseName> service.
10-
* @module <#invokerPackage><&invokerPackage>/</invokerPackage><#apiPackage><&apiPackage>/</apiPackage><classname>
11-
* @version <projectVersion>
12-
*/</emitJSDoc>
13-
export default class <classname> {
19+
{{#emitJSDoc}} /**
20+
* {{baseName}} service.
21+
* @module {{#invokerPackage}}{{&invokerPackage}}/{{/invokerPackage}}{{#apiPackage}}{{&apiPackage}}/{{/apiPackage}}{{classname}}
22+
* @version {{projectVersion}}
23+
*/
1424

15-
<#emitJSDoc>/**
16-
* Constructs a new <&classname>. <#description>
17-
* <description></description>
18-
* @alias module:<#invokerPackage><&invokerPackage>/</invokerPackage><#apiPackage><apiPackage>/</apiPackage><classname>
19-
* @class
20-
* @param {module:<#invokerPackage><&invokerPackage>/</invokerPackage>ApiClient} [apiClient] Optional API client implementation to use,
21-
* default to {@link module:<#invokerPackage><&invokerPackage>/</invokerPackage>ApiClient#instance} if unspecified.
22-
*/</emitJSDoc>
23-
constructor(apiClient) {
24-
this.apiClient = apiClient || ApiClient.instance;
25-
}
25+
/**
26+
* Constructs a new {{&classname}}. {{#description}}
27+
* {{description}}{{/description}}
28+
* @alias module:{{#invokerPackage}}{{&invokerPackage}}/{{/invokerPackage}}{{#apiPackage}}{{apiPackage}}/{{/apiPackage}}{{classname}}
29+
* @class
30+
* @param {module:{{#invokerPackage}}{{&invokerPackage}}/{{/invokerPackage}}ApiClient} [apiClient] Optional API client implementation to use,
31+
* default to {@link module:{{#invokerPackage}}{{&invokerPackage}}/{{/invokerPackage}}ApiClient#instance} if unspecified.
32+
*/
33+
{{/emitJSDoc}} var exports = function(apiClient) {
34+
this.apiClient = apiClient || ApiClient.instance;
2635
27-
<#operations><#operation><#emitJSDoc><^usePromises>
36+
{{#operations}}{{#operation}}{{#emitJSDoc}}{{^usePromises}}
2837
/**
29-
* Callback function to receive the result of the <operationId> operation.
30-
* @callback module:<#invokerPackage><invokerPackage>/</invokerPackage><#apiPackage><apiPackage>/</apiPackage><classname>~<operationId>Callback
38+
* Callback function to receive the result of the {{operationId}} operation.
39+
* @callback module:{{#invokerPackage}}{{invokerPackage}}/{{/invokerPackage}}{{#apiPackage}}{{apiPackage}}/{{/apiPackage}}{{classname}}~{{operationId}}Callback
3140
* @param {String} error Error message, if any.
32-
* @param <#vendorExtensions.x-jsdoc-type>{<&vendorExtensions.x-jsdoc-type>} data The data returned by the service call.</vendorExtensions.x-jsdoc-type><^vendorExtensions.x-jsdoc-type>data This operation does not return a value.</vendorExtensions.x-jsdoc-type>
41+
* @param {{#vendorExtensions.x-jsdoc-type}}{{braces "left"}}{{&vendorExtensions.x-jsdoc-type}}{{braces "right"}} data The data returned by the service call.{{/vendorExtensions.x-jsdoc-type}}{{^vendorExtensions.x-jsdoc-type}}data This operation does not return a value.{{/vendorExtensions.x-jsdoc-type}}
3342
* @param {String} response The complete HTTP response.
34-
*/</usePromises>
43+
*/{{/usePromises}}
3544

36-
/**<#summary>
37-
* <summary></summary><#notes>
38-
* <notes></notes><#parameters><#required>
39-
* @param {<&vendorExtensions.x-jsdoc-type>} <paramName> <description></required></parameters><#hasOptionalParams>
40-
* @param {Object} opts Optional parameters<#parameters><^required>
41-
* @param {<&vendorExtensions.x-jsdoc-type>} opts.<paramName> <description><#defaultValue> (default to <.>)</defaultValue></required></parameters></hasOptionalParams><^usePromises>
42-
* @param {module:<#invokerPackage><&invokerPackage>/</invokerPackage><#apiPackage><&apiPackage>/</apiPackage><&classname>~<operationId>Callback} callback The callback function, accepting three arguments: error, data, response<#returnType>
43-
* data is of type: {@link <&vendorExtensions.x-jsdoc-type>}</returnType></usePromises><#usePromises>
44-
* @return {Promise} a {@link https://www.promisejs.org/|Promise}<#returnType>, with an object containing data of type {@link <&vendorExtensions.x-jsdoc-type>} and HTTP response</returnType><^returnType>, with an object containing HTTP response</returnType></usePromises>
45+
/**{{#summary}}
46+
* {{summary}}{{/summary}}{{#notes}}
47+
* {{notes}}{{/notes}}{{#allParams}}{{#required}}
48+
* @param {{braces "left"}}{{&vendorExtensions.x-jsdoc-type}}{{braces "right"}} {{paramName}} {{description}}{{/required}}{{/allParams}}{{#hasOptionalParams}}
49+
* @param {Object} opts Optional parameters{{#allParams}}{{^required}}
50+
* @param {{braces "left"}}{{&vendorExtensions.x-jsdoc-type}}{{braces "right"}} opts.{{paramName}} {{description}}{{#defaultValue}} (default to {{.}}){{/defaultValue}}{{/required}}{{/allParams}}{{/hasOptionalParams}}{{^usePromises}}
51+
* @param {module:{{#invokerPackage}}{{&invokerPackage}}/{{/invokerPackage}}{{#apiPackage}}{{&apiPackage}}/{{/apiPackage}}{{&classname}}~{{operationId}}Callback} callback The callback function, accepting three arguments: error, data, response{{#returnType}}
52+
* data is of type: {{braces "left"}}@link {{&vendorExtensions.x-jsdoc-type}}{{braces "right"}}{{/returnType}}{{/usePromises}}{{#usePromises}}
53+
* @return {Promise} a {@link https://www.promisejs.org/|Promise{{braces "right"}}{{#returnType}}, with an object containing data of type {@link {{&vendorExtensions.x-jsdoc-type}}{{braces "right"}} and HTTP response{{/returnType}}{{^returnType}}, with an object containing HTTP response{{/returnType}}{{/usePromises}}
4554
*/
46-
</emitJSDoc> <operationId><#usePromises>WithHttpInfo</usePromises>(<vendorExtensions.x-codegen-argList>) {<#hasOptionalParams>
47-
opts = opts || {};</hasOptionalParams>
48-
let postBody = <#bodyParam><#required><paramName></required><^required>opts['<paramName>']</required></bodyParam><^bodyParam>null</bodyParam>;
49-
<#parameters><#required>
50-
// verify the required parameter '<paramName>' is set
51-
if (<paramName> === undefined || <paramName> === null) {
52-
throw new Error("Missing the required parameter '<paramName>' when calling <operationId>");
55+
{{/emitJSDoc}} this.{{operationId}}{{#usePromises}}WithHttpInfo{{/usePromises}} = function({{vendorExtensions.x-codegen-arg-list}}{{^usePromises}}{{#hasParams}}, {{/hasParams}}callback{{/usePromises}}) {{braces "left"}}{{#hasOptionalParams}}
56+
opts = opts || {};{{/hasOptionalParams}}
57+
var postBody = {{#bodyParam}}{{#required}}{{paramName}}{{/required}}{{^required}}opts['{{paramName}}']{{/required}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
58+
{{#allParams}}{{#required}}
59+
// verify the required parameter '{{paramName}}' is set
60+
if ({{paramName}} === undefined || {{paramName}} === null) {
61+
throw new Error("Missing the required parameter '{{paramName}}' when calling {{operationId}}");
5362
}
54-
</required></parameters>
63+
{{/required}}{{/allParams}}
5564

56-
let pathParams = {<#pathParams>
57-
'<baseName>': <#required><paramName></required><^required>opts['<paramName>']</required><#hasMore>,</hasMore></pathParams>
65+
var pathParams = {{braces "left"}}{{#pathParams}}
66+
'{{baseName}}': {{#required}}{{paramName}}{{/required}}{{^required}}opts['{{paramName}}']{{/required}}{{#hasMore}},{{/hasMore}}{{/pathParams}}
67+
};
68+
let queryParams = {{braces "left"}}{{#queryParams}}
69+
'{{baseName}}': {{#collectionFormat}}this.apiClient.buildCollectionParam({{#required}}{{paramName}}{{/required}}{{^required}}opts['{{paramName}}']{{/required}}, '{{collectionFormat}}'){{/collectionFormat}}{{^collectionFormat}}{{#required}}{{paramName}}{{/required}}{{^required}}opts['{{paramName}}']{{/required}}{{/collectionFormat}}{{#hasMore}},{{/hasMore}}{{/queryParams}}
5870
};
59-
let queryParams = {<#queryParams>
60-
'<baseName>': <#collectionFormat>this.apiClient.buildCollectionParam(<#required><paramName></required><^required>opts['<paramName>']</required>, '<collectionFormat>')</collectionFormat><^collectionFormat><#required><paramName></required><^required>opts['<paramName>']</required></collectionFormat><#hasMore>,</hasMore></queryParams>
71+
var collectionQueryParams = {{braces "left"}}{{#queryParams}}{{#collectionFormat}}
72+
'{{baseName}}': {
73+
value: {{#required}}{{paramName}}{{/required}}{{^required}}opts['{{paramName}}']{{/required}},
74+
collectionFormat: '{{collectionFormat}}'
75+
},{{/collectionFormat}}{{/queryParams}}
6176
};
62-
let headerParams = {<#headerParams>
63-
'<baseName>': <#required><paramName></required><^required>opts['<paramName>']</required><#hasMore>,</hasMore></headerParams>
77+
var headerParams = {{braces "left"}}{{#headerParams}}
78+
'{{baseName}}': {{#required}}{{paramName}}{{/required}}{{^required}}opts['{{paramName}}']{{/required}}{{#hasMore}},{{/hasMore}}{{/headerParams}}
6479
};
65-
let formParams = {<#formParams>
66-
'<baseName>': <#collectionFormat>this.apiClient.buildCollectionParam(<#required><paramName></required><^required>opts['<paramName>']</required>, '<collectionFormat>')</collectionFormat><^collectionFormat><#required><paramName></required><^required>opts['<paramName>']</required></collectionFormat><#hasMore>,</hasMore></formParams>
80+
var formParams = {{braces "left"}}{{#formParams}}
81+
'{{baseName}}': {{#collectionFormat}}this.apiClient.buildCollectionParam({{#required}}{{paramName}}{{/required}}{{^required}}opts['{{paramName}}']{{/required}}, '{{collectionFormat}}'){{/collectionFormat}}{{^collectionFormat}}{{#required}}{{paramName}}{{/required}}{{^required}}opts['{{paramName}}']{{/required}}{{/collectionFormat}}{{#hasMore}},{{/hasMore}}{{/formParams}}
6782
};
6883

69-
let authNames = [<#authMethods>'<name>'<#hasMore>, </hasMore></authMethods>];
70-
let contentTypes = [<#consumes>'<& mediaType>'<#hasMore>, </hasMore></consumes>];
71-
let accepts = [<#produces>'<& mediaType>'<#hasMore>, </hasMore></produces>];
72-
let returnType = <#returnType><&returnType></returnType><^returnType>null</returnType>;
84+
var authNames = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}];
85+
var contentTypes = [{{#consumes}}'{{& mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}];
86+
var accepts = [{{#produces}}'{{& mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}];
87+
var returnType = {{#returnType}}{{&returnType}}{{/returnType}}{{^returnType}}null{{/returnType}};
7388

7489
return this.apiClient.callApi(
75-
'<&path>', '<httpMethod>',
76-
pathParams, queryParams, headerParams, formParams, postBody,
77-
authNames, contentTypes, accepts, returnType<^usePromises>, callback</usePromises>
90+
'{{&path}}', '{{httpMethod}}',
91+
pathParams, queryParams, collectionQueryParams, headerParams, formParams, postBody,
92+
authNames, contentTypes, accepts, returnType{{^usePromises}}, callback{{/usePromises}}
7893
);
7994
}
80-
<#usePromises>
81-
<#emitJSDoc>
95+
{{#usePromises}}
96+
{{#emitJSDoc}}
8297

83-
/**<#summary>
84-
* <summary></summary><#notes>
85-
* <notes></notes><#parameters><#required>
86-
* @param {<&vendorExtensions.x-jsdoc-type>} <paramName> <description></required></parameters><#hasOptionalParams>
87-
* @param {Object} opts Optional parameters<#parameters><^required>
88-
* @param {<&vendorExtensions.x-jsdoc-type>} opts.<paramName> <description><#defaultValue> (default to <.>)</defaultValue></required></parameters></hasOptionalParams><^usePromises>
89-
* @param {module:<#invokerPackage><&invokerPackage>/</invokerPackage><#apiPackage><&apiPackage>/</apiPackage><&classname>~<operationId>Callback} callback The callback function, accepting three arguments: error, data, response<#returnType>
90-
* data is of type: {@link <&vendorExtensions.x-jsdoc-type>}</returnType></usePromises><#usePromises>
91-
* @return {Promise} a {@link https://www.promisejs.org/|Promise}<#returnType>, with data of type {@link <&vendorExtensions.x-jsdoc-type>}</returnType></usePromises>
98+
/**{{#summary}}
99+
* {{summary}}{{/summary}}{{#notes}}
100+
* {{notes}}{{/notes}}{{#allParams}}{{#required}}
101+
* @param {{braces "left"}}{{&vendorExtensions.x-jsdoc-type}}{{braces "right"}} {{paramName}} {{description}}{{/required}}{{/allParams}}{{#hasOptionalParams}}
102+
* @param {Object} opts Optional parameters{{#allParams}}{{^required}}
103+
* @param {{braces "left"}}{{&vendorExtensions.x-jsdoc-type}}{{braces "right"}} opts.{{paramName}} {{description}}{{#defaultValue}} (default to {{.}}){{/defaultValue}}{{/required}}{{/allParams}}{{/hasOptionalParams}}{{^usePromises}}
104+
* @param {module:{{#invokerPackage}}{{&invokerPackage}}/{{/invokerPackage}}{{#apiPackage}}{{&apiPackage}}/{{/apiPackage}}{{&classname}}~{{operationId}}Callback} callback The callback function, accepting three arguments: error, data, response{{#returnType}}
105+
* data is of type: {@link {{&vendorExtensions.x-jsdoc-type}}{{braces "right"}}{{/returnType}}{{/usePromises}}{{#usePromises}}
106+
* @return {Promise} a {@link https://www.promisejs.org/|Promise}{{#returnType}}, with data of type {@link {{&vendorExtensions.x-jsdoc-type}}{{braces "right"}}{{/returnType}}{{/usePromises}}
92107
*/
93-
</emitJSDoc> <operationId>(<vendorExtensions.x-codegen-argList>) {
94-
return this.<operationId>WithHttpInfo(<vendorExtensions.x-codegen-argList>)
108+
{{/emitJSDoc}} this.{{operationId}} = function({{vendorExtensions.x-codegen-arg-list}}) {
109+
return this.{{operationId}}WithHttpInfo({{vendorExtensions.x-codegen-arg-list}})
95110
.then(function(response_and_data) {
96111
return response_and_data.data;
97112
});
98113
}
99-
</usePromises>
100-
</operation></operations>
114+
{{/usePromises}}
115+
{{/operation}}{{/operations}} };
101116

102-
}
103-
<={{ }}=>
117+
return exports;
118+
}));
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
{{#emitJSDoc}}/**
2-
* Allowed values for the <code>{{baseName}}</code> property.
3-
* @enum {{=<% %>=}}{<%datatype%>}<%={{ }}=%>
4-
* @readonly
5-
*/{{/emitJSDoc}}
6-
export default {{datatypeWithEnum}} = {
7-
{{#allowableValues}}{{#enumVars}}
8-
{{#emitJSDoc}}/**
1+
{{#emitJSDoc}}
2+
/**
3+
* Allowed values for the <code>{{baseName}}</code> property.
4+
* @enum {{braces "left"}}{{datatype}}{{braces "right"}}
5+
* @readonly
6+
*/
7+
{{/emitJSDoc}}
8+
exports.{{datatypeWithEnum}} = {
9+
{{#allowableValues}}
10+
{{#enumVars}}
11+
{{#emitJSDoc}}
12+
/**
913
* value: {{{value}}}
1014
* @const
11-
*/{{/emitJSDoc}}
15+
*/
16+
{{/emitJSDoc}}
1217
"{{name}}": {{{value}}}{{^@last}},
1318
{{/@last}}
14-
{{/enumVars}}{{/allowableValues}}
15-
};
19+
{{/enumVars}}
20+
{{/allowableValues}}
21+
};

0 commit comments

Comments
 (0)