From 59ff4c198be4581fd6edcf30a2784828b568cf9f Mon Sep 17 00:00:00 2001 From: ccozzolino Date: Sat, 20 Jan 2018 00:31:06 -0600 Subject: [PATCH] =?UTF-8?q?[Java][library:=20vertx]=20Add=20default=20valu?= =?UTF-8?q?e=20and=20required=20parameter=20support=20to=20vertx=20server?= =?UTF-8?q?=20temp=E2=80=A6=20(#7410)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add default value and required parameter support to vertx server templates. Fix for #7409. * Added missing serviceId declaration to workaround #allParams section clearing the vendorExtensions map --- .../JavaVertXServer/apiVerticle.mustache | 48 +++++++++- .../java-vertx/async/.swagger-codegen/VERSION | 2 +- .../server/api/verticle/PetApiVerticle.java | 95 ++++++++++++++++--- .../server/api/verticle/StoreApiVerticle.java | 29 +++++- .../server/api/verticle/UserApiVerticle.java | 83 +++++++++++++--- .../java-vertx/rx/.swagger-codegen/VERSION | 2 +- .../server/api/verticle/PetApiVerticle.java | 95 ++++++++++++++++--- .../server/api/verticle/StoreApiVerticle.java | 29 +++++- .../server/api/verticle/UserApiVerticle.java | 83 +++++++++++++--- 9 files changed, 401 insertions(+), 65 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/apiVerticle.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/apiVerticle.mustache index 74b976f66a..ad95c32825 100644 --- a/modules/swagger-codegen/src/main/resources/JavaVertXServer/apiVerticle.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/apiVerticle.mustache @@ -37,23 +37,61 @@ public class {{classname}}Verticle extends AbstractVerticle { //Consumer for {{#vendorExtensions}}{{x-serviceid}}{{/vendorExtensions}} vertx.eventBus(). consumer({{#vendorExtensions}}{{x-serviceid-varname}}{{/vendorExtensions}}).handler(message -> { try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "{{#vendorExtensions}}{{x-serviceid}}{{/vendorExtensions}}"; {{#hasParams}} {{#allParams}} {{#isListContainer}} - {{{dataType}}} {{paramName}} = Json.mapper.readValue(message.body().getJsonArray("{{baseName}}").encode(), - Json.mapper.getTypeFactory().constructCollectionType(List.class, {{{baseType}}}.class)); + JsonArray {{paramName}}Param = message.body().getJsonArray("{{baseName}}"); + {{#required}} + if({{paramName}}Param == null) { + manageError(message, new MainApiException(400, "{{baseName}} is required"), serviceId); + return; + } + {{{dataType}}} {{paramName}} = Json.mapper.readValue({{paramName}}Param.encode(), + Json.mapper.getTypeFactory().constructCollectionType(List.class, {{{baseType}}}.class)); + {{/required}} + {{^required}} + {{{dataType}}} {{paramName}} = ({{paramName}}Param == null) ? {{#defaultValue}}{{defaultValue}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}} : Json.mapper.readValue({{paramName}}Param.encode(), + Json.mapper.getTypeFactory().constructCollectionType(List.class, {{{baseType}}}.class)); + {{/required}} {{/isListContainer}} {{^isListContainer}} {{#isPrimitiveType}} {{#isString}} - {{{dataType}}} {{paramName}} = message.body().getString("{{baseName}}"); + String {{paramName}}Param = message.body().getString("{{baseName}}"); + {{#required}} + if({{paramName}}Param == null) { + manageError(message, new MainApiException(400, "{{baseName}} is required"), serviceId); + return; + } + {{{dataType}}} {{paramName}} = {{paramName}}Param; + {{/required}} + {{^required}} + {{{dataType}}} {{paramName}} = ({{paramName}}Param == null) ? {{#defaultValue}}{{defaultValue}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}} : {{paramName}}Param; + {{/required}} {{/isString}} {{^isString}} - {{{dataType}}} {{paramName}} = Json.mapper.readValue(message.body().getString("{{baseName}}"), {{{dataType}}}.class); + String {{paramName}}Param = message.body().getString("{{baseName}}"); + {{#required}} + if({{paramName}}Param == null) { + manageError(message, new MainApiException(400, "{{baseName}} is required"), serviceId); + return; + } + {{{dataType}}} {{paramName}} = Json.mapper.readValue({{paramName}}Param, {{{dataType}}}.class); + {{/required}} + {{^required}} + {{{dataType}}} {{paramName}} = ({{paramName}}Param == null) ? {{#defaultValue}}{{defaultValue}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}} : Json.mapper.readValue({{paramName}}Param, {{{dataType}}}.class); + {{/required}} {{/isString}} {{/isPrimitiveType}} {{^isPrimitiveType}} - {{{dataType}}} {{paramName}} = Json.mapper.readValue(message.body().getJsonObject("{{baseName}}").encode(), {{{dataType}}}.class); + JsonObject {{paramName}}Param = message.body().getJsonObject("{{baseName}}"); + if ({{paramName}}Param == null) { + manageError(message, new MainApiException(400, "{{baseName}} is required"), serviceId); + return; + } + {{{dataType}}} {{paramName}} = Json.mapper.readValue({{paramName}}Param.encode(), {{{dataType}}}.class); {{/isPrimitiveType}} {{/isListContainer}} {{/allParams}} diff --git a/samples/server/petstore/java-vertx/async/.swagger-codegen/VERSION b/samples/server/petstore/java-vertx/async/.swagger-codegen/VERSION index 50794f17f1..a6254504e4 100644 --- a/samples/server/petstore/java-vertx/async/.swagger-codegen/VERSION +++ b/samples/server/petstore/java-vertx/async/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.1-SNAPSHOT \ No newline at end of file +2.3.1 \ No newline at end of file diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/PetApiVerticle.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/PetApiVerticle.java index f97369e6ad..4746d13428 100644 --- a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/PetApiVerticle.java +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/PetApiVerticle.java @@ -46,7 +46,14 @@ public class PetApiVerticle extends AbstractVerticle { //Consumer for addPet vertx.eventBus(). consumer(ADDPET_SERVICE_ID).handler(message -> { try { - Pet body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), Pet.class); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "addPet"; + JsonObject bodyParam = message.body().getJsonObject("body"); + if (bodyParam == null) { + manageError(message, new MainApiException(400, "body is required"), serviceId); + return; + } + Pet body = Json.mapper.readValue(bodyParam.encode(), Pet.class); service.addPet(body, result -> { if (result.succeeded()) message.reply(null); @@ -64,8 +71,16 @@ public class PetApiVerticle extends AbstractVerticle { //Consumer for deletePet vertx.eventBus(). consumer(DELETEPET_SERVICE_ID).handler(message -> { try { - Long petId = Json.mapper.readValue(message.body().getString("petId"), Long.class); - String apiKey = message.body().getString("api_key"); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "deletePet"; + String petIdParam = message.body().getString("petId"); + if(petIdParam == null) { + manageError(message, new MainApiException(400, "petId is required"), serviceId); + return; + } + Long petId = Json.mapper.readValue(petIdParam, Long.class); + String apiKeyParam = message.body().getString("api_key"); + String apiKey = (apiKeyParam == null) ? null : apiKeyParam; service.deletePet(petId, apiKey, result -> { if (result.succeeded()) message.reply(null); @@ -83,8 +98,15 @@ public class PetApiVerticle extends AbstractVerticle { //Consumer for findPetsByStatus vertx.eventBus(). consumer(FINDPETSBYSTATUS_SERVICE_ID).handler(message -> { try { - List status = Json.mapper.readValue(message.body().getJsonArray("status").encode(), - Json.mapper.getTypeFactory().constructCollectionType(List.class, String.class)); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "findPetsByStatus"; + JsonArray statusParam = message.body().getJsonArray("status"); + if(statusParam == null) { + manageError(message, new MainApiException(400, "status is required"), serviceId); + return; + } + List status = Json.mapper.readValue(statusParam.encode(), + Json.mapper.getTypeFactory().constructCollectionType(List.class, String.class)); service.findPetsByStatus(status, result -> { if (result.succeeded()) message.reply(new JsonArray(Json.encode(result.result())).encodePrettily()); @@ -102,8 +124,15 @@ public class PetApiVerticle extends AbstractVerticle { //Consumer for findPetsByTags vertx.eventBus(). consumer(FINDPETSBYTAGS_SERVICE_ID).handler(message -> { try { - List tags = Json.mapper.readValue(message.body().getJsonArray("tags").encode(), - Json.mapper.getTypeFactory().constructCollectionType(List.class, String.class)); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "findPetsByTags"; + JsonArray tagsParam = message.body().getJsonArray("tags"); + if(tagsParam == null) { + manageError(message, new MainApiException(400, "tags is required"), serviceId); + return; + } + List tags = Json.mapper.readValue(tagsParam.encode(), + Json.mapper.getTypeFactory().constructCollectionType(List.class, String.class)); service.findPetsByTags(tags, result -> { if (result.succeeded()) message.reply(new JsonArray(Json.encode(result.result())).encodePrettily()); @@ -121,7 +150,14 @@ public class PetApiVerticle extends AbstractVerticle { //Consumer for getPetById vertx.eventBus(). consumer(GETPETBYID_SERVICE_ID).handler(message -> { try { - Long petId = Json.mapper.readValue(message.body().getString("petId"), Long.class); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "getPetById"; + String petIdParam = message.body().getString("petId"); + if(petIdParam == null) { + manageError(message, new MainApiException(400, "petId is required"), serviceId); + return; + } + Long petId = Json.mapper.readValue(petIdParam, Long.class); service.getPetById(petId, result -> { if (result.succeeded()) message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); @@ -139,7 +175,14 @@ public class PetApiVerticle extends AbstractVerticle { //Consumer for updatePet vertx.eventBus(). consumer(UPDATEPET_SERVICE_ID).handler(message -> { try { - Pet body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), Pet.class); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "updatePet"; + JsonObject bodyParam = message.body().getJsonObject("body"); + if (bodyParam == null) { + manageError(message, new MainApiException(400, "body is required"), serviceId); + return; + } + Pet body = Json.mapper.readValue(bodyParam.encode(), Pet.class); service.updatePet(body, result -> { if (result.succeeded()) message.reply(null); @@ -157,9 +200,18 @@ public class PetApiVerticle extends AbstractVerticle { //Consumer for updatePetWithForm vertx.eventBus(). consumer(UPDATEPETWITHFORM_SERVICE_ID).handler(message -> { try { - Long petId = Json.mapper.readValue(message.body().getString("petId"), Long.class); - String name = message.body().getString("name"); - String status = message.body().getString("status"); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "updatePetWithForm"; + String petIdParam = message.body().getString("petId"); + if(petIdParam == null) { + manageError(message, new MainApiException(400, "petId is required"), serviceId); + return; + } + Long petId = Json.mapper.readValue(petIdParam, Long.class); + String nameParam = message.body().getString("name"); + String name = (nameParam == null) ? null : nameParam; + String statusParam = message.body().getString("status"); + String status = (statusParam == null) ? null : statusParam; service.updatePetWithForm(petId, name, status, result -> { if (result.succeeded()) message.reply(null); @@ -177,9 +229,22 @@ public class PetApiVerticle extends AbstractVerticle { //Consumer for uploadFile vertx.eventBus(). consumer(UPLOADFILE_SERVICE_ID).handler(message -> { try { - Long petId = Json.mapper.readValue(message.body().getString("petId"), Long.class); - String additionalMetadata = message.body().getString("additionalMetadata"); - File file = Json.mapper.readValue(message.body().getJsonObject("file").encode(), File.class); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "uploadFile"; + String petIdParam = message.body().getString("petId"); + if(petIdParam == null) { + manageError(message, new MainApiException(400, "petId is required"), serviceId); + return; + } + Long petId = Json.mapper.readValue(petIdParam, Long.class); + String additionalMetadataParam = message.body().getString("additionalMetadata"); + String additionalMetadata = (additionalMetadataParam == null) ? null : additionalMetadataParam; + JsonObject fileParam = message.body().getJsonObject("file"); + if (fileParam == null) { + manageError(message, new MainApiException(400, "file is required"), serviceId); + return; + } + File file = Json.mapper.readValue(fileParam.encode(), File.class); service.uploadFile(petId, additionalMetadata, file, result -> { if (result.succeeded()) message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/StoreApiVerticle.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/StoreApiVerticle.java index cc11fa49a2..e2f608589b 100644 --- a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/StoreApiVerticle.java +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/StoreApiVerticle.java @@ -40,7 +40,14 @@ public class StoreApiVerticle extends AbstractVerticle { //Consumer for deleteOrder vertx.eventBus(). consumer(DELETEORDER_SERVICE_ID).handler(message -> { try { - String orderId = message.body().getString("orderId"); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "deleteOrder"; + String orderIdParam = message.body().getString("orderId"); + if(orderIdParam == null) { + manageError(message, new MainApiException(400, "orderId is required"), serviceId); + return; + } + String orderId = orderIdParam; service.deleteOrder(orderId, result -> { if (result.succeeded()) message.reply(null); @@ -58,6 +65,8 @@ public class StoreApiVerticle extends AbstractVerticle { //Consumer for getInventory vertx.eventBus(). consumer(GETINVENTORY_SERVICE_ID).handler(message -> { try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "getInventory"; service.getInventory(result -> { if (result.succeeded()) message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); @@ -75,7 +84,14 @@ public class StoreApiVerticle extends AbstractVerticle { //Consumer for getOrderById vertx.eventBus(). consumer(GETORDERBYID_SERVICE_ID).handler(message -> { try { - Long orderId = Json.mapper.readValue(message.body().getString("orderId"), Long.class); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "getOrderById"; + String orderIdParam = message.body().getString("orderId"); + if(orderIdParam == null) { + manageError(message, new MainApiException(400, "orderId is required"), serviceId); + return; + } + Long orderId = Json.mapper.readValue(orderIdParam, Long.class); service.getOrderById(orderId, result -> { if (result.succeeded()) message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); @@ -93,7 +109,14 @@ public class StoreApiVerticle extends AbstractVerticle { //Consumer for placeOrder vertx.eventBus(). consumer(PLACEORDER_SERVICE_ID).handler(message -> { try { - Order body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), Order.class); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "placeOrder"; + JsonObject bodyParam = message.body().getJsonObject("body"); + if (bodyParam == null) { + manageError(message, new MainApiException(400, "body is required"), serviceId); + return; + } + Order body = Json.mapper.readValue(bodyParam.encode(), Order.class); service.placeOrder(body, result -> { if (result.succeeded()) message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/UserApiVerticle.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/UserApiVerticle.java index 70070fd59b..5021215f4d 100644 --- a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/UserApiVerticle.java +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/UserApiVerticle.java @@ -44,7 +44,14 @@ public class UserApiVerticle extends AbstractVerticle { //Consumer for createUser vertx.eventBus(). consumer(CREATEUSER_SERVICE_ID).handler(message -> { try { - User body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), User.class); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "createUser"; + JsonObject bodyParam = message.body().getJsonObject("body"); + if (bodyParam == null) { + manageError(message, new MainApiException(400, "body is required"), serviceId); + return; + } + User body = Json.mapper.readValue(bodyParam.encode(), User.class); service.createUser(body, result -> { if (result.succeeded()) message.reply(null); @@ -62,8 +69,15 @@ public class UserApiVerticle extends AbstractVerticle { //Consumer for createUsersWithArrayInput vertx.eventBus(). consumer(CREATEUSERSWITHARRAYINPUT_SERVICE_ID).handler(message -> { try { - List body = Json.mapper.readValue(message.body().getJsonArray("body").encode(), - Json.mapper.getTypeFactory().constructCollectionType(List.class, User.class)); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "createUsersWithArrayInput"; + JsonArray bodyParam = message.body().getJsonArray("body"); + if(bodyParam == null) { + manageError(message, new MainApiException(400, "body is required"), serviceId); + return; + } + List body = Json.mapper.readValue(bodyParam.encode(), + Json.mapper.getTypeFactory().constructCollectionType(List.class, User.class)); service.createUsersWithArrayInput(body, result -> { if (result.succeeded()) message.reply(null); @@ -81,8 +95,15 @@ public class UserApiVerticle extends AbstractVerticle { //Consumer for createUsersWithListInput vertx.eventBus(). consumer(CREATEUSERSWITHLISTINPUT_SERVICE_ID).handler(message -> { try { - List body = Json.mapper.readValue(message.body().getJsonArray("body").encode(), - Json.mapper.getTypeFactory().constructCollectionType(List.class, User.class)); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "createUsersWithListInput"; + JsonArray bodyParam = message.body().getJsonArray("body"); + if(bodyParam == null) { + manageError(message, new MainApiException(400, "body is required"), serviceId); + return; + } + List body = Json.mapper.readValue(bodyParam.encode(), + Json.mapper.getTypeFactory().constructCollectionType(List.class, User.class)); service.createUsersWithListInput(body, result -> { if (result.succeeded()) message.reply(null); @@ -100,7 +121,14 @@ public class UserApiVerticle extends AbstractVerticle { //Consumer for deleteUser vertx.eventBus(). consumer(DELETEUSER_SERVICE_ID).handler(message -> { try { - String username = message.body().getString("username"); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "deleteUser"; + String usernameParam = message.body().getString("username"); + if(usernameParam == null) { + manageError(message, new MainApiException(400, "username is required"), serviceId); + return; + } + String username = usernameParam; service.deleteUser(username, result -> { if (result.succeeded()) message.reply(null); @@ -118,7 +146,14 @@ public class UserApiVerticle extends AbstractVerticle { //Consumer for getUserByName vertx.eventBus(). consumer(GETUSERBYNAME_SERVICE_ID).handler(message -> { try { - String username = message.body().getString("username"); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "getUserByName"; + String usernameParam = message.body().getString("username"); + if(usernameParam == null) { + manageError(message, new MainApiException(400, "username is required"), serviceId); + return; + } + String username = usernameParam; service.getUserByName(username, result -> { if (result.succeeded()) message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); @@ -136,8 +171,20 @@ public class UserApiVerticle extends AbstractVerticle { //Consumer for loginUser vertx.eventBus(). consumer(LOGINUSER_SERVICE_ID).handler(message -> { try { - String username = message.body().getString("username"); - String password = message.body().getString("password"); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "loginUser"; + String usernameParam = message.body().getString("username"); + if(usernameParam == null) { + manageError(message, new MainApiException(400, "username is required"), serviceId); + return; + } + String username = usernameParam; + String passwordParam = message.body().getString("password"); + if(passwordParam == null) { + manageError(message, new MainApiException(400, "password is required"), serviceId); + return; + } + String password = passwordParam; service.loginUser(username, password, result -> { if (result.succeeded()) message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); @@ -155,6 +202,8 @@ public class UserApiVerticle extends AbstractVerticle { //Consumer for logoutUser vertx.eventBus(). consumer(LOGOUTUSER_SERVICE_ID).handler(message -> { try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "logoutUser"; service.logoutUser(result -> { if (result.succeeded()) message.reply(null); @@ -172,8 +221,20 @@ public class UserApiVerticle extends AbstractVerticle { //Consumer for updateUser vertx.eventBus(). consumer(UPDATEUSER_SERVICE_ID).handler(message -> { try { - String username = message.body().getString("username"); - User body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), User.class); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "updateUser"; + String usernameParam = message.body().getString("username"); + if(usernameParam == null) { + manageError(message, new MainApiException(400, "username is required"), serviceId); + return; + } + String username = usernameParam; + JsonObject bodyParam = message.body().getJsonObject("body"); + if (bodyParam == null) { + manageError(message, new MainApiException(400, "body is required"), serviceId); + return; + } + User body = Json.mapper.readValue(bodyParam.encode(), User.class); service.updateUser(username, body, result -> { if (result.succeeded()) message.reply(null); diff --git a/samples/server/petstore/java-vertx/rx/.swagger-codegen/VERSION b/samples/server/petstore/java-vertx/rx/.swagger-codegen/VERSION index 50794f17f1..a6254504e4 100644 --- a/samples/server/petstore/java-vertx/rx/.swagger-codegen/VERSION +++ b/samples/server/petstore/java-vertx/rx/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.1-SNAPSHOT \ No newline at end of file +2.3.1 \ No newline at end of file diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/PetApiVerticle.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/PetApiVerticle.java index 1b7e08c336..c3999ff191 100644 --- a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/PetApiVerticle.java +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/PetApiVerticle.java @@ -46,7 +46,14 @@ public class PetApiVerticle extends AbstractVerticle { //Consumer for addPet vertx.eventBus(). consumer(ADDPET_SERVICE_ID).handler(message -> { try { - Pet body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), Pet.class); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "addPet"; + JsonObject bodyParam = message.body().getJsonObject("body"); + if (bodyParam == null) { + manageError(message, new MainApiException(400, "body is required"), serviceId); + return; + } + Pet body = Json.mapper.readValue(bodyParam.encode(), Pet.class); service.addPet(body).subscribe( () -> { message.reply(null); @@ -63,8 +70,16 @@ public class PetApiVerticle extends AbstractVerticle { //Consumer for deletePet vertx.eventBus(). consumer(DELETEPET_SERVICE_ID).handler(message -> { try { - Long petId = Json.mapper.readValue(message.body().getString("petId"), Long.class); - String apiKey = message.body().getString("api_key"); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "deletePet"; + String petIdParam = message.body().getString("petId"); + if(petIdParam == null) { + manageError(message, new MainApiException(400, "petId is required"), serviceId); + return; + } + Long petId = Json.mapper.readValue(petIdParam, Long.class); + String apiKeyParam = message.body().getString("api_key"); + String apiKey = (apiKeyParam == null) ? null : apiKeyParam; service.deletePet(petId, apiKey).subscribe( () -> { message.reply(null); @@ -81,8 +96,15 @@ public class PetApiVerticle extends AbstractVerticle { //Consumer for findPetsByStatus vertx.eventBus(). consumer(FINDPETSBYSTATUS_SERVICE_ID).handler(message -> { try { - List status = Json.mapper.readValue(message.body().getJsonArray("status").encode(), - Json.mapper.getTypeFactory().constructCollectionType(List.class, String.class)); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "findPetsByStatus"; + JsonArray statusParam = message.body().getJsonArray("status"); + if(statusParam == null) { + manageError(message, new MainApiException(400, "status is required"), serviceId); + return; + } + List status = Json.mapper.readValue(statusParam.encode(), + Json.mapper.getTypeFactory().constructCollectionType(List.class, String.class)); service.findPetsByStatus(status).subscribe( result -> { message.reply(new JsonArray(Json.encode(result)).encodePrettily()); @@ -99,8 +121,15 @@ public class PetApiVerticle extends AbstractVerticle { //Consumer for findPetsByTags vertx.eventBus(). consumer(FINDPETSBYTAGS_SERVICE_ID).handler(message -> { try { - List tags = Json.mapper.readValue(message.body().getJsonArray("tags").encode(), - Json.mapper.getTypeFactory().constructCollectionType(List.class, String.class)); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "findPetsByTags"; + JsonArray tagsParam = message.body().getJsonArray("tags"); + if(tagsParam == null) { + manageError(message, new MainApiException(400, "tags is required"), serviceId); + return; + } + List tags = Json.mapper.readValue(tagsParam.encode(), + Json.mapper.getTypeFactory().constructCollectionType(List.class, String.class)); service.findPetsByTags(tags).subscribe( result -> { message.reply(new JsonArray(Json.encode(result)).encodePrettily()); @@ -117,7 +146,14 @@ public class PetApiVerticle extends AbstractVerticle { //Consumer for getPetById vertx.eventBus(). consumer(GETPETBYID_SERVICE_ID).handler(message -> { try { - Long petId = Json.mapper.readValue(message.body().getString("petId"), Long.class); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "getPetById"; + String petIdParam = message.body().getString("petId"); + if(petIdParam == null) { + manageError(message, new MainApiException(400, "petId is required"), serviceId); + return; + } + Long petId = Json.mapper.readValue(petIdParam, Long.class); service.getPetById(petId).subscribe( result -> { message.reply(new JsonObject(Json.encode(result)).encodePrettily()); @@ -134,7 +170,14 @@ public class PetApiVerticle extends AbstractVerticle { //Consumer for updatePet vertx.eventBus(). consumer(UPDATEPET_SERVICE_ID).handler(message -> { try { - Pet body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), Pet.class); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "updatePet"; + JsonObject bodyParam = message.body().getJsonObject("body"); + if (bodyParam == null) { + manageError(message, new MainApiException(400, "body is required"), serviceId); + return; + } + Pet body = Json.mapper.readValue(bodyParam.encode(), Pet.class); service.updatePet(body).subscribe( () -> { message.reply(null); @@ -151,9 +194,18 @@ public class PetApiVerticle extends AbstractVerticle { //Consumer for updatePetWithForm vertx.eventBus(). consumer(UPDATEPETWITHFORM_SERVICE_ID).handler(message -> { try { - Long petId = Json.mapper.readValue(message.body().getString("petId"), Long.class); - String name = message.body().getString("name"); - String status = message.body().getString("status"); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "updatePetWithForm"; + String petIdParam = message.body().getString("petId"); + if(petIdParam == null) { + manageError(message, new MainApiException(400, "petId is required"), serviceId); + return; + } + Long petId = Json.mapper.readValue(petIdParam, Long.class); + String nameParam = message.body().getString("name"); + String name = (nameParam == null) ? null : nameParam; + String statusParam = message.body().getString("status"); + String status = (statusParam == null) ? null : statusParam; service.updatePetWithForm(petId, name, status).subscribe( () -> { message.reply(null); @@ -170,9 +222,22 @@ public class PetApiVerticle extends AbstractVerticle { //Consumer for uploadFile vertx.eventBus(). consumer(UPLOADFILE_SERVICE_ID).handler(message -> { try { - Long petId = Json.mapper.readValue(message.body().getString("petId"), Long.class); - String additionalMetadata = message.body().getString("additionalMetadata"); - File file = Json.mapper.readValue(message.body().getJsonObject("file").encode(), File.class); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "uploadFile"; + String petIdParam = message.body().getString("petId"); + if(petIdParam == null) { + manageError(message, new MainApiException(400, "petId is required"), serviceId); + return; + } + Long petId = Json.mapper.readValue(petIdParam, Long.class); + String additionalMetadataParam = message.body().getString("additionalMetadata"); + String additionalMetadata = (additionalMetadataParam == null) ? null : additionalMetadataParam; + JsonObject fileParam = message.body().getJsonObject("file"); + if (fileParam == null) { + manageError(message, new MainApiException(400, "file is required"), serviceId); + return; + } + File file = Json.mapper.readValue(fileParam.encode(), File.class); service.uploadFile(petId, additionalMetadata, file).subscribe( result -> { message.reply(new JsonObject(Json.encode(result)).encodePrettily()); diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/StoreApiVerticle.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/StoreApiVerticle.java index 67353e8ac8..8d15fb4c04 100644 --- a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/StoreApiVerticle.java +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/StoreApiVerticle.java @@ -40,7 +40,14 @@ public class StoreApiVerticle extends AbstractVerticle { //Consumer for deleteOrder vertx.eventBus(). consumer(DELETEORDER_SERVICE_ID).handler(message -> { try { - String orderId = message.body().getString("orderId"); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "deleteOrder"; + String orderIdParam = message.body().getString("orderId"); + if(orderIdParam == null) { + manageError(message, new MainApiException(400, "orderId is required"), serviceId); + return; + } + String orderId = orderIdParam; service.deleteOrder(orderId).subscribe( () -> { message.reply(null); @@ -57,6 +64,8 @@ public class StoreApiVerticle extends AbstractVerticle { //Consumer for getInventory vertx.eventBus(). consumer(GETINVENTORY_SERVICE_ID).handler(message -> { try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "getInventory"; service.getInventory().subscribe( result -> { message.reply(new JsonObject(Json.encode(result)).encodePrettily()); @@ -73,7 +82,14 @@ public class StoreApiVerticle extends AbstractVerticle { //Consumer for getOrderById vertx.eventBus(). consumer(GETORDERBYID_SERVICE_ID).handler(message -> { try { - Long orderId = Json.mapper.readValue(message.body().getString("orderId"), Long.class); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "getOrderById"; + String orderIdParam = message.body().getString("orderId"); + if(orderIdParam == null) { + manageError(message, new MainApiException(400, "orderId is required"), serviceId); + return; + } + Long orderId = Json.mapper.readValue(orderIdParam, Long.class); service.getOrderById(orderId).subscribe( result -> { message.reply(new JsonObject(Json.encode(result)).encodePrettily()); @@ -90,7 +106,14 @@ public class StoreApiVerticle extends AbstractVerticle { //Consumer for placeOrder vertx.eventBus(). consumer(PLACEORDER_SERVICE_ID).handler(message -> { try { - Order body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), Order.class); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "placeOrder"; + JsonObject bodyParam = message.body().getJsonObject("body"); + if (bodyParam == null) { + manageError(message, new MainApiException(400, "body is required"), serviceId); + return; + } + Order body = Json.mapper.readValue(bodyParam.encode(), Order.class); service.placeOrder(body).subscribe( result -> { message.reply(new JsonObject(Json.encode(result)).encodePrettily()); diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/UserApiVerticle.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/UserApiVerticle.java index a6d8f69da0..fb175bd559 100644 --- a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/UserApiVerticle.java +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/UserApiVerticle.java @@ -44,7 +44,14 @@ public class UserApiVerticle extends AbstractVerticle { //Consumer for createUser vertx.eventBus(). consumer(CREATEUSER_SERVICE_ID).handler(message -> { try { - User body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), User.class); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "createUser"; + JsonObject bodyParam = message.body().getJsonObject("body"); + if (bodyParam == null) { + manageError(message, new MainApiException(400, "body is required"), serviceId); + return; + } + User body = Json.mapper.readValue(bodyParam.encode(), User.class); service.createUser(body).subscribe( () -> { message.reply(null); @@ -61,8 +68,15 @@ public class UserApiVerticle extends AbstractVerticle { //Consumer for createUsersWithArrayInput vertx.eventBus(). consumer(CREATEUSERSWITHARRAYINPUT_SERVICE_ID).handler(message -> { try { - List body = Json.mapper.readValue(message.body().getJsonArray("body").encode(), - Json.mapper.getTypeFactory().constructCollectionType(List.class, User.class)); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "createUsersWithArrayInput"; + JsonArray bodyParam = message.body().getJsonArray("body"); + if(bodyParam == null) { + manageError(message, new MainApiException(400, "body is required"), serviceId); + return; + } + List body = Json.mapper.readValue(bodyParam.encode(), + Json.mapper.getTypeFactory().constructCollectionType(List.class, User.class)); service.createUsersWithArrayInput(body).subscribe( () -> { message.reply(null); @@ -79,8 +93,15 @@ public class UserApiVerticle extends AbstractVerticle { //Consumer for createUsersWithListInput vertx.eventBus(). consumer(CREATEUSERSWITHLISTINPUT_SERVICE_ID).handler(message -> { try { - List body = Json.mapper.readValue(message.body().getJsonArray("body").encode(), - Json.mapper.getTypeFactory().constructCollectionType(List.class, User.class)); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "createUsersWithListInput"; + JsonArray bodyParam = message.body().getJsonArray("body"); + if(bodyParam == null) { + manageError(message, new MainApiException(400, "body is required"), serviceId); + return; + } + List body = Json.mapper.readValue(bodyParam.encode(), + Json.mapper.getTypeFactory().constructCollectionType(List.class, User.class)); service.createUsersWithListInput(body).subscribe( () -> { message.reply(null); @@ -97,7 +118,14 @@ public class UserApiVerticle extends AbstractVerticle { //Consumer for deleteUser vertx.eventBus(). consumer(DELETEUSER_SERVICE_ID).handler(message -> { try { - String username = message.body().getString("username"); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "deleteUser"; + String usernameParam = message.body().getString("username"); + if(usernameParam == null) { + manageError(message, new MainApiException(400, "username is required"), serviceId); + return; + } + String username = usernameParam; service.deleteUser(username).subscribe( () -> { message.reply(null); @@ -114,7 +142,14 @@ public class UserApiVerticle extends AbstractVerticle { //Consumer for getUserByName vertx.eventBus(). consumer(GETUSERBYNAME_SERVICE_ID).handler(message -> { try { - String username = message.body().getString("username"); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "getUserByName"; + String usernameParam = message.body().getString("username"); + if(usernameParam == null) { + manageError(message, new MainApiException(400, "username is required"), serviceId); + return; + } + String username = usernameParam; service.getUserByName(username).subscribe( result -> { message.reply(new JsonObject(Json.encode(result)).encodePrettily()); @@ -131,8 +166,20 @@ public class UserApiVerticle extends AbstractVerticle { //Consumer for loginUser vertx.eventBus(). consumer(LOGINUSER_SERVICE_ID).handler(message -> { try { - String username = message.body().getString("username"); - String password = message.body().getString("password"); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "loginUser"; + String usernameParam = message.body().getString("username"); + if(usernameParam == null) { + manageError(message, new MainApiException(400, "username is required"), serviceId); + return; + } + String username = usernameParam; + String passwordParam = message.body().getString("password"); + if(passwordParam == null) { + manageError(message, new MainApiException(400, "password is required"), serviceId); + return; + } + String password = passwordParam; service.loginUser(username, password).subscribe( result -> { message.reply(new JsonObject(Json.encode(result)).encodePrettily()); @@ -149,6 +196,8 @@ public class UserApiVerticle extends AbstractVerticle { //Consumer for logoutUser vertx.eventBus(). consumer(LOGOUTUSER_SERVICE_ID).handler(message -> { try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "logoutUser"; service.logoutUser().subscribe( () -> { message.reply(null); @@ -165,8 +214,20 @@ public class UserApiVerticle extends AbstractVerticle { //Consumer for updateUser vertx.eventBus(). consumer(UPDATEUSER_SERVICE_ID).handler(message -> { try { - String username = message.body().getString("username"); - User body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), User.class); + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "updateUser"; + String usernameParam = message.body().getString("username"); + if(usernameParam == null) { + manageError(message, new MainApiException(400, "username is required"), serviceId); + return; + } + String username = usernameParam; + JsonObject bodyParam = message.body().getJsonObject("body"); + if (bodyParam == null) { + manageError(message, new MainApiException(400, "body is required"), serviceId); + return; + } + User body = Json.mapper.readValue(bodyParam.encode(), User.class); service.updateUser(username, body).subscribe( () -> { message.reply(null);