diff --git a/.travis.yml b/.travis.yml index 9e9a06d..3cb523e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ +dist: trusty + language: node_js sudo: required diff --git a/package-lock.json b/package-lock.json index 772dc80..5983d40 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "raml-javascript-generator", - "version": "2.1.2", + "version": "2.1.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index f1bd6d6..23b0d78 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "raml-javascript-generator", - "version": "2.1.2", + "version": "2.1.3", "description": "Generate a JavaScript API client from RAML", "main": "dist/index.js", "config": { diff --git a/src/support/method.ts b/src/support/method.ts index 8b0bfe9..27fe337 100644 --- a/src/support/method.ts +++ b/src/support/method.ts @@ -25,8 +25,7 @@ export function getRequestSnippet(method: any, resource: any) { } const parts = resource.relativeUri.split(/(?=[\/\.])/g); - - return parts.map((part: string) => { + const requestMethod = parts.map((part: string) => { const methodName = toMethodName(part); const uriParams = Object.keys(getUsedUriParameters(part, resource.uriParameters)); @@ -35,7 +34,9 @@ export function getRequestSnippet(method: any, resource: any) { } return `${methodName}`; - }).join('.') + `.${camelCase(method.method)}([${type}, [options]])`; + }).join('.'); + + return `${requestMethod}.${camelCase(method.method)}([${type}, [options]])`; } /** diff --git a/src/templates/index.js.ts b/src/templates/index.js.ts index e87d632..cc2fb88 100644 --- a/src/templates/index.js.ts +++ b/src/templates/index.js.ts @@ -186,7 +186,7 @@ const request = (client, method, path, opts) => { } // Create prototype resources. - private createProtoResources(withParams: KeyedNestedResources, noParams: KeyedNestedResources) { + private createProtoResources(withParams: KeyedNestedResources, client: string, noParams: KeyedNestedResources) { for (const key of Object.keys(withParams)) { const child = withParams[key]; @@ -196,7 +196,7 @@ const request = (client, method, path, opts) => { } this.buffer.append(`\n`); - this.buffer.append(` ${child.methodName}${this.toParamsMethod(child, 'this.client', true)}`); + this.buffer.append(` ${child.methodName}${this.toParamsMethod(child, client, true)}`); } } @@ -223,7 +223,7 @@ const request = (client, method, path, opts) => { this.createThisResources(withParams, noParams, 'this.client'); this.buffer.line(` }`); - this.createProtoResources(withParams, noParams); + this.createProtoResources(withParams, 'this.client', noParams); this.createProtoMethods(resource.methods, 'this.client', 'this.path'); if (className.indexOf('.') > 0) { this.buffer.line(`};`); @@ -368,7 +368,7 @@ class Client { } } this.createProtoMethods(this.nestedTree.methods, 'this', `''`); - this.createProtoResources(this.withParams, this.noParams); + this.createProtoResources(this.withParams, 'this', this.noParams); this.buffer.line(`}`); } @@ -382,7 +382,7 @@ class Client { if (scheme.type === 'OAuth 2.0') { this.buffer.return(); - this.buffer.line('// eslint-disable-next-line'); + this.buffer.line(' // eslint-disable-next-line'); this.buffer.line(` ${name}: function ${name}(options) {`); this.buffer.multiline(` const schemeSettings = ${this.formatJSON(scheme.settings, 2, 4)};`); this.buffer.line(` return new ClientOAuth2(Object.assign(schemeSettings, options));`); diff --git a/src/templates/package.json.ts b/src/templates/package.json.ts index a8c883c..2ff15de 100644 --- a/src/templates/package.json.ts +++ b/src/templates/package.json.ts @@ -35,5 +35,5 @@ export const packageTemplate = (api: Api) => { } }; - return JSON.stringify(json, null, 2) + '\n'; + return `${JSON.stringify(json, null, 2)}\n`; };