From 1a831a1a7b44e7d650fe8f518b600d8ad56168fc Mon Sep 17 00:00:00 2001 From: Cliff Cozzolino Date: Wed, 20 Dec 2017 16:47:20 -0600 Subject: [PATCH 1/3] Initialize router in init method and re-use router member to create SwaggerRouter --- .../JavaVertXServer/MainApiVerticle.mustache | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/MainApiVerticle.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/MainApiVerticle.mustache index 14433bcad2a..d7f93d050b9 100644 --- a/modules/swagger-codegen/src/main/resources/JavaVertXServer/MainApiVerticle.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/MainApiVerticle.mustache @@ -9,18 +9,26 @@ import com.github.phiz71.vertx.swagger.router.SwaggerRouter; import io.swagger.models.Swagger; import io.swagger.parser.SwaggerParser; import io.vertx.core.AbstractVerticle; +import io.vertx.core.Context; import io.vertx.core.Future; import io.vertx.core.file.FileSystem; import io.vertx.core.json.Json; import io.vertx.core.logging.Logger; import io.vertx.core.logging.LoggerFactory; +import io.vertx.core.Vertx; import io.vertx.ext.web.Router; public class MainApiVerticle extends AbstractVerticle { final static Logger LOGGER = LoggerFactory.getLogger(MainApiVerticle.class); - final Router router = Router.router(vertx); - + protected Router router; + + @Override + public void init(Vertx vertx, Context context) { + super.init(vertx, context); + router = Router.router(vertx); + } + @Override public void start(Future startFuture) throws Exception { Json.mapper.registerModule(new JavaTimeModule()); @@ -28,7 +36,7 @@ public class MainApiVerticle extends AbstractVerticle { vertxFileSystem.readFile("swagger.json", readFile -> { if (readFile.succeeded()) { Swagger swagger = new SwaggerParser().parse(readFile.result().toString(Charset.forName("utf-8"))); - Router swaggerRouter = SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, vertx.eventBus(), new OperationIdServiceIdResolver()); + Router swaggerRouter = SwaggerRouter.swaggerRouter(router, swagger, vertx.eventBus(), new OperationIdServiceIdResolver()); deployVerticles(startFuture); @@ -49,7 +57,7 @@ public class MainApiVerticle extends AbstractVerticle { LOGGER.info("{{classname}}Verticle : Deployed"); } else { startFuture.fail(res.cause()); - LOGGER.error("{{classname}}Verticle : Deployement failed"); + LOGGER.error("{{classname}}Verticle : Deployment failed"); } }); {{/apis}}{{/apiInfo}} From f767d456131c29e558e660593b26159ce2d6a844 Mon Sep 17 00:00:00 2001 From: Cliff Cozzolino Date: Fri, 22 Dec 2017 10:26:58 -0600 Subject: [PATCH 2/3] Added generated samples for 7320 fix --- .../swagger/server/api/MainApiVerticle.java | 20 +++++++++++++------ .../async/src/main/resources/swagger.json | 15 ++------------ .../swagger/server/api/MainApiVerticle.java | 20 +++++++++++++------ .../rx/src/main/resources/swagger.json | 15 ++------------ 4 files changed, 32 insertions(+), 38 deletions(-) diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/MainApiVerticle.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/MainApiVerticle.java index 8fb3ae2f3cf..ed9377ad08b 100644 --- a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/MainApiVerticle.java +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/MainApiVerticle.java @@ -9,18 +9,26 @@ import io.swagger.models.Swagger; import io.swagger.parser.SwaggerParser; import io.vertx.core.AbstractVerticle; +import io.vertx.core.Context; import io.vertx.core.Future; import io.vertx.core.file.FileSystem; import io.vertx.core.json.Json; import io.vertx.core.logging.Logger; import io.vertx.core.logging.LoggerFactory; +import io.vertx.core.Vertx; import io.vertx.ext.web.Router; public class MainApiVerticle extends AbstractVerticle { final static Logger LOGGER = LoggerFactory.getLogger(MainApiVerticle.class); - final Router router = Router.router(vertx); - + protected Router router; + + @Override + public void init(Vertx vertx, Context context) { + super.init(vertx, context); + router = Router.router(vertx); + } + @Override public void start(Future startFuture) throws Exception { Json.mapper.registerModule(new JavaTimeModule()); @@ -28,7 +36,7 @@ public void start(Future startFuture) throws Exception { vertxFileSystem.readFile("swagger.json", readFile -> { if (readFile.succeeded()) { Swagger swagger = new SwaggerParser().parse(readFile.result().toString(Charset.forName("utf-8"))); - Router swaggerRouter = SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, vertx.eventBus(), new OperationIdServiceIdResolver()); + Router swaggerRouter = SwaggerRouter.swaggerRouter(router, swagger, vertx.eventBus(), new OperationIdServiceIdResolver()); deployVerticles(startFuture); @@ -49,7 +57,7 @@ public void deployVerticles(Future startFuture) { LOGGER.info("PetApiVerticle : Deployed"); } else { startFuture.fail(res.cause()); - LOGGER.error("PetApiVerticle : Deployement failed"); + LOGGER.error("PetApiVerticle : Deployment failed"); } }); @@ -58,7 +66,7 @@ public void deployVerticles(Future startFuture) { LOGGER.info("StoreApiVerticle : Deployed"); } else { startFuture.fail(res.cause()); - LOGGER.error("StoreApiVerticle : Deployement failed"); + LOGGER.error("StoreApiVerticle : Deployment failed"); } }); @@ -67,7 +75,7 @@ public void deployVerticles(Future startFuture) { LOGGER.info("UserApiVerticle : Deployed"); } else { startFuture.fail(res.cause()); - LOGGER.error("UserApiVerticle : Deployement failed"); + LOGGER.error("UserApiVerticle : Deployment failed"); } }); diff --git a/samples/server/petstore/java-vertx/async/src/main/resources/swagger.json b/samples/server/petstore/java-vertx/async/src/main/resources/swagger.json index 4e35b37c4c8..1535f18c6e3 100644 --- a/samples/server/petstore/java-vertx/async/src/main/resources/swagger.json +++ b/samples/server/petstore/java-vertx/async/src/main/resources/swagger.json @@ -112,8 +112,8 @@ "type" : "array", "items" : { "type" : "string", - "enum" : [ "available", "pending", "sold" ], - "default" : "available" + "default" : "available", + "enum" : [ "available", "pending", "sold" ] }, "collectionFormat" : "csv" } ], @@ -134,7 +134,6 @@ "security" : [ { "petstore_auth" : [ "write:pets", "read:pets" ] } ], - "x-contentType" : "application/json", "x-accepts" : "application/json" } }, @@ -174,7 +173,6 @@ "petstore_auth" : [ "write:pets", "read:pets" ] } ], "deprecated" : true, - "x-contentType" : "application/json", "x-accepts" : "application/json" } }, @@ -210,7 +208,6 @@ "security" : [ { "api_key" : [ ] } ], - "x-contentType" : "application/json", "x-accepts" : "application/json" }, "post" : { @@ -278,7 +275,6 @@ "security" : [ { "petstore_auth" : [ "write:pets", "read:pets" ] } ], - "x-contentType" : "application/json", "x-accepts" : "application/json" } }, @@ -348,7 +344,6 @@ "security" : [ { "api_key" : [ ] } ], - "x-contentType" : "application/json", "x-accepts" : "application/json" } }, @@ -414,7 +409,6 @@ "description" : "Order not found" } }, - "x-contentType" : "application/json", "x-accepts" : "application/json" }, "delete" : { @@ -438,7 +432,6 @@ "description" : "Order not found" } }, - "x-contentType" : "application/json", "x-accepts" : "application/json" } }, @@ -566,7 +559,6 @@ "description" : "Invalid username/password supplied" } }, - "x-contentType" : "application/json", "x-accepts" : "application/json" } }, @@ -583,7 +575,6 @@ "description" : "successful operation" } }, - "x-contentType" : "application/json", "x-accepts" : "application/json" } }, @@ -615,7 +606,6 @@ "description" : "User not found" } }, - "x-contentType" : "application/json", "x-accepts" : "application/json" }, "put" : { @@ -671,7 +661,6 @@ "description" : "User not found" } }, - "x-contentType" : "application/json", "x-accepts" : "application/json" } } diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/MainApiVerticle.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/MainApiVerticle.java index 8fb3ae2f3cf..ed9377ad08b 100644 --- a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/MainApiVerticle.java +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/MainApiVerticle.java @@ -9,18 +9,26 @@ import io.swagger.models.Swagger; import io.swagger.parser.SwaggerParser; import io.vertx.core.AbstractVerticle; +import io.vertx.core.Context; import io.vertx.core.Future; import io.vertx.core.file.FileSystem; import io.vertx.core.json.Json; import io.vertx.core.logging.Logger; import io.vertx.core.logging.LoggerFactory; +import io.vertx.core.Vertx; import io.vertx.ext.web.Router; public class MainApiVerticle extends AbstractVerticle { final static Logger LOGGER = LoggerFactory.getLogger(MainApiVerticle.class); - final Router router = Router.router(vertx); - + protected Router router; + + @Override + public void init(Vertx vertx, Context context) { + super.init(vertx, context); + router = Router.router(vertx); + } + @Override public void start(Future startFuture) throws Exception { Json.mapper.registerModule(new JavaTimeModule()); @@ -28,7 +36,7 @@ public void start(Future startFuture) throws Exception { vertxFileSystem.readFile("swagger.json", readFile -> { if (readFile.succeeded()) { Swagger swagger = new SwaggerParser().parse(readFile.result().toString(Charset.forName("utf-8"))); - Router swaggerRouter = SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, vertx.eventBus(), new OperationIdServiceIdResolver()); + Router swaggerRouter = SwaggerRouter.swaggerRouter(router, swagger, vertx.eventBus(), new OperationIdServiceIdResolver()); deployVerticles(startFuture); @@ -49,7 +57,7 @@ public void deployVerticles(Future startFuture) { LOGGER.info("PetApiVerticle : Deployed"); } else { startFuture.fail(res.cause()); - LOGGER.error("PetApiVerticle : Deployement failed"); + LOGGER.error("PetApiVerticle : Deployment failed"); } }); @@ -58,7 +66,7 @@ public void deployVerticles(Future startFuture) { LOGGER.info("StoreApiVerticle : Deployed"); } else { startFuture.fail(res.cause()); - LOGGER.error("StoreApiVerticle : Deployement failed"); + LOGGER.error("StoreApiVerticle : Deployment failed"); } }); @@ -67,7 +75,7 @@ public void deployVerticles(Future startFuture) { LOGGER.info("UserApiVerticle : Deployed"); } else { startFuture.fail(res.cause()); - LOGGER.error("UserApiVerticle : Deployement failed"); + LOGGER.error("UserApiVerticle : Deployment failed"); } }); diff --git a/samples/server/petstore/java-vertx/rx/src/main/resources/swagger.json b/samples/server/petstore/java-vertx/rx/src/main/resources/swagger.json index 4e35b37c4c8..1535f18c6e3 100644 --- a/samples/server/petstore/java-vertx/rx/src/main/resources/swagger.json +++ b/samples/server/petstore/java-vertx/rx/src/main/resources/swagger.json @@ -112,8 +112,8 @@ "type" : "array", "items" : { "type" : "string", - "enum" : [ "available", "pending", "sold" ], - "default" : "available" + "default" : "available", + "enum" : [ "available", "pending", "sold" ] }, "collectionFormat" : "csv" } ], @@ -134,7 +134,6 @@ "security" : [ { "petstore_auth" : [ "write:pets", "read:pets" ] } ], - "x-contentType" : "application/json", "x-accepts" : "application/json" } }, @@ -174,7 +173,6 @@ "petstore_auth" : [ "write:pets", "read:pets" ] } ], "deprecated" : true, - "x-contentType" : "application/json", "x-accepts" : "application/json" } }, @@ -210,7 +208,6 @@ "security" : [ { "api_key" : [ ] } ], - "x-contentType" : "application/json", "x-accepts" : "application/json" }, "post" : { @@ -278,7 +275,6 @@ "security" : [ { "petstore_auth" : [ "write:pets", "read:pets" ] } ], - "x-contentType" : "application/json", "x-accepts" : "application/json" } }, @@ -348,7 +344,6 @@ "security" : [ { "api_key" : [ ] } ], - "x-contentType" : "application/json", "x-accepts" : "application/json" } }, @@ -414,7 +409,6 @@ "description" : "Order not found" } }, - "x-contentType" : "application/json", "x-accepts" : "application/json" }, "delete" : { @@ -438,7 +432,6 @@ "description" : "Order not found" } }, - "x-contentType" : "application/json", "x-accepts" : "application/json" } }, @@ -566,7 +559,6 @@ "description" : "Invalid username/password supplied" } }, - "x-contentType" : "application/json", "x-accepts" : "application/json" } }, @@ -583,7 +575,6 @@ "description" : "successful operation" } }, - "x-contentType" : "application/json", "x-accepts" : "application/json" } }, @@ -615,7 +606,6 @@ "description" : "User not found" } }, - "x-contentType" : "application/json", "x-accepts" : "application/json" }, "put" : { @@ -671,7 +661,6 @@ "description" : "User not found" } }, - "x-contentType" : "application/json", "x-accepts" : "application/json" } } From fc64efc5b3cb12318e2b94e6b2a1c56a081c3308 Mon Sep 17 00:00:00 2001 From: Cliff Cozzolino Date: Thu, 28 Dec 2017 12:21:25 -0600 Subject: [PATCH 3/3] Fixed alignment to 4 spaces for 7320 fix --- .../main/resources/JavaVertXServer/MainApiVerticle.mustache | 6 +++--- .../main/java/io/swagger/server/api/MainApiVerticle.java | 6 +++--- .../main/java/io/swagger/server/api/MainApiVerticle.java | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/MainApiVerticle.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/MainApiVerticle.mustache index d7f93d050b9..9f834d4e644 100644 --- a/modules/swagger-codegen/src/main/resources/JavaVertXServer/MainApiVerticle.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/MainApiVerticle.mustache @@ -25,14 +25,14 @@ public class MainApiVerticle extends AbstractVerticle { @Override public void init(Vertx vertx, Context context) { - super.init(vertx, context); - router = Router.router(vertx); + super.init(vertx, context); + router = Router.router(vertx); } @Override public void start(Future startFuture) throws Exception { Json.mapper.registerModule(new JavaTimeModule()); - FileSystem vertxFileSystem = vertx.fileSystem(); + FileSystem vertxFileSystem = vertx.fileSystem(); vertxFileSystem.readFile("swagger.json", readFile -> { if (readFile.succeeded()) { Swagger swagger = new SwaggerParser().parse(readFile.result().toString(Charset.forName("utf-8"))); diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/MainApiVerticle.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/MainApiVerticle.java index ed9377ad08b..34cf3a7761b 100644 --- a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/MainApiVerticle.java +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/MainApiVerticle.java @@ -25,14 +25,14 @@ public class MainApiVerticle extends AbstractVerticle { @Override public void init(Vertx vertx, Context context) { - super.init(vertx, context); - router = Router.router(vertx); + super.init(vertx, context); + router = Router.router(vertx); } @Override public void start(Future startFuture) throws Exception { Json.mapper.registerModule(new JavaTimeModule()); - FileSystem vertxFileSystem = vertx.fileSystem(); + FileSystem vertxFileSystem = vertx.fileSystem(); vertxFileSystem.readFile("swagger.json", readFile -> { if (readFile.succeeded()) { Swagger swagger = new SwaggerParser().parse(readFile.result().toString(Charset.forName("utf-8"))); diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/MainApiVerticle.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/MainApiVerticle.java index ed9377ad08b..34cf3a7761b 100644 --- a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/MainApiVerticle.java +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/MainApiVerticle.java @@ -25,14 +25,14 @@ public class MainApiVerticle extends AbstractVerticle { @Override public void init(Vertx vertx, Context context) { - super.init(vertx, context); - router = Router.router(vertx); + super.init(vertx, context); + router = Router.router(vertx); } @Override public void start(Future startFuture) throws Exception { Json.mapper.registerModule(new JavaTimeModule()); - FileSystem vertxFileSystem = vertx.fileSystem(); + FileSystem vertxFileSystem = vertx.fileSystem(); vertxFileSystem.readFile("swagger.json", readFile -> { if (readFile.succeeded()) { Swagger swagger = new SwaggerParser().parse(readFile.result().toString(Charset.forName("utf-8")));