diff --git a/src/generated-client.js b/src/generated-client.js index 5478df913..8f2b99c13 100644 --- a/src/generated-client.js +++ b/src/generated-client.js @@ -215,7 +215,7 @@ class GeneratedApiClient { * Convenience method for /api/v1/apps/{appId}/credentials/csrs/{csrId}/lifecycle/publish * @returns {Promise} */ - publishCerCert(appId, csrId, string) { + publishCerCert(appId, csrId, certificate) { let url = `${this.baseUrl}/api/v1/apps/${appId}/credentials/csrs/${csrId}/lifecycle/publish`; const resources = [ @@ -224,7 +224,7 @@ class GeneratedApiClient { ]; const request = this.http.postJson(url, { - body: string + body: certificate }, {resources}); return request.then(jsonRes => new models.JsonWebKey(jsonRes, this)); } @@ -238,7 +238,7 @@ class GeneratedApiClient { * Convenience method for /api/v1/apps/{appId}/credentials/csrs/{csrId}/lifecycle/publish * @returns {Promise} */ - publishBinaryCerCert(appId, csrId, string) { + publishBinaryCerCert(appId, csrId, certificate) { let url = `${this.baseUrl}/api/v1/apps/${appId}/credentials/csrs/${csrId}/lifecycle/publish`; const resources = [ @@ -247,7 +247,7 @@ class GeneratedApiClient { ]; const request = this.http.postJson(url, { - body: string + body: certificate }, {resources}); return request.then(jsonRes => new models.JsonWebKey(jsonRes, this)); } @@ -261,7 +261,7 @@ class GeneratedApiClient { * Convenience method for /api/v1/apps/{appId}/credentials/csrs/{csrId}/lifecycle/publish * @returns {Promise} */ - publishDerCert(appId, csrId, string) { + publishDerCert(appId, csrId, certificate) { let url = `${this.baseUrl}/api/v1/apps/${appId}/credentials/csrs/${csrId}/lifecycle/publish`; const resources = [ @@ -270,7 +270,7 @@ class GeneratedApiClient { ]; const request = this.http.postJson(url, { - body: string + body: certificate }, {resources}); return request.then(jsonRes => new models.JsonWebKey(jsonRes, this)); } @@ -284,7 +284,7 @@ class GeneratedApiClient { * Convenience method for /api/v1/apps/{appId}/credentials/csrs/{csrId}/lifecycle/publish * @returns {Promise} */ - publishBinaryDerCert(appId, csrId, string) { + publishBinaryDerCert(appId, csrId, certificate) { let url = `${this.baseUrl}/api/v1/apps/${appId}/credentials/csrs/${csrId}/lifecycle/publish`; const resources = [ @@ -293,7 +293,7 @@ class GeneratedApiClient { ]; const request = this.http.postJson(url, { - body: string + body: certificate }, {resources}); return request.then(jsonRes => new models.JsonWebKey(jsonRes, this)); } @@ -307,7 +307,7 @@ class GeneratedApiClient { * Convenience method for /api/v1/apps/{appId}/credentials/csrs/{csrId}/lifecycle/publish * @returns {Promise} */ - publishBinaryPemCert(appId, csrId, string) { + publishBinaryPemCert(appId, csrId, certificate) { let url = `${this.baseUrl}/api/v1/apps/${appId}/credentials/csrs/${csrId}/lifecycle/publish`; const resources = [ @@ -316,7 +316,7 @@ class GeneratedApiClient { ]; const request = this.http.postJson(url, { - body: string + body: certificate }, {resources}); return request.then(jsonRes => new models.JsonWebKey(jsonRes, this)); } @@ -2378,7 +2378,7 @@ class GeneratedApiClient { * Update the CSR with a signed X.509 certificate and add it into the signing key credentials for the IdP. * @returns {Promise} */ - publishCerCertForIdentityProvider(idpId, csrId, string) { + publishCerCertForIdentityProvider(idpId, csrId, certificate) { let url = `${this.baseUrl}/api/v1/idps/${idpId}/credentials/csrs/${csrId}/lifecycle/publish`; const resources = [ @@ -2387,7 +2387,7 @@ class GeneratedApiClient { ]; const request = this.http.postJson(url, { - body: string + body: certificate }, {resources}); return request.then(jsonRes => new models.JsonWebKey(jsonRes, this)); } @@ -2401,7 +2401,7 @@ class GeneratedApiClient { * Update the CSR with a signed X.509 certificate and add it into the signing key credentials for the IdP. * @returns {Promise} */ - publishBinaryCerCertForIdentityProvider(idpId, csrId, string) { + publishBinaryCerCertForIdentityProvider(idpId, csrId, certificate) { let url = `${this.baseUrl}/api/v1/idps/${idpId}/credentials/csrs/${csrId}/lifecycle/publish`; const resources = [ @@ -2410,7 +2410,7 @@ class GeneratedApiClient { ]; const request = this.http.postJson(url, { - body: string + body: certificate }, {resources}); return request.then(jsonRes => new models.JsonWebKey(jsonRes, this)); } @@ -2424,7 +2424,7 @@ class GeneratedApiClient { * Update the CSR with a signed X.509 certificate and add it into the signing key credentials for the IdP. * @returns {Promise} */ - publishDerCertForIdentityProvider(idpId, csrId, string) { + publishDerCertForIdentityProvider(idpId, csrId, certificate) { let url = `${this.baseUrl}/api/v1/idps/${idpId}/credentials/csrs/${csrId}/lifecycle/publish`; const resources = [ @@ -2433,7 +2433,7 @@ class GeneratedApiClient { ]; const request = this.http.postJson(url, { - body: string + body: certificate }, {resources}); return request.then(jsonRes => new models.JsonWebKey(jsonRes, this)); } @@ -2447,7 +2447,7 @@ class GeneratedApiClient { * Update the CSR with a signed X.509 certificate and add it into the signing key credentials for the IdP. * @returns {Promise} */ - publishBinaryDerCertForIdentityProvider(idpId, csrId, string) { + publishBinaryDerCertForIdentityProvider(idpId, csrId, certificate) { let url = `${this.baseUrl}/api/v1/idps/${idpId}/credentials/csrs/${csrId}/lifecycle/publish`; const resources = [ @@ -2456,7 +2456,7 @@ class GeneratedApiClient { ]; const request = this.http.postJson(url, { - body: string + body: certificate }, {resources}); return request.then(jsonRes => new models.JsonWebKey(jsonRes, this)); } @@ -2470,7 +2470,7 @@ class GeneratedApiClient { * Update the CSR with a signed X.509 certificate and add it into the signing key credentials for the IdP. * @returns {Promise} */ - publishBinaryPemCertForIdentityProvider(idpId, csrId, string) { + publishBinaryPemCertForIdentityProvider(idpId, csrId, certificate) { let url = `${this.baseUrl}/api/v1/idps/${idpId}/credentials/csrs/${csrId}/lifecycle/publish`; const resources = [ @@ -2479,7 +2479,7 @@ class GeneratedApiClient { ]; const request = this.http.postJson(url, { - body: string + body: certificate }, {resources}); return request.then(jsonRes => new models.JsonWebKey(jsonRes, this)); } diff --git a/templates/generated-client.js.hbs b/templates/generated-client.js.hbs index 42ac31074..41cd19c52 100644 --- a/templates/generated-client.js.hbs +++ b/templates/generated-client.js.hbs @@ -45,11 +45,11 @@ class GeneratedApiClient { {{#if bodyModel}} {{#if responseModel}} const request = this.http.postJson(url, { - body: {{camelCase bodyModel}} + body: {{getBodyModelNameInCamelCase this}} }, {resources}); {{else}} const request = this.http.post(url, { - body: {{camelCase bodyModel}} + body: {{getBodyModelNameInCamelCase this}} }, {resources}); {{/if}} {{else}} @@ -64,11 +64,11 @@ class GeneratedApiClient { {{#if bodyModel}} {{#if responseModel}} const request = this.http.putJson(url, { - body: {{camelCase bodyModel}} + body: {{getBodyModelNameInCamelCase this}} }, {resources}); {{else}} const request = this.http.put(url, { - body: {{camelCase bodyModel}} + body: {{getBodyModelNameInCamelCase this}} }, {resources}); {{/if}} {{else}} diff --git a/templates/index.js b/templates/index.js index a2e5c699c..44d79e2a1 100644 --- a/templates/index.js +++ b/templates/index.js @@ -16,6 +16,18 @@ class ModelResolver { } } +const getBodyModelNameInCamelCase = operation => { + const { bodyModel, parameters } = operation; + let bodyModelName = bodyModel; + if (bodyModel === 'string') { + const bodyParam = parameters.find(param => param.in === 'body'); + if (bodyParam) { + bodyModelName = bodyParam.name; + } + } + return _.camelCase(bodyModelName); +}; + /** * This file is used by the @okta/openapi generator. It defines language-specific * post-processing of the JSON spec, as well as handebars helpers. This file is meant @@ -138,25 +150,29 @@ js.process = ({spec, operations, models, handlebars}) => { }); handlebars.registerHelper('operationArgumentBuilder', (operation) => { - const args = []; + const { bodyModel, method, pathParams, queryParams, parameters } = operation; - operation.pathParams.map((arg) => args.push(arg.name)); + const args = pathParams.reduce((acc, curr) => { + acc.push(curr.name); + return acc; + }, []); - if ( - !operation.isArray - && (operation.method === 'post' || operation.method === 'put') - && operation.bodyModel - ) { - args.push(_.camelCase(operation.bodyModel)); + if (!operation.isArray && (method === 'post' || method === 'put') && bodyModel) { + const bodyModelName = getBodyModelNameInCamelCase(operation); + if (bodyModelName) { + args.push(bodyModelName); + } } - if (operation.queryParams.length) { + if (queryParams.length) { args.push('queryParameters'); } return args.join(', '); }); + handlebars.registerHelper('getBodyModelNameInCamelCase', getBodyModelNameInCamelCase); + handlebars.registerHelper('modelMethodPublicArgumentBuilder', (method, modelName) => { const args = [];