diff --git a/code-generator/definitions.js b/code-generator/definitions.js index 6eb8eece..5293699e 100644 --- a/code-generator/definitions.js +++ b/code-generator/definitions.js @@ -1,7 +1,7 @@ import yaml from 'js-yaml' import fs from 'fs' import path from 'path' -import pascalCase from 'pascal-case' +import { pascalCase } from 'change-case' const outputDir = '../src/main/java/com/ringcentral/definitions' diff --git a/code-generator/package.json b/code-generator/package.json index eb6e276a..34a9578b 100644 --- a/code-generator/package.json +++ b/code-generator/package.json @@ -8,6 +8,7 @@ "dependencies": { "change-case": "^4.1.1", "js-yaml": "^3.13.1", + "lower-case-first": "^2.0.1", "ramda": "^0.26.1" }, "devDependencies": { diff --git a/code-generator/paths.js b/code-generator/paths.js index 5088b552..c08fb391 100644 --- a/code-generator/paths.js +++ b/code-generator/paths.js @@ -1,7 +1,8 @@ import yaml from 'js-yaml' import fs from 'fs' import * as R from 'ramda' -import changeCase from 'change-case' +import { pascalCase, titleCase } from 'change-case' +import { lowerCaseFirst } from 'lower-case-first' import path from 'path' import { normalizePath, deNormalizePath, getResponseType, appendCodeToFile } from './utils' @@ -17,7 +18,7 @@ const paths = Object.keys(doc.paths) const normalizedPaths = paths.map(p => normalizePath(p)) const getRoutes = (prefix, name) => { - return [...prefix.split('/').filter(t => t !== '' && !t.startsWith('{')), name].map(t => changeCase.pascalCase(t)) + return [...prefix.split('/').filter(t => t !== '' && !t.startsWith('{')), name].map(t => pascalCase(t)) } const getFolderPath = (prefix, name) => { return path.join(outputDir, ...getRoutes(prefix, name)) @@ -128,7 +129,7 @@ const generate = (prefix = '/') => { }) operations.forEach(operation => { - const method = changeCase.pascalCase(operation.method) + const method = pascalCase(operation.method) const smartMethod = (operation.method === 'get' && !operation.endpoint.endsWith('}') && R.any(o => o.method === 'get' && o.endpoint === operation.endpoint + `/{${paramName}}`)(operations)) ? 'List' : method const responses = operation.detail.responses @@ -152,18 +153,18 @@ const generate = (prefix = '/') => { bodyParam = 'body' } else { bodyClass = R.last(body.schema.$ref.split('/')) - bodyParam = changeCase.lowerCaseFirst(bodyClass) + bodyParam = lowerCaseFirst(bodyClass) bodyClass = 'com.ringcentral.definitions.' + bodyClass } } } if (formUrlEncoded || multipart) { - bodyClass = `com.ringcentral.definitions.${changeCase.pascalCase(operation.detail.operationId)}Request` + bodyClass = `com.ringcentral.definitions.${pascalCase(operation.detail.operationId)}Request` bodyParam = `${operation.detail.operationId}Request` body = (operation.detail.parameters || []).filter(p => p.in === 'body' && p.schema && p.schema.$ref)[0] if (body) { bodyClass = R.last(body.schema.$ref.split('/')) - bodyParam = changeCase.lowerCaseFirst(bodyClass) + bodyParam = lowerCaseFirst(bodyClass) bodyClass = 'com.ringcentral.definitions.' + bodyClass } } @@ -175,12 +176,12 @@ const generate = (prefix = '/') => { methodParams.push(`${bodyParam}: ${bodyClass}`) } if (queryParams.length > 0) { - methodParams.push(`queryParams: com.ringcentral.definitions.${changeCase.pascalCase(operation.detail.operationId)}Parameters? = null`) + methodParams.push(`queryParams: com.ringcentral.definitions.${pascalCase(operation.detail.operationId)}Parameters? = null`) } code += ` /** - * Operation: ${operation.detail.summary || changeCase.titleCase(operation.detail.operationId)} + * Operation: ${operation.detail.summary || titleCase(operation.detail.operationId)} * Http ${method} ${operation.endpoint} */ ${methodParams.join(', ').includes(' = ') ? '@JvmOverloads ' : ''}fun ${smartMethod.toLowerCase()}(${methodParams.join(', ')}) : ${responseType}? diff --git a/code-generator/yarn.lock b/code-generator/yarn.lock index 679645bc..806cd4d4 100644 --- a/code-generator/yarn.lock +++ b/code-generator/yarn.lock @@ -1615,6 +1615,13 @@ loose-envify@^1.0.0, loose-envify@^1.4.0: dependencies: js-tokens "^3.0.0 || ^4.0.0" +lower-case-first@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/lower-case-first/-/lower-case-first-2.0.1.tgz#ecd03e25d9abc32aeab8d52b5fd7072772dd0ccf" + integrity sha512-Z5fqHsaDN4FkWtPjTkhZDBy3uD4ir9L/ooqrNzOyyruDW6nCn/05AbC9HupxEIjlIoeT4bdrtChUllcU+cNgmg== + dependencies: + tslib "^1.10.0" + lower-case@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/lower-case/-/lower-case-2.0.1.tgz#39eeb36e396115cc05e29422eaea9e692c9408c7"