diff --git a/modules/openapi-generator/src/main/resources/zapier/api.mustache b/modules/openapi-generator/src/main/resources/zapier/api.mustache index 7b49251f5609..c3e525624012 100644 --- a/modules/openapi-generator/src/main/resources/zapier/api.mustache +++ b/modules/openapi-generator/src/main/resources/zapier/api.mustache @@ -104,7 +104,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, '{{operationId}}', response.json); return {{#returnType}}{{#returnTypeIsPrimitive}}{ data: results }{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}results{{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}results{{/returnType}}; }) }, diff --git a/modules/openapi-generator/src/main/resources/zapier/utils.mustache b/modules/openapi-generator/src/main/resources/zapier/utils.mustache index 7690a1cda1ea..3c787e051e1b 100644 --- a/modules/openapi-generator/src/main/resources/zapier/utils.mustache +++ b/modules/openapi-generator/src/main/resources/zapier/utils.mustache @@ -28,13 +28,6 @@ const isCreateAction = (key) => { return !isSearchAction(key); } -const requestOptionsMiddleware = (z, bundle, requestOptions) => { - // TODO: modify the request options for all outgoing request to your api - // if you are using session authentication without a Bearer token. - // This may be true if your API uses basic authentication or api keys. - return requestOptions -} - const isTrigger = (key) => { // TODO: custom logic return false @@ -44,6 +37,24 @@ const triggerMiddleware = (action) => { return action } +const requestOptionsMiddleware = (z, bundle, requestOptions) => { + // TODO: modify the request options for all outgoing request to your api + // if you are using session authentication without a Bearer token. + // This may be true if your API uses basic authentication or api keys. + return requestOptions +} + +const responseOptionsMiddleware = (z, bundle, key, json) => { + // TODO: modify if your response needs to be transformed before returning the + // data to Zapier. For example, you may need to map an id field to the + // "id" field. For example, map "contactId": 1 to "id": 1. Or wrap your + // response in a json object. For example, { data: response }. + // + // Note that if the type being returned from the endpoint is a primitive + // type, the response is automatically wrapped like this: { data: response }. + return json +} + module.exports = { replacePathParameters: replacePathParameters, childMapping: childMapping, @@ -53,6 +64,7 @@ module.exports = { isSearchAction: isSearchAction, searchMiddleware: searchMiddleware, requestOptionsMiddleware: requestOptionsMiddleware, + responseOptionsMiddleware: responseOptionsMiddleware, isTrigger: isTrigger, triggerMiddleware: triggerMiddleware, isCreateAction: isCreateAction, diff --git a/samples/client/petstore/zapier/apis/PetApi.js b/samples/client/petstore/zapier/apis/PetApi.js index 88c4c34898a3..3bf6e365b813 100644 --- a/samples/client/petstore/zapier/apis/PetApi.js +++ b/samples/client/petstore/zapier/apis/PetApi.js @@ -37,7 +37,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'addPet', response.json); return results; }) }, @@ -84,7 +84,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'deletePet', response.json); return results; }) }, @@ -126,7 +126,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'findPetsByStatus', response.json); return results; }) }, @@ -168,7 +168,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'findPetsByTags', response.json); return results; }) }, @@ -211,7 +211,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'getPetById', response.json); return results; }) }, @@ -250,7 +250,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'updatePet', response.json); return results; }) }, @@ -302,7 +302,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'updatePetWithForm', response.json); return results; }) }, @@ -358,7 +358,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'uploadFile', response.json); return results; }) }, diff --git a/samples/client/petstore/zapier/apis/StoreApi.js b/samples/client/petstore/zapier/apis/StoreApi.js index bb5d80be83bf..067b6841cff9 100644 --- a/samples/client/petstore/zapier/apis/StoreApi.js +++ b/samples/client/petstore/zapier/apis/StoreApi.js @@ -38,7 +38,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'deleteOrder', response.json); return results; }) }, @@ -74,7 +74,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'getInventory', response.json); return { data: results }; }) }, @@ -117,7 +117,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'getOrderById', response.json); return results; }) }, @@ -156,7 +156,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'placeOrder', response.json); return results; }) }, diff --git a/samples/client/petstore/zapier/apis/UserApi.js b/samples/client/petstore/zapier/apis/UserApi.js index 8138b724a504..166eeae0dcfa 100644 --- a/samples/client/petstore/zapier/apis/UserApi.js +++ b/samples/client/petstore/zapier/apis/UserApi.js @@ -34,7 +34,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'createUser', response.json); return results; }) }, @@ -76,7 +76,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'createUsersWithArrayInput', response.json); return results; }) }, @@ -118,7 +118,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'createUsersWithListInput', response.json); return results; }) }, @@ -160,7 +160,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'deleteUser', response.json); return results; }) }, @@ -203,7 +203,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'getUserByName', response.json); return results; }) }, @@ -253,7 +253,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'loginUser', response.json); return { data: results }; }) }, @@ -289,7 +289,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'logoutUser', response.json); return results; }) }, @@ -333,7 +333,7 @@ module.exports = { } return z.request(utils.requestOptionsMiddleware(z, bundle, options)).then((response) => { response.throwForStatus(); - const results = response.json; + const results = utils.responseOptionsMiddleware(z, bundle, 'updateUser', response.json); return results; }) }, diff --git a/samples/client/petstore/zapier/utils/utils.js b/samples/client/petstore/zapier/utils/utils.js index 7690a1cda1ea..3c787e051e1b 100644 --- a/samples/client/petstore/zapier/utils/utils.js +++ b/samples/client/petstore/zapier/utils/utils.js @@ -28,13 +28,6 @@ const isCreateAction = (key) => { return !isSearchAction(key); } -const requestOptionsMiddleware = (z, bundle, requestOptions) => { - // TODO: modify the request options for all outgoing request to your api - // if you are using session authentication without a Bearer token. - // This may be true if your API uses basic authentication or api keys. - return requestOptions -} - const isTrigger = (key) => { // TODO: custom logic return false @@ -44,6 +37,24 @@ const triggerMiddleware = (action) => { return action } +const requestOptionsMiddleware = (z, bundle, requestOptions) => { + // TODO: modify the request options for all outgoing request to your api + // if you are using session authentication without a Bearer token. + // This may be true if your API uses basic authentication or api keys. + return requestOptions +} + +const responseOptionsMiddleware = (z, bundle, key, json) => { + // TODO: modify if your response needs to be transformed before returning the + // data to Zapier. For example, you may need to map an id field to the + // "id" field. For example, map "contactId": 1 to "id": 1. Or wrap your + // response in a json object. For example, { data: response }. + // + // Note that if the type being returned from the endpoint is a primitive + // type, the response is automatically wrapped like this: { data: response }. + return json +} + module.exports = { replacePathParameters: replacePathParameters, childMapping: childMapping, @@ -53,6 +64,7 @@ module.exports = { isSearchAction: isSearchAction, searchMiddleware: searchMiddleware, requestOptionsMiddleware: requestOptionsMiddleware, + responseOptionsMiddleware: responseOptionsMiddleware, isTrigger: isTrigger, triggerMiddleware: triggerMiddleware, isCreateAction: isCreateAction,