htmlDocs2.sample_js.mustache Maven / Gradle / Ivy
var {{{jsModuleName}}} = require('{{{jsProjectName}}}');
{{#hasAuthMethods}}
var defaultClient = {{{jsModuleName}}}.ApiClient.instance;
{{#authMethods}}{{^isBasicBearer}}{{#isBasic}}
// Configure HTTP basic authorization: {{{name}}}
var {{{name}}} = defaultClient.authentications['{{{name}}}'];
{{{name}}}.username = 'YOUR USERNAME';
{{{name}}}.password = 'YOUR PASSWORD';{{/isBasic}}{{/isBasicBearer}}{{#isBasicBearer}}
// Configure Bearer{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} access token for authorization: {{{name}}}
var {{{name}}} = defaultClient.authentications['{{{name}}}'];
{{{name}}}.accessToken = "YOUR ACCESS TOKEN";{{/isBasicBearer}}{{#isApiKey}}
// Configure API key authorization: {{{name}}}
var {{{name}}} = defaultClient.authentications['{{{name}}}'];
{{{name}}}.apiKey = "YOUR API KEY";
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//{{{name}}}.apiKeyPrefix['{{{keyParamName}}}'] = "Token";{{/isApiKey}}{{#isOAuth}}
// Configure OAuth2 access token for authorization: {{{name}}}
var {{{name}}} = defaultClient.authentications['{{{name}}}'];
{{{name}}}.accessToken = "YOUR ACCESS TOKEN";{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
// Create an instance of the API class
var api = new {{{jsModuleName}}}.{{{classname}}}(){{#hasParams}}
{{#hasRequiredParams}}
{{#requiredParams}}
var {{{paramName}}} = {{{example}}}; // {{=< >=}}{<&dataType>}<={{ }}=> {{{unescapedDescription}}}
{{/requiredParams}}
{{/hasRequiredParams}}
{{#hasOptionalParams}}
var opts = {
{{#optionalParams}}
'{{{paramName}}}': {{{example}}}{{^-last}},{{/-last}} // {{=< >=}}{<&dataType>}<={{ }}=> {{{unescapedDescription}}}
{{/optionalParams}}
};
{{/hasOptionalParams}}
{{/hasParams}}
{{#usePromises}}
api.{{{operationId}}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#hasOptionalParams}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/hasOptionalParams}}).then(function({{#returnType}}data{{/returnType}}) {
{{#returnType}}console.log('API called successfully. Returned data: ' + data);{{/returnType}}{{^returnType}}console.log('API called successfully.');{{/returnType}}
}, function(error) {
console.error(error);
});
{{/usePromises}}{{^usePromises}}
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
{{#returnType}}console.log('API called successfully. Returned data: ' + data);{{/returnType}}{{^returnType}}console.log('API called successfully.');{{/returnType}}
}
};
api.{{{operationId}}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#hasOptionalParams}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/hasOptionalParams}}{{#hasParams}}, {{/hasParams}}callback);
{{/usePromises}}