Files
elasticsearch-js/scripts/generate/templates/api_methods.tmpl

73 lines
2.0 KiB
Cheetah

[[api-reference<%= branchSuffix %>]]
== <%= branch %> API
<% if (branchIsDefault) { %>
NOTE: This is currently the default API, but in upcoming versions that will change. We recommend setting the `apiVersion` config param when you instantiate your client to make sure that the API does not change unexpectedly.
<% } else { %>
NOTE: At this time, you must opt into the <%= branch %> API by setting the `apiVersion` config parameter.
<% }
actions = _.sortBy(actions, 'namespace');
_.each(actions, function (action) {
action.index = 'api-' + action.name.toLowerCase().replace(/[^\w]+/g, '-') + branchSuffix;
%>
[[<%= action.index %>]]
=== `<%= action.name %>`
[source,js]
--------
client.<%= action.name %>([params, [callback]])
--------
<%= action.description %>
Check the *<<api-conventions>>* and <%= action.docUrl %>[the elasticsearch docs] for more information pertaining to this method.
<%= action.examples %>
<% if (_.size(action.allParams)) { %>
*Params*
[horizontal]<%
var printParam = function (param, paramName) {
// param name
print(`\n\`${paramWithDefault(paramName, param.default)}\`::`)
// param type and description
print(`\n${paramType(param.type, paramName)} -- ${joinParagraphs(param.description || '', 4)}`)
if (param.type === 'enum') {
print('\nOptions:::')
_.each(param.options, function (opt) {
print(`\n * \`"${opt}"\``)
})
print('\n')
}
}
_.each(action.allParams, printParam)
if (action.spec.method && action.spec.method !== 'GET') {
var bodyTitle = `${action.spec.needBody ? 'The' : 'An optional'} request body`
var bodyTypeDesc = action.spec.bulkBody
? 'as either an array of objects or new-line delimited JSON objects'
: 'as either JSON or a JSON serializable object'
printParam({
type: action.spec.bulkBody ? 'bulkbody' : 'body',
description: `${bodyTitle}, ${bodyTypeDesc}. See ${action.docUrl}[the elasticsearch docs] for details about what can be specified here.`
}, 'body')
}
%>
link:#[back to top]<%
} // endif size allParams
}); // endeach
%>