From b022235b253bb5433fdd80bafa0522dc8cbfda33 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 18 Jul 2019 14:37:15 +0900 Subject: [PATCH] remove test service (#3379) --- .../languages/NodeJSExpressServerCodegen.java | 2 - .../services/index.mustache | 2 - .../services/test.mustache | 113 ------------------ .../.openapi-generator/VERSION | 2 +- .../services/TestService.js | 113 ------------------ .../nodejs-express-server/services/index.js | 2 - 6 files changed, 1 insertion(+), 233 deletions(-) delete mode 100644 modules/openapi-generator/src/main/resources/nodejs-express-server/services/test.mustache delete mode 100644 samples/server/petstore/nodejs-express-server/services/TestService.js diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/NodeJSExpressServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/NodeJSExpressServerCodegen.java index 1ae10d803e7a..d89fb863fa8e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/NodeJSExpressServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/NodeJSExpressServerCodegen.java @@ -26,7 +26,6 @@ import io.swagger.v3.oas.models.Paths; import io.swagger.v3.oas.models.info.Info; import org.openapitools.codegen.*; -import org.openapitools.codegen.config.GeneratorProperties; import org.openapitools.codegen.meta.GeneratorMetadata; import org.openapitools.codegen.meta.Stability; import org.openapitools.codegen.utils.URLPathUtils; @@ -98,7 +97,6 @@ public NodeJSExpressServerCodegen() { supportingFiles.add(new SupportingFile("controllers" + File.separator + "index.mustache", "controllers", "index.js")); supportingFiles.add(new SupportingFile("controllers" + File.separator + "Controller.mustache", "controllers", "Controller.js")); // service folder - supportingFiles.add(new SupportingFile("services" + File.separator + "test.mustache", "services", "TestService.js")); supportingFiles.add(new SupportingFile("services" + File.separator + "index.mustache", "services", "index.js")); supportingFiles.add(new SupportingFile("services" + File.separator + "Service.mustache", "services", "Service.js")); diff --git a/modules/openapi-generator/src/main/resources/nodejs-express-server/services/index.mustache b/modules/openapi-generator/src/main/resources/nodejs-express-server/services/index.mustache index 4a122c0a2496..19478453fa8f 100644 --- a/modules/openapi-generator/src/main/resources/nodejs-express-server/services/index.mustache +++ b/modules/openapi-generator/src/main/resources/nodejs-express-server/services/index.mustache @@ -9,7 +9,6 @@ const {{classname}}Service = require('./{{classname}}Service'); {{/operations}} {{/apis}} {{/apiInfo}} -const TestService = require('./TestService'); module.exports = { {{#apiInfo}} @@ -23,5 +22,4 @@ module.exports = { {{/operations}} {{/apis}} {{/apiInfo}} - TestService, }; diff --git a/modules/openapi-generator/src/main/resources/nodejs-express-server/services/test.mustache b/modules/openapi-generator/src/main/resources/nodejs-express-server/services/test.mustache deleted file mode 100644 index 8ecd49dbf89b..000000000000 --- a/modules/openapi-generator/src/main/resources/nodejs-express-server/services/test.mustache +++ /dev/null @@ -1,113 +0,0 @@ -const Service = require('./Service'); - -const testItems = require('../tests/testFiles/testItems.json'); - -class TestService { - static testGetController() { - return new Promise( - async (resolve, reject) => { - try { - resolve(Service.successResponse( - testItems, - 200, - )); - } catch (e) { - const message = e.getMessage() || 'Could not get items. Server error'; - reject(Service.rejectResponse(message, 500)); - } - }, - ); - } - - static testDeleteController({ itemId }) { - return new Promise( - async (resolve, reject) => { - try { - let responseMessage = ''; - const itemToDeleteIndex = testItems.findIndex(item => item.id === itemId); - if (itemToDeleteIndex > -1) { - testItems.splice(itemToDeleteIndex, 1); - responseMessage = `test item id ${itemId} deleted successfully`; - } else { - responseMessage = 'test item not found, nothing changed'; - } - resolve(Service.successResponse(responseMessage, 200)); - } catch (err) { - const message = err.getMessage() || 'Invalid test item value'; - const code = err.status || 400; - reject(Service.rejectResponse(message, code)); - } - }, - ); - } - - static testPostController({ testItem }) { - return new Promise( - async (resolve, reject) => { - try { - const highestId = testItems[testItems.length - 1].id; - const newItem = { - id: highestId + 1, - name: testItem.name, - description: testItem.description, - version: testItem.version, - }; - testItems.push(newItem); - resolve(Service.successResponse(newItem)); - } catch (e) { - reject(Service.rejectResponse( - e.getMessage() || 'Invalid input', - e.status || 405, - )); - } - }, - ); - } - - static testFindByIdController({ itemId }) { - return new Promise( - async (resolve, reject) => { - try { - const itemFound = testItems.find(item => item.id === itemId); - if (itemFound !== undefined) { - resolve(Service.successResponse(itemFound, 200)); - } else { - reject(Service.rejectResponse('item not found', 404)); - } - } catch (e) { - reject(Service.rejectResponse(e.getMessage() || 'Invalid ID supplied', 400)); - } - }, - ); - } - - static testPutController({ itemId, testItem }) { - return new Promise( - async (resolve, reject) => { - try { - let responseBody; - const itemToUpdate = testItems.find(item => item.id === itemId); - if (itemToUpdate !== undefined) { - itemToUpdate.name = testItem.name || itemToUpdate.name; - itemToUpdate.description = testItem.description || itemToUpdate.description; - itemToUpdate.version = testItem.version || itemToUpdate.version; - responseBody = itemToUpdate; - } else { - responseBody = `could not find an item with id ${itemId} to update. Nothing changed`; - } - resolve(Service.successResponse( - responseBody, - 200, - )); - } catch (e) { - reject(Service.rejectResponse( - e.getMessage || 'Invalid input', - 405, - )); - } - }, - ); - } -} - -module.exports = TestService; diff --git a/samples/server/petstore/nodejs-express-server/.openapi-generator/VERSION b/samples/server/petstore/nodejs-express-server/.openapi-generator/VERSION index 479c313e87b9..83a328a9227e 100644 --- a/samples/server/petstore/nodejs-express-server/.openapi-generator/VERSION +++ b/samples/server/petstore/nodejs-express-server/.openapi-generator/VERSION @@ -1 +1 @@ -4.0.3-SNAPSHOT \ No newline at end of file +4.1.0-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/nodejs-express-server/services/TestService.js b/samples/server/petstore/nodejs-express-server/services/TestService.js deleted file mode 100644 index 8ecd49dbf89b..000000000000 --- a/samples/server/petstore/nodejs-express-server/services/TestService.js +++ /dev/null @@ -1,113 +0,0 @@ -const Service = require('./Service'); - -const testItems = require('../tests/testFiles/testItems.json'); - -class TestService { - static testGetController() { - return new Promise( - async (resolve, reject) => { - try { - resolve(Service.successResponse( - testItems, - 200, - )); - } catch (e) { - const message = e.getMessage() || 'Could not get items. Server error'; - reject(Service.rejectResponse(message, 500)); - } - }, - ); - } - - static testDeleteController({ itemId }) { - return new Promise( - async (resolve, reject) => { - try { - let responseMessage = ''; - const itemToDeleteIndex = testItems.findIndex(item => item.id === itemId); - if (itemToDeleteIndex > -1) { - testItems.splice(itemToDeleteIndex, 1); - responseMessage = `test item id ${itemId} deleted successfully`; - } else { - responseMessage = 'test item not found, nothing changed'; - } - resolve(Service.successResponse(responseMessage, 200)); - } catch (err) { - const message = err.getMessage() || 'Invalid test item value'; - const code = err.status || 400; - reject(Service.rejectResponse(message, code)); - } - }, - ); - } - - static testPostController({ testItem }) { - return new Promise( - async (resolve, reject) => { - try { - const highestId = testItems[testItems.length - 1].id; - const newItem = { - id: highestId + 1, - name: testItem.name, - description: testItem.description, - version: testItem.version, - }; - testItems.push(newItem); - resolve(Service.successResponse(newItem)); - } catch (e) { - reject(Service.rejectResponse( - e.getMessage() || 'Invalid input', - e.status || 405, - )); - } - }, - ); - } - - static testFindByIdController({ itemId }) { - return new Promise( - async (resolve, reject) => { - try { - const itemFound = testItems.find(item => item.id === itemId); - if (itemFound !== undefined) { - resolve(Service.successResponse(itemFound, 200)); - } else { - reject(Service.rejectResponse('item not found', 404)); - } - } catch (e) { - reject(Service.rejectResponse(e.getMessage() || 'Invalid ID supplied', 400)); - } - }, - ); - } - - static testPutController({ itemId, testItem }) { - return new Promise( - async (resolve, reject) => { - try { - let responseBody; - const itemToUpdate = testItems.find(item => item.id === itemId); - if (itemToUpdate !== undefined) { - itemToUpdate.name = testItem.name || itemToUpdate.name; - itemToUpdate.description = testItem.description || itemToUpdate.description; - itemToUpdate.version = testItem.version || itemToUpdate.version; - responseBody = itemToUpdate; - } else { - responseBody = `could not find an item with id ${itemId} to update. Nothing changed`; - } - resolve(Service.successResponse( - responseBody, - 200, - )); - } catch (e) { - reject(Service.rejectResponse( - e.getMessage || 'Invalid input', - 405, - )); - } - }, - ); - } -} - -module.exports = TestService; diff --git a/samples/server/petstore/nodejs-express-server/services/index.js b/samples/server/petstore/nodejs-express-server/services/index.js index ca9599851baf..bdf3c87fb749 100644 --- a/samples/server/petstore/nodejs-express-server/services/index.js +++ b/samples/server/petstore/nodejs-express-server/services/index.js @@ -1,11 +1,9 @@ const PetService = require('./PetService'); const StoreService = require('./StoreService'); const UserService = require('./UserService'); -const TestService = require('./TestService'); module.exports = { PetService, StoreService, UserService, - TestService, };