in scripts/utils/generateApis.js [73:145]
function generateNamespace (namespace, nested, specFolder, version) {
const common = require(join(specFolder, '_common.json'))
let code = dedent`
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
'use strict'
/* eslint camelcase: 0 */
/* eslint no-unused-vars: 0 */
const { handleError, snakeCaseKeys, normalizeArguments, kConfigurationError } = require('../utils')
`
if (nested.length > 0) {
let getters = ''
for (const n of nested) {
if (n.includes('_')) {
const nameSnaked = n
.replace(/\.([a-z])/g, k => k[1].toUpperCase())
.replace(/_([a-z])/g, k => k[1].toUpperCase())
getters += `${n}: { get () { return this.${nameSnaked} } },\n`
}
}
const api = generateMultiApi(version, namespace, nested, common, specFolder)
if (getters.length > 0) {
getters = `Object.defineProperties(${api.namespace}Api.prototype, {\n${getters}})`
}
code += `
const acceptedQuerystring = ${JSON.stringify(api.acceptedQuerystring)}
const snakeCase = ${JSON.stringify(api.snakeCase)}
function ${api.namespace}Api (transport, ConfigurationError) {
this.transport = transport
this[kConfigurationError] = ConfigurationError
}
${api.code}
${getters}
module.exports = ${api.namespace}Api
`
} else {
const spec = require(join(specFolder, `${namespace}.json`))
const api = generateSingleApi(version, spec, common)
code += `
const acceptedQuerystring = ${JSON.stringify(api.acceptedQuerystring)}
const snakeCase = ${JSON.stringify(api.snakeCase)}
${api.code}
module.exports = ${api.name}Api
`
}
return code
}