Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support x-okta-multi-operation - OKTA-289242 #156

Merged
merged 1 commit into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/generated-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class GeneratedApiClient {
* Convenience method for /api/v1/apps/{appId}/credentials/csrs/{csrId}/lifecycle/publish
* @returns {Promise<JsonWebKey>}
*/
publishCerCert(appId, csrId, string) {
publishCerCert(appId, csrId, certificate) {
let url = `${this.baseUrl}/api/v1/apps/${appId}/credentials/csrs/${csrId}/lifecycle/publish`;

const resources = [
Expand All @@ -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));
}
Expand All @@ -238,7 +238,7 @@ class GeneratedApiClient {
* Convenience method for /api/v1/apps/{appId}/credentials/csrs/{csrId}/lifecycle/publish
* @returns {Promise<JsonWebKey>}
*/
publishBinaryCerCert(appId, csrId, string) {
publishBinaryCerCert(appId, csrId, certificate) {
let url = `${this.baseUrl}/api/v1/apps/${appId}/credentials/csrs/${csrId}/lifecycle/publish`;

const resources = [
Expand All @@ -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));
}
Expand All @@ -261,7 +261,7 @@ class GeneratedApiClient {
* Convenience method for /api/v1/apps/{appId}/credentials/csrs/{csrId}/lifecycle/publish
* @returns {Promise<JsonWebKey>}
*/
publishDerCert(appId, csrId, string) {
publishDerCert(appId, csrId, certificate) {
let url = `${this.baseUrl}/api/v1/apps/${appId}/credentials/csrs/${csrId}/lifecycle/publish`;

const resources = [
Expand All @@ -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));
}
Expand All @@ -284,7 +284,7 @@ class GeneratedApiClient {
* Convenience method for /api/v1/apps/{appId}/credentials/csrs/{csrId}/lifecycle/publish
* @returns {Promise<JsonWebKey>}
*/
publishBinaryDerCert(appId, csrId, string) {
publishBinaryDerCert(appId, csrId, certificate) {
let url = `${this.baseUrl}/api/v1/apps/${appId}/credentials/csrs/${csrId}/lifecycle/publish`;

const resources = [
Expand All @@ -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));
}
Expand All @@ -307,7 +307,7 @@ class GeneratedApiClient {
* Convenience method for /api/v1/apps/{appId}/credentials/csrs/{csrId}/lifecycle/publish
* @returns {Promise<JsonWebKey>}
*/
publishBinaryPemCert(appId, csrId, string) {
publishBinaryPemCert(appId, csrId, certificate) {
let url = `${this.baseUrl}/api/v1/apps/${appId}/credentials/csrs/${csrId}/lifecycle/publish`;

const resources = [
Expand All @@ -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));
}
Expand Down Expand Up @@ -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<JsonWebKey>}
*/
publishCerCertForIdentityProvider(idpId, csrId, string) {
publishCerCertForIdentityProvider(idpId, csrId, certificate) {
let url = `${this.baseUrl}/api/v1/idps/${idpId}/credentials/csrs/${csrId}/lifecycle/publish`;

const resources = [
Expand All @@ -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));
}
Expand All @@ -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<JsonWebKey>}
*/
publishBinaryCerCertForIdentityProvider(idpId, csrId, string) {
publishBinaryCerCertForIdentityProvider(idpId, csrId, certificate) {
let url = `${this.baseUrl}/api/v1/idps/${idpId}/credentials/csrs/${csrId}/lifecycle/publish`;

const resources = [
Expand All @@ -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));
}
Expand All @@ -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<JsonWebKey>}
*/
publishDerCertForIdentityProvider(idpId, csrId, string) {
publishDerCertForIdentityProvider(idpId, csrId, certificate) {
let url = `${this.baseUrl}/api/v1/idps/${idpId}/credentials/csrs/${csrId}/lifecycle/publish`;

const resources = [
Expand All @@ -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));
}
Expand All @@ -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<JsonWebKey>}
*/
publishBinaryDerCertForIdentityProvider(idpId, csrId, string) {
publishBinaryDerCertForIdentityProvider(idpId, csrId, certificate) {
let url = `${this.baseUrl}/api/v1/idps/${idpId}/credentials/csrs/${csrId}/lifecycle/publish`;

const resources = [
Expand All @@ -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));
}
Expand All @@ -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<JsonWebKey>}
*/
publishBinaryPemCertForIdentityProvider(idpId, csrId, string) {
publishBinaryPemCertForIdentityProvider(idpId, csrId, certificate) {
let url = `${this.baseUrl}/api/v1/idps/${idpId}/credentials/csrs/${csrId}/lifecycle/publish`;

const resources = [
Expand All @@ -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));
}
Expand Down
8 changes: 4 additions & 4 deletions templates/generated-client.js.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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}}
Expand Down
34 changes: 25 additions & 9 deletions templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [];
Expand Down