diff --git a/bin/java-vertx-async-petstore-server.sh b/bin/java-vertx-async-petstore-server.sh new file mode 100644 index 0000000000..50220ef330 --- /dev/null +++ b/bin/java-vertx-async-petstore-server.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +SCRIPT="$0" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar" + +if [ ! -f "$executable" ] +then + mvn clean package +fi + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" +ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l java-vertx -o samples/server/petstore/java-vertx/async -DvertxSwaggerRouterVersion=1.2.0" + +java $JAVA_OPTS -jar $executable $ags diff --git a/bin/java-vertx-rx-petstore-server.sh b/bin/java-vertx-rx-petstore-server.sh new file mode 100644 index 0000000000..f569df51cc --- /dev/null +++ b/bin/java-vertx-rx-petstore-server.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +SCRIPT="$0" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar" + +if [ ! -f "$executable" ] +then + mvn clean package +fi + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" +ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l java-vertx -o samples/server/petstore/java-vertx/rx -DvertxSwaggerRouterVersion=1.2.0,rxInterface=true" + +java $JAVA_OPTS -jar $executable $ags diff --git a/bin/windows/java-vertx-async-petstore-server.bat b/bin/windows/java-vertx-async-petstore-server.bat new file mode 100644 index 0000000000..105eaa2368 --- /dev/null +++ b/bin/windows/java-vertx-async-petstore-server.bat @@ -0,0 +1,10 @@ +set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar + +If Not Exist %executable% ( + mvn clean package +) + +REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M +set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l java-vertx -o samples\server\petstore\java-vertx\async -DvertxSwaggerRouterVersion=1.2.0 + +java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/java-vertx-rx-petstore-server.bat b/bin/windows/java-vertx-rx-petstore-server.bat new file mode 100644 index 0000000000..fc7b239754 --- /dev/null +++ b/bin/windows/java-vertx-rx-petstore-server.bat @@ -0,0 +1,10 @@ +set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar + +If Not Exist %executable% ( + mvn clean package +) + +REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M +set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l java-vertx -o samples\server\petstore\java-vertx\rx -DvertxSwaggerRouterVersion=1.2.0,rxInterface=true + +java %JAVA_OPTS% -jar %executable% %ags% diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaVertXServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaVertXServerCodegen.java new file mode 100644 index 0000000000..f8a6168516 --- /dev/null +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaVertXServerCodegen.java @@ -0,0 +1,272 @@ +package io.swagger.codegen.languages; + +import io.swagger.codegen.CliOption; +import io.swagger.codegen.CodegenModel; +import io.swagger.codegen.CodegenOperation; +import io.swagger.codegen.CodegenProperty; +import io.swagger.codegen.CodegenType; +import io.swagger.codegen.SupportingFile; +import io.swagger.models.HttpMethod; +import io.swagger.models.Model; +import io.swagger.models.Operation; +import io.swagger.models.Path; +import io.swagger.models.Swagger; +import io.swagger.util.Json; + +import java.io.File; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class JavaVertXServerCodegen extends AbstractJavaCodegen { + + protected String resourceFolder = "src/main/resources"; + protected String rootPackage = "io.swagger.server.api"; + protected String apiVersion = "1.0.0-SNAPSHOT"; + + public static final String ROOT_PACKAGE = "rootPackage"; + + public static final String RX_INTERFACE_OPTION = "rxInterface"; + public static final String VERTX_SWAGGER_ROUTER_VERSION_OPTION = "vertxSwaggerRouterVersion"; + + /** + * A Java Vert.X generator. It uses java8 date API. It can be configured with 2 CLI options : + * + * rxInterface : type Boolean if true, API interfaces are generated with RX and methods return + * Single and Comparable. default : false + * + * vertxSwaggerRouterVersion : type String Specify the version of the swagger router library + */ + public JavaVertXServerCodegen() { + super(); + + // set the output folder here + outputFolder = "generated-code" + File.separator + "javaVertXServer"; + + modelTemplateFiles.clear(); + modelTemplateFiles.put("model.mustache", ".java"); + + apiTemplateFiles.clear(); + apiTemplateFiles.put("api.mustache", ".java"); + apiTemplateFiles.put("apiVerticle.mustache", "Verticle.java"); + apiTemplateFiles.put("apiException.mustache", "Exception.java"); + + embeddedTemplateDir = templateDir = "JavaVertXServer"; + + apiPackage = rootPackage + ".verticle"; + + modelPackage = rootPackage + ".model"; + + additionalProperties.put(ROOT_PACKAGE, rootPackage); + + groupId = "io.swagger"; + artifactId = "swagger-java-vertx-server"; + artifactVersion = apiVersion; + + this.setDateLibrary("java8"); + + cliOptions.add(CliOption.newBoolean(RX_INTERFACE_OPTION, + "When specified, API interfaces are generated with RX " + + "and methods return Single<> and Comparable.")); + cliOptions.add(CliOption.newString(VERTX_SWAGGER_ROUTER_VERSION_OPTION, + "Specify the version of the swagger router library")); + + } + + /** + * Configures the type of generator. + * + * @return the CodegenType for this generator + * @see io.swagger.codegen.CodegenType + */ + public CodegenType getTag() { + return CodegenType.SERVER; + } + + /** + * Configures a friendly name for the generator. This will be used by the generator to select + * the library with the -l flag. + * + * @return the friendly name for the generator + */ + public String getName() { + return "java-vertx"; + } + + /** + * Returns human-friendly help for the generator. Provide the consumer with help tips, + * parameters here + * + * @return A string value for the help message + */ + public String getHelp() { + return "Generates a java-Vert.X Server library."; + } + + @Override + public void processOpts() { + super.processOpts(); + + apiTestTemplateFiles.clear(); + + importMapping.remove("JsonCreator"); + importMapping.remove("com.fasterxml.jackson.annotation.JsonProperty"); + importMapping.put("JsonInclude", "com.fasterxml.jackson.annotation.JsonInclude"); + importMapping.put("JsonProperty", "com.fasterxml.jackson.annotation.JsonProperty"); + importMapping.put("JsonValue", "com.fasterxml.jackson.annotation.JsonValue"); + importMapping.put("MainApiException", rootPackage + ".MainApiException"); + + modelDocTemplateFiles.clear(); + apiDocTemplateFiles.clear(); + + supportingFiles.clear(); + supportingFiles.add(new SupportingFile("swagger.mustache", resourceFolder, "swagger.json")); + supportingFiles.add(new SupportingFile("MainApiVerticle.mustache", + sourceFolder + File.separator + rootPackage.replace(".", File.separator), + "MainApiVerticle.java")); + supportingFiles.add(new SupportingFile("MainApiException.mustache", + sourceFolder + File.separator + rootPackage.replace(".", File.separator), + "MainApiException.java")); + + writeOptional(outputFolder, new SupportingFile("vertx-default-jul-logging.mustache", + resourceFolder, "vertx-default-jul-logging.properties")); + writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml")); + writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md")); + } + + @Override + public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { + super.postProcessModelProperty(model, property); + if (!model.isEnum) { + model.imports.add("JsonInclude"); + model.imports.add("JsonProperty"); + if (model.hasEnums) { + model.imports.add("JsonValue"); + } + } + + } + + @Override + public Map postProcessOperations(Map objs) { + Map newObjs = super.postProcessOperations(objs); + Map operations = (Map) newObjs.get("operations"); + if (operations != null) { + List ops = (List) operations.get("operation"); + for (CodegenOperation operation : ops) { + operation.httpMethod = operation.httpMethod.toLowerCase(); + + if ("Void".equalsIgnoreCase(operation.returnType)) { + operation.returnType = null; + } + + if (operation.getHasPathParams()) { + operation.path = camelizePath(operation.path); + } + + } + } + return newObjs; + } + + @Override + public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, + Map definitions, Swagger swagger) { + CodegenOperation codegenOperation = + super.fromOperation(path, httpMethod, operation, definitions, swagger); + codegenOperation.imports.add("MainApiException"); + return codegenOperation; + } + + @Override + public CodegenModel fromModel(String name, Model model, Map allDefinitions) { + CodegenModel codegenModel = super.fromModel(name, model, allDefinitions); + codegenModel.imports.remove("ApiModel"); + codegenModel.imports.remove("ApiModelProperty"); + return codegenModel; + + } + + @Override + public void preprocessSwagger(Swagger swagger) { + super.preprocessSwagger(swagger); + + // add full swagger definition in a mustache parameter + String swaggerDef = Json.pretty(swagger); + this.additionalProperties.put("fullSwagger", swaggerDef); + + // add server port from the swagger file, 8080 by default + String host = swagger.getHost(); + String port = extractPortFromHost(host); + this.additionalProperties.put("serverPort", port); + + // retrieve api version from swagger file, 1.0.0-SNAPSHOT by default + if (swagger.getInfo() != null && swagger.getInfo().getVersion() != null) { + artifactVersion = apiVersion = swagger.getInfo().getVersion(); + } else { + artifactVersion = apiVersion; + } + + /* + * manage operation & custom serviceId because operationId field is not + * required and may be empty + */ + Map paths = swagger.getPaths(); + if (paths != null) { + for (Entry entry : paths.entrySet()) { + manageOperationNames(entry.getValue(), entry.getKey()); + } + } + this.additionalProperties.remove("gson"); + } + + private void manageOperationNames(Path path, String pathname) { + String serviceIdTemp; + + Map operationMap = path.getOperationMap(); + if (operationMap != null) { + for (Entry entry : operationMap.entrySet()) { + serviceIdTemp = computeServiceId(pathname, entry); + entry.getValue().setVendorExtension("x-serviceid", serviceIdTemp); + entry.getValue().setVendorExtension("x-serviceid-varname", + serviceIdTemp.toUpperCase() + "_SERVICE_ID"); + } + } + } + + private String computeServiceId(String pathname, Entry entry) { + String operationId = entry.getValue().getOperationId(); + return (operationId != null) ? operationId + : entry.getKey().name() + + pathname.replaceAll("-", "_").replaceAll("/", "_").replaceAll("[{}]", ""); + } + + protected String extractPortFromHost(String host) { + if (host != null) { + int portSeparatorIndex = host.indexOf(':'); + if (portSeparatorIndex >= 0 && portSeparatorIndex + 1 < host.length()) { + return host.substring(portSeparatorIndex + 1); + } + } + return "8080"; + } + + private String camelizePath(String path) { + String word = path; + Pattern pattern = Pattern.compile("\\{([^/]*)\\}"); + Matcher matcher = pattern.matcher(word); + while (matcher.find()) { + word = matcher.replaceFirst(":" + matcher.group(1)); + matcher = pattern.matcher(word); + } + pattern = Pattern.compile("(_)(.)"); + matcher = pattern.matcher(word); + while (matcher.find()) { + word = matcher.replaceFirst(matcher.group(2).toUpperCase()); + matcher = pattern.matcher(word); + } + return word; + } +} diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/AsyncCall.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/AsyncCall.mustache new file mode 100644 index 0000000000..d941d4644d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/AsyncCall.mustache @@ -0,0 +1,18 @@ + service.{{operationId}}({{#hasParams}}{{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{^hasMore}}, {{/hasMore}}{{/allParams}}{{/hasParams}}result -> { + if (result.succeeded()) + {{#returnType}} + {{#isListContainer}} + message.reply(new JsonArray(Json.encode(result.result())).encodePrettily()); + {{/isListContainer}} + {{^isListContainer}} + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + {{/isListContainer}} + {{/returnType}} + {{^returnType}} + message.reply(null); + {{/returnType}} + else { + Throwable cause = result.cause(); + manageError(message, cause, "{{#vendorExtensions}}{{x-serviceid}}{{/vendorExtensions}}"); + } + }); \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/AsyncMethod.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/AsyncMethod.mustache new file mode 100644 index 0000000000..bfde8acdb2 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/AsyncMethod.mustache @@ -0,0 +1 @@ + void {{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{^hasMore}}, {{/hasMore}}{{/allParams}}Handler> handler); \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/MainApiException.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/MainApiException.mustache new file mode 100644 index 0000000000..2e2b887a11 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/MainApiException.mustache @@ -0,0 +1,22 @@ +package {{rootPackage}}; + +public class MainApiException extends Exception { + private int statusCode; + private String statusMessage; + + public MainApiException(int statusCode, String statusMessage) { + super(); + this.statusCode = statusCode; + this.statusMessage = statusMessage; + } + + public int getStatusCode() { + return statusCode; + } + + public String getStatusMessage() { + return statusMessage; + } + + public static final MainApiException INTERNAL_SERVER_ERROR = new MainApiException(500, "Internal Server Error"); +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/MainApiVerticle.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/MainApiVerticle.mustache new file mode 100644 index 0000000000..14433bcad2 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/MainApiVerticle.mustache @@ -0,0 +1,57 @@ +package {{rootPackage}}; + +import java.nio.charset.Charset; + +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.github.phiz71.vertx.swagger.router.OperationIdServiceIdResolver; +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.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.ext.web.Router; + +public class MainApiVerticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger(MainApiVerticle.class); + + final Router router = Router.router(vertx); + + @Override + public void start(Future startFuture) throws Exception { + Json.mapper.registerModule(new JavaTimeModule()); + FileSystem vertxFileSystem = vertx.fileSystem(); + 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()); + + deployVerticles(startFuture); + + vertx.createHttpServer() + .requestHandler(swaggerRouter::accept) + .listen({{serverPort}}); + startFuture.complete(); + } else { + startFuture.fail(readFile.cause()); + } + }); + } + + public void deployVerticles(Future startFuture) { + {{#apiInfo}}{{#apis}} + vertx.deployVerticle("{{apiPackage}}.{{classname}}Verticle", res -> { + if (res.succeeded()) { + LOGGER.info("{{classname}}Verticle : Deployed"); + } else { + startFuture.fail(res.cause()); + LOGGER.error("{{classname}}Verticle : Deployement failed"); + } + }); + {{/apis}}{{/apiInfo}} + } +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/README.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/README.mustache new file mode 100644 index 0000000000..ac03f0bc7c --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/README.mustache @@ -0,0 +1 @@ +Project generated on : {{generatedDate}} diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/RxCall.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/RxCall.mustache new file mode 100644 index 0000000000..b28db6dae6 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/RxCall.mustache @@ -0,0 +1,18 @@ + service.{{operationId}}({{#hasParams}}{{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{/hasParams}}).subscribe( + {{#returnType}} + result -> { + {{#isListContainer}} + message.reply(new JsonArray(Json.encode(result)).encodePrettily()); + {{/isListContainer}} + {{^isListContainer}} + message.reply(new JsonObject(Json.encode(result)).encodePrettily()); + {{/isListContainer}} + {{/returnType}} + {{^returnType}} + () -> { + message.reply(null); + {{/returnType}} + }, + error -> { + manageError(message, error, "{{#vendorExtensions}}{{x-serviceid}}{{/vendorExtensions}}"); + }); \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/RxMethod.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/RxMethod.mustache new file mode 100644 index 0000000000..d30087853f --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/RxMethod.mustache @@ -0,0 +1 @@ + public {{#returnType}}Single<{{{returnType}}}>{{/returnType}}{{^returnType}}Completable{{/returnType}} {{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}},{{/hasMore}}{{/allParams}}); \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/api.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/api.mustache new file mode 100644 index 0000000000..bbef264504 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/api.mustache @@ -0,0 +1,31 @@ +package {{package}}; + +{{#imports}}import {{import}}; +{{/imports}} + +{{#rxInterface}} +import rx.Completable; +import rx.Single; +{{/rxInterface}} +{{^rxInterface}} +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; +{{/rxInterface}} + +import java.util.List; +import java.util.Map; + +public interface {{classname}} { +{{#operations}} +{{#operation}} + //{{#vendorExtensions}}{{x-serviceid}}{{/vendorExtensions}} + {{#rxInterface}} +{{>RxMethod}} + {{/rxInterface}} + {{^rxInterface}} +{{>AsyncMethod}} + {{/rxInterface}} + +{{/operation}} +{{/operations}} +} diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/apiException.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/apiException.mustache new file mode 100644 index 0000000000..f3b495dfb4 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/apiException.mustache @@ -0,0 +1,14 @@ +package {{package}}; + +{{#imports}}import {{import}}; +{{/imports}} + +public final class {{classname}}Exception extends MainApiException { + public {{classname}}Exception(int statusCode, String statusMessage) { + super(statusCode, statusMessage); + } + + {{#operations}}{{#operation}}{{#responses}}{{^isDefault}}public static final {{classname}}Exception {{baseName}}_{{{operationId}}}_{{{code}}}_Exception = new {{classname}}Exception({{{code}}}, "{{{message}}}"); + {{/isDefault}}{{/responses}}{{/operation}}{{/operations}} + +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/apiVerticle.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/apiVerticle.mustache new file mode 100644 index 0000000000..715e7aa11f --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/apiVerticle.mustache @@ -0,0 +1,82 @@ +package {{package}}; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.eventbus.Message; +import io.vertx.core.json.Json; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; + +{{#imports}}import {{import}}; +{{/imports}} + +import java.util.List; +import java.util.Map; + +public class {{classname}}Verticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger({{classname}}Verticle.class); + + {{#operations}}{{#operation}}{{#vendorExtensions}}final static String {{x-serviceid-varname}} = "{{x-serviceid}}"; + {{/vendorExtensions}}{{/operation}}{{/operations}} + //TODO : create Implementation + {{classname}} service = new {{classname}}Impl(); + + @Override + public void start() throws Exception { + {{#operations}}{{#operation}} + //Consumer for {{#vendorExtensions}}{{x-serviceid}}{{/vendorExtensions}} + vertx.eventBus(). consumer({{#vendorExtensions}}{{x-serviceid-varname}}{{/vendorExtensions}}).handler(message -> { + try { + {{#hasParams}} + {{#allParams}} + {{#isListContainer}} + {{{dataType}}} {{paramName}} = Json.mapper.readValue(message.body().getJsonArray("{{baseName}}").encode(), + Json.mapper.getTypeFactory().constructCollectionType(List.class, {{{baseType}}}.class)); + {{/isListContainer}} + {{^isListContainer}} + {{#isPrimitiveType}} + {{#isString}} + {{{dataType}}} {{paramName}} = message.body().getString("{{baseName}}"); + {{/isString}} + {{^isString}} + {{{dataType}}} {{paramName}} = Json.mapper.readValue(message.body().getString("{{baseName}}"), {{{dataType}}}.class); + {{/isString}} + {{/isPrimitiveType}} + {{^isPrimitiveType}} + {{{dataType}}} {{paramName}} = Json.mapper.readValue(message.body().getJsonObject("{{baseName}}").encode(), {{{dataType}}}.class); + {{/isPrimitiveType}} + {{/isListContainer}} + {{/allParams}} + {{/hasParams}} + {{#rxInterface}} +{{>RxCall}} + {{/rxInterface}} + {{^rxInterface}} +{{>AsyncCall}} + {{/rxInterface}} + } catch (Exception e) { + logUnexpectedError("{{#vendorExtensions}}{{x-serviceid}}{{/vendorExtensions}}", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + {{/operation}}{{/operations}} + } + + private void manageError(Message message, Throwable cause, String serviceName) { + int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); + String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); + if (cause instanceof MainApiException) { + code = ((MainApiException)cause).getStatusCode(); + statusMessage = ((MainApiException)cause).getStatusMessage(); + } else { + logUnexpectedError(serviceName, cause); + } + + message.fail(code, statusMessage); + } + + private void logUnexpectedError(String serviceName, Throwable cause) { + LOGGER.error("Unexpected error in "+ serviceName, cause); + } +} diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/enumClass.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/enumClass.mustache new file mode 100644 index 0000000000..0867107d99 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/enumClass.mustache @@ -0,0 +1,17 @@ + + public enum {{{datatypeWithEnum}}} { + {{#allowableValues}}{{#enumVars}}{{{name}}}({{{value}}}){{^-last}}, + {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}} + + private String value; + + {{{datatypeWithEnum}}}(String value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return value; + } + } diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/enumOuterClass.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/enumOuterClass.mustache new file mode 100644 index 0000000000..7aea7b92f2 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/enumOuterClass.mustache @@ -0,0 +1,3 @@ +public enum {{classname}} { + {{#allowableValues}}{{.}}{{^-last}}, {{/-last}}{{/allowableValues}} +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/model.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/model.mustache new file mode 100644 index 0000000000..46f9f77357 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/model.mustache @@ -0,0 +1,12 @@ +package {{package}}; + +import java.util.Objects; +{{#imports}}import {{import}}; +{{/imports}} +{{#serializableModel}}import java.io.Serializable; +{{/serializableModel}}{{#models}}{{#model}}{{#description}} +/** + * {{description}} + **/ +{{/description}}{{^description}} +{{/description}}{{#isEnum}}{{>enumOuterClass}}{{/isEnum}}{{^isEnum}}{{>pojo}}{{/isEnum}}{{/model}}{{/models}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/pojo.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/pojo.mustache new file mode 100644 index 0000000000..c3f95a095c --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/pojo.mustache @@ -0,0 +1,71 @@ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} { + {{#vars}}{{#isEnum}} + +{{>enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}} + +{{>enumClass}}{{/items}}{{/items.isEnum}} + private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}} + + public {{classname}} () { + + } + + public {{classname}} ({{#vars}}{{{datatypeWithEnum}}} {{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}) { + {{#vars}} + this.{{name}} = {{name}}; + {{/vars}} + } + + {{#vars}} + {{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}} + @JsonProperty("{{baseName}}") + public {{{datatypeWithEnum}}} {{getter}}() { + return {{name}}; + } + public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { + this.{{name}} = {{name}}; + } + + {{/vars}} + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + {{classname}} {{classVarName}} = ({{classname}}) o;{{#hasVars}} + return {{#vars}}Objects.equals({{name}}, {{classVarName}}.{{name}}){{#hasMore}} && + {{/hasMore}}{{^hasMore}};{{/hasMore}}{{/vars}}{{/hasVars}}{{^hasVars}} + return true;{{/hasVars}} + } + + @Override + public int hashCode() { + return Objects.hash({{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class {{classname}} {\n"); + {{#parent}}sb.append(" ").append(toIndentedString(super.toString())).append("\n");{{/parent}} + {{#vars}}sb.append(" {{name}}: ").append(toIndentedString({{name}})).append("\n"); + {{/vars}}sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/pom.mustache new file mode 100644 index 0000000000..f899fca9a0 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/pom.mustache @@ -0,0 +1,91 @@ + + 4.0.0 + + {{groupId}} + {{artifactId}} + {{artifactVersion}} + jar + + {{appName}} + + + UTF-8 + 1.8 + 4.12 + 3.4.1 + 3.3 + {{vertxSwaggerRouterVersion}} + 2.3 + 2.7.4 + + + + + junit + junit + ${junit.version} + test + + + + io.vertx + vertx-unit + ${vertx.version} + test + + + + com.github.phiz71 + vertx-swagger-router + ${vertx-swagger-router.version} + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson-datatype-jsr310.version} + + + + + + + + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${java.version} + ${java.version} + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven-shade-plugin.version} + + + package + + shade + + + + + + io.vertx.core.Starter + {{rootPackage}}.MainApiVerticle + + + + + ${project.build.directory}/${project.artifactId}-${project.version}-fat.jar + + + + + + + \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/swagger.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/swagger.mustache new file mode 100644 index 0000000000..d54f6b94d2 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/swagger.mustache @@ -0,0 +1 @@ +{{{fullSwagger}}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaVertXServer/vertx-default-jul-logging.mustache b/modules/swagger-codegen/src/main/resources/JavaVertXServer/vertx-default-jul-logging.mustache new file mode 100644 index 0000000000..706d6d9b2f --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaVertXServer/vertx-default-jul-logging.mustache @@ -0,0 +1,30 @@ +# +# Copyright 2014 Red Hat, Inc. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# and Apache License v2.0 which accompanies this distribution. +# +# The Eclipse Public License is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# The Apache License v2.0 is available at +# http://www.opensource.org/licenses/apache2.0.php +# +# You may elect to redistribute this code under either of these licenses. +# +handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler +java.util.logging.SimpleFormatter.format=%5$s %6$s\n +java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter +java.util.logging.ConsoleHandler.level=FINEST +java.util.logging.FileHandler.level=INFO +java.util.logging.FileHandler.formatter=io.vertx.core.logging.VertxLoggerFormatter + +# Put the log in the system temporary directory +java.util.logging.FileHandler.pattern=vertx.log + +.level=INFO +io.vertx.ext.web.level=FINEST +io.vertx.level=INFO +com.hazelcast.level=INFO +io.netty.util.internal.PlatformDependent.level=SEVERE \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig b/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig index 0775ba1654..6e8c165f87 100644 --- a/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig +++ b/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig @@ -36,6 +36,7 @@ io.swagger.codegen.languages.JavaResteasyEapServerCodegen io.swagger.codegen.languages.JavaResteasyServerCodegen io.swagger.codegen.languages.JavascriptClientCodegen io.swagger.codegen.languages.JavascriptClosureAngularClientCodegen +io.swagger.codegen.languages.JavaVertXServerCodegen io.swagger.codegen.languages.KotlinClientCodegen io.swagger.codegen.languages.LumenServerCodegen io.swagger.codegen.languages.NancyFXServerCodegen diff --git a/samples/server/petstore/java-vertx/async/.swagger-codegen-ignore b/samples/server/petstore/java-vertx/async/.swagger-codegen-ignore new file mode 100644 index 0000000000..c5fa491b4c --- /dev/null +++ b/samples/server/petstore/java-vertx/async/.swagger-codegen-ignore @@ -0,0 +1,23 @@ +# Swagger Codegen Ignore +# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/server/petstore/java-vertx/async/.swagger-codegen/VERSION b/samples/server/petstore/java-vertx/async/.swagger-codegen/VERSION new file mode 100644 index 0000000000..7fea99011a --- /dev/null +++ b/samples/server/petstore/java-vertx/async/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/java-vertx/async/README.md b/samples/server/petstore/java-vertx/async/README.md new file mode 100644 index 0000000000..7f4534629b --- /dev/null +++ b/samples/server/petstore/java-vertx/async/README.md @@ -0,0 +1 @@ +Project generated on : 2017-07-08T16:03:02.953+02:00 diff --git a/samples/server/petstore/java-vertx/async/pom.xml b/samples/server/petstore/java-vertx/async/pom.xml new file mode 100644 index 0000000000..8e1a96f88e --- /dev/null +++ b/samples/server/petstore/java-vertx/async/pom.xml @@ -0,0 +1,91 @@ + + 4.0.0 + + io.swagger + swagger-java-vertx-server + 1.0.0-SNAPSHOT + jar + + Swagger Petstore + + + UTF-8 + 1.8 + 4.12 + 3.4.1 + 3.3 + 1.2.0 + 2.3 + 2.7.4 + + + + + junit + junit + ${junit.version} + test + + + + io.vertx + vertx-unit + ${vertx.version} + test + + + + com.github.phiz71 + vertx-swagger-router + ${vertx-swagger-router.version} + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson-datatype-jsr310.version} + + + + + + + + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${java.version} + ${java.version} + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven-shade-plugin.version} + + + package + + shade + + + + + + io.vertx.core.Starter + io.swagger.server.api.MainApiVerticle + + + + + ${project.build.directory}/${project.artifactId}-${project.version}-fat.jar + + + + + + + \ No newline at end of file diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/MainApiException.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/MainApiException.java new file mode 100644 index 0000000000..8eb8f720d6 --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/MainApiException.java @@ -0,0 +1,22 @@ +package io.swagger.server.api; + +public class MainApiException extends Exception { + private int statusCode; + private String statusMessage; + + public MainApiException(int statusCode, String statusMessage) { + super(); + this.statusCode = statusCode; + this.statusMessage = statusMessage; + } + + public int getStatusCode() { + return statusCode; + } + + public String getStatusMessage() { + return statusMessage; + } + + public static final MainApiException INTERNAL_SERVER_ERROR = new MainApiException(500, "Internal Server Error"); +} \ No newline at end of file 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 new file mode 100644 index 0000000000..8fb3ae2f3c --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/MainApiVerticle.java @@ -0,0 +1,75 @@ +package io.swagger.server.api; + +import java.nio.charset.Charset; + +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.github.phiz71.vertx.swagger.router.OperationIdServiceIdResolver; +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.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.ext.web.Router; + +public class MainApiVerticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger(MainApiVerticle.class); + + final Router router = Router.router(vertx); + + @Override + public void start(Future startFuture) throws Exception { + Json.mapper.registerModule(new JavaTimeModule()); + FileSystem vertxFileSystem = vertx.fileSystem(); + 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()); + + deployVerticles(startFuture); + + vertx.createHttpServer() + .requestHandler(swaggerRouter::accept) + .listen(8080); + startFuture.complete(); + } else { + startFuture.fail(readFile.cause()); + } + }); + } + + public void deployVerticles(Future startFuture) { + + vertx.deployVerticle("io.swagger.server.api.verticle.PetApiVerticle", res -> { + if (res.succeeded()) { + LOGGER.info("PetApiVerticle : Deployed"); + } else { + startFuture.fail(res.cause()); + LOGGER.error("PetApiVerticle : Deployement failed"); + } + }); + + vertx.deployVerticle("io.swagger.server.api.verticle.StoreApiVerticle", res -> { + if (res.succeeded()) { + LOGGER.info("StoreApiVerticle : Deployed"); + } else { + startFuture.fail(res.cause()); + LOGGER.error("StoreApiVerticle : Deployement failed"); + } + }); + + vertx.deployVerticle("io.swagger.server.api.verticle.UserApiVerticle", res -> { + if (res.succeeded()) { + LOGGER.info("UserApiVerticle : Deployed"); + } else { + startFuture.fail(res.cause()); + LOGGER.error("UserApiVerticle : Deployement failed"); + } + }); + + } +} \ No newline at end of file diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/Category.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/Category.java new file mode 100644 index 0000000000..1065963542 --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/Category.java @@ -0,0 +1,83 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A category for a pet + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Category { + + private Long id = null; + private String name = null; + + public Category () { + + } + + public Category (Long id, String name) { + this.id = id; + this.name = name; + } + + + @JsonProperty("id") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + @JsonProperty("name") + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Category category = (Category) o; + return Objects.equals(id, category.id) && + Objects.equals(name, category.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Category {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/ModelApiResponse.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/ModelApiResponse.java new file mode 100644 index 0000000000..ef5261c7ed --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/ModelApiResponse.java @@ -0,0 +1,96 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Describes the result of uploading an image resource + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ModelApiResponse { + + private Integer code = null; + private String type = null; + private String message = null; + + public ModelApiResponse () { + + } + + public ModelApiResponse (Integer code, String type, String message) { + this.code = code; + this.type = type; + this.message = message; + } + + + @JsonProperty("code") + public Integer getCode() { + return code; + } + public void setCode(Integer code) { + this.code = code; + } + + + @JsonProperty("type") + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + + @JsonProperty("message") + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ModelApiResponse _apiResponse = (ModelApiResponse) o; + return Objects.equals(code, _apiResponse.code) && + Objects.equals(type, _apiResponse.type) && + Objects.equals(message, _apiResponse.message); + } + + @Override + public int hashCode() { + return Objects.hash(code, type, message); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ModelApiResponse {\n"); + + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" message: ").append(toIndentedString(message)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/Order.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/Order.java new file mode 100644 index 0000000000..9e7d41ff04 --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/Order.java @@ -0,0 +1,157 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.time.OffsetDateTime; + +/** + * An order for a pets from the pet store + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Order { + + private Long id = null; + private Long petId = null; + private Integer quantity = null; + private OffsetDateTime shipDate = null; + + + public enum StatusEnum { + PLACED("placed"), + APPROVED("approved"), + DELIVERED("delivered"); + + private String value; + + StatusEnum(String value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return value; + } + } + + private StatusEnum status = null; + private Boolean complete = false; + + public Order () { + + } + + public Order (Long id, Long petId, Integer quantity, OffsetDateTime shipDate, StatusEnum status, Boolean complete) { + this.id = id; + this.petId = petId; + this.quantity = quantity; + this.shipDate = shipDate; + this.status = status; + this.complete = complete; + } + + + @JsonProperty("id") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + @JsonProperty("petId") + public Long getPetId() { + return petId; + } + public void setPetId(Long petId) { + this.petId = petId; + } + + + @JsonProperty("quantity") + public Integer getQuantity() { + return quantity; + } + public void setQuantity(Integer quantity) { + this.quantity = quantity; + } + + + @JsonProperty("shipDate") + public OffsetDateTime getShipDate() { + return shipDate; + } + public void setShipDate(OffsetDateTime shipDate) { + this.shipDate = shipDate; + } + + + @JsonProperty("status") + public StatusEnum getStatus() { + return status; + } + public void setStatus(StatusEnum status) { + this.status = status; + } + + + @JsonProperty("complete") + public Boolean getComplete() { + return complete; + } + public void setComplete(Boolean complete) { + this.complete = complete; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Order order = (Order) o; + return Objects.equals(id, order.id) && + Objects.equals(petId, order.petId) && + Objects.equals(quantity, order.quantity) && + Objects.equals(shipDate, order.shipDate) && + Objects.equals(status, order.status) && + Objects.equals(complete, order.complete); + } + + @Override + public int hashCode() { + return Objects.hash(id, petId, quantity, shipDate, status, complete); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Order {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" petId: ").append(toIndentedString(petId)).append("\n"); + sb.append(" quantity: ").append(toIndentedString(quantity)).append("\n"); + sb.append(" shipDate: ").append(toIndentedString(shipDate)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" complete: ").append(toIndentedString(complete)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/Pet.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/Pet.java new file mode 100644 index 0000000000..8b3181be26 --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/Pet.java @@ -0,0 +1,160 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import io.swagger.server.api.model.Category; +import io.swagger.server.api.model.Tag; +import java.util.ArrayList; +import java.util.List; + +/** + * A pet for sale in the pet store + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Pet { + + private Long id = null; + private Category category = null; + private String name = null; + private List photoUrls = new ArrayList(); + private List tags = new ArrayList(); + + + public enum StatusEnum { + AVAILABLE("available"), + PENDING("pending"), + SOLD("sold"); + + private String value; + + StatusEnum(String value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return value; + } + } + + private StatusEnum status = null; + + public Pet () { + + } + + public Pet (Long id, Category category, String name, List photoUrls, List tags, StatusEnum status) { + this.id = id; + this.category = category; + this.name = name; + this.photoUrls = photoUrls; + this.tags = tags; + this.status = status; + } + + + @JsonProperty("id") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + @JsonProperty("category") + public Category getCategory() { + return category; + } + public void setCategory(Category category) { + this.category = category; + } + + + @JsonProperty("name") + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + + @JsonProperty("photoUrls") + public List getPhotoUrls() { + return photoUrls; + } + public void setPhotoUrls(List photoUrls) { + this.photoUrls = photoUrls; + } + + + @JsonProperty("tags") + public List getTags() { + return tags; + } + public void setTags(List tags) { + this.tags = tags; + } + + + @JsonProperty("status") + public StatusEnum getStatus() { + return status; + } + public void setStatus(StatusEnum status) { + this.status = status; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Pet pet = (Pet) o; + return Objects.equals(id, pet.id) && + Objects.equals(category, pet.category) && + Objects.equals(name, pet.name) && + Objects.equals(photoUrls, pet.photoUrls) && + Objects.equals(tags, pet.tags) && + Objects.equals(status, pet.status); + } + + @Override + public int hashCode() { + return Objects.hash(id, category, name, photoUrls, tags, status); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Pet {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" category: ").append(toIndentedString(category)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" photoUrls: ").append(toIndentedString(photoUrls)).append("\n"); + sb.append(" tags: ").append(toIndentedString(tags)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/Tag.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/Tag.java new file mode 100644 index 0000000000..f00a458e3d --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/Tag.java @@ -0,0 +1,83 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A tag for a pet + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Tag { + + private Long id = null; + private String name = null; + + public Tag () { + + } + + public Tag (Long id, String name) { + this.id = id; + this.name = name; + } + + + @JsonProperty("id") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + @JsonProperty("name") + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Tag tag = (Tag) o; + return Objects.equals(id, tag.id) && + Objects.equals(name, tag.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Tag {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/User.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/User.java new file mode 100644 index 0000000000..6e7331cd23 --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/model/User.java @@ -0,0 +1,161 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A User who is purchasing from the pet store + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class User { + + private Long id = null; + private String username = null; + private String firstName = null; + private String lastName = null; + private String email = null; + private String password = null; + private String phone = null; + private Integer userStatus = null; + + public User () { + + } + + public User (Long id, String username, String firstName, String lastName, String email, String password, String phone, Integer userStatus) { + this.id = id; + this.username = username; + this.firstName = firstName; + this.lastName = lastName; + this.email = email; + this.password = password; + this.phone = phone; + this.userStatus = userStatus; + } + + + @JsonProperty("id") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + @JsonProperty("username") + public String getUsername() { + return username; + } + public void setUsername(String username) { + this.username = username; + } + + + @JsonProperty("firstName") + public String getFirstName() { + return firstName; + } + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + + @JsonProperty("lastName") + public String getLastName() { + return lastName; + } + public void setLastName(String lastName) { + this.lastName = lastName; + } + + + @JsonProperty("email") + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + + + @JsonProperty("password") + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } + + + @JsonProperty("phone") + public String getPhone() { + return phone; + } + public void setPhone(String phone) { + this.phone = phone; + } + + + @JsonProperty("userStatus") + public Integer getUserStatus() { + return userStatus; + } + public void setUserStatus(Integer userStatus) { + this.userStatus = userStatus; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + User user = (User) o; + return Objects.equals(id, user.id) && + Objects.equals(username, user.username) && + Objects.equals(firstName, user.firstName) && + Objects.equals(lastName, user.lastName) && + Objects.equals(email, user.email) && + Objects.equals(password, user.password) && + Objects.equals(phone, user.phone) && + Objects.equals(userStatus, user.userStatus); + } + + @Override + public int hashCode() { + return Objects.hash(id, username, firstName, lastName, email, password, phone, userStatus); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class User {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" username: ").append(toIndentedString(username)).append("\n"); + sb.append(" firstName: ").append(toIndentedString(firstName)).append("\n"); + sb.append(" lastName: ").append(toIndentedString(lastName)).append("\n"); + sb.append(" email: ").append(toIndentedString(email)).append("\n"); + sb.append(" password: ").append(toIndentedString(password)).append("\n"); + sb.append(" phone: ").append(toIndentedString(phone)).append("\n"); + sb.append(" userStatus: ").append(toIndentedString(userStatus)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/PetApi.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/PetApi.java new file mode 100644 index 0000000000..7c7849563e --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/PetApi.java @@ -0,0 +1,39 @@ +package io.swagger.server.api.verticle; + +import java.io.File; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.ModelApiResponse; +import io.swagger.server.api.model.Pet; + +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; + +import java.util.List; +import java.util.Map; + +public interface PetApi { + //addPet + void addPet(Pet body, Handler> handler); + + //deletePet + void deletePet(Long petId, String apiKey, Handler> handler); + + //findPetsByStatus + void findPetsByStatus(List status, Handler>> handler); + + //findPetsByTags + void findPetsByTags(List tags, Handler>> handler); + + //getPetById + void getPetById(Long petId, Handler> handler); + + //updatePet + void updatePet(Pet body, Handler> handler); + + //updatePetWithForm + void updatePetWithForm(Long petId, String name, String status, Handler> handler); + + //uploadFile + void uploadFile(Long petId, String additionalMetadata, File file, Handler> handler); + +} diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/PetApiException.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/PetApiException.java new file mode 100644 index 0000000000..c618e243e0 --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/PetApiException.java @@ -0,0 +1,25 @@ +package io.swagger.server.api.verticle; + +import java.io.File; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.ModelApiResponse; +import io.swagger.server.api.model.Pet; + +public final class PetApiException extends MainApiException { + public PetApiException(int statusCode, String statusMessage) { + super(statusCode, statusMessage); + } + + public static final PetApiException Pet_addPet_405_Exception = new PetApiException(405, "Invalid input"); + public static final PetApiException Pet_deletePet_400_Exception = new PetApiException(400, "Invalid pet value"); + public static final PetApiException Pet_findPetsByStatus_400_Exception = new PetApiException(400, "Invalid status value"); + public static final PetApiException Pet_findPetsByTags_400_Exception = new PetApiException(400, "Invalid tag value"); + public static final PetApiException Pet_getPetById_400_Exception = new PetApiException(400, "Invalid ID supplied"); + public static final PetApiException Pet_getPetById_404_Exception = new PetApiException(404, "Pet not found"); + public static final PetApiException Pet_updatePet_400_Exception = new PetApiException(400, "Invalid ID supplied"); + public static final PetApiException Pet_updatePet_404_Exception = new PetApiException(404, "Pet not found"); + public static final PetApiException Pet_updatePet_405_Exception = new PetApiException(405, "Validation exception"); + public static final PetApiException Pet_updatePetWithForm_405_Exception = new PetApiException(405, "Invalid input"); + + +} \ 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 new file mode 100644 index 0000000000..fb3c20944f --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/PetApiVerticle.java @@ -0,0 +1,206 @@ +package io.swagger.server.api.verticle; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.eventbus.Message; +import io.vertx.core.json.Json; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; + +import java.io.File; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.ModelApiResponse; +import io.swagger.server.api.model.Pet; + +import java.util.List; +import java.util.Map; + +public class PetApiVerticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger(PetApiVerticle.class); + + final static String ADDPET_SERVICE_ID = "addPet"; + final static String DELETEPET_SERVICE_ID = "deletePet"; + final static String FINDPETSBYSTATUS_SERVICE_ID = "findPetsByStatus"; + final static String FINDPETSBYTAGS_SERVICE_ID = "findPetsByTags"; + final static String GETPETBYID_SERVICE_ID = "getPetById"; + final static String UPDATEPET_SERVICE_ID = "updatePet"; + final static String UPDATEPETWITHFORM_SERVICE_ID = "updatePetWithForm"; + final static String UPLOADFILE_SERVICE_ID = "uploadFile"; + + //TODO : create Implementation + PetApi service = new PetApiImpl(); + + @Override + public void start() throws Exception { + + //Consumer for addPet + vertx.eventBus(). consumer(ADDPET_SERVICE_ID).handler(message -> { + try { + Pet body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), Pet.class); + service.addPet(body, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "addPet"); + } + }); + } catch (Exception e) { + logUnexpectedError("addPet", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //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"); + service.deletePet(petId, apiKey, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "deletePet"); + } + }); + } catch (Exception e) { + logUnexpectedError("deletePet", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //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)); + service.findPetsByStatus(status, result -> { + if (result.succeeded()) + message.reply(new JsonArray(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "findPetsByStatus"); + } + }); + } catch (Exception e) { + logUnexpectedError("findPetsByStatus", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //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)); + service.findPetsByTags(tags, result -> { + if (result.succeeded()) + message.reply(new JsonArray(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "findPetsByTags"); + } + }); + } catch (Exception e) { + logUnexpectedError("findPetsByTags", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for getPetById + vertx.eventBus(). consumer(GETPETBYID_SERVICE_ID).handler(message -> { + try { + Long petId = Json.mapper.readValue(message.body().getString("petId"), Long.class); + service.getPetById(petId, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "getPetById"); + } + }); + } catch (Exception e) { + logUnexpectedError("getPetById", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for updatePet + vertx.eventBus(). consumer(UPDATEPET_SERVICE_ID).handler(message -> { + try { + Pet body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), Pet.class); + service.updatePet(body, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "updatePet"); + } + }); + } catch (Exception e) { + logUnexpectedError("updatePet", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //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"); + service.updatePetWithForm(petId, name, status, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "updatePetWithForm"); + } + }); + } catch (Exception e) { + logUnexpectedError("updatePetWithForm", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //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); + service.uploadFile(petId, additionalMetadata, file, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "uploadFile"); + } + }); + } catch (Exception e) { + logUnexpectedError("uploadFile", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + } + + private void manageError(Message message, Throwable cause, String serviceName) { + int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); + String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); + if (cause instanceof MainApiException) { + code = ((MainApiException)cause).getStatusCode(); + statusMessage = ((MainApiException)cause).getStatusMessage(); + } else { + logUnexpectedError(serviceName, cause); + } + + message.fail(code, statusMessage); + } + + private void logUnexpectedError(String serviceName, Throwable cause) { + LOGGER.error("Unexpected error in "+ serviceName, cause); + } +} diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/StoreApi.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/StoreApi.java new file mode 100644 index 0000000000..dc26dd8d30 --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/StoreApi.java @@ -0,0 +1,25 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.Order; + +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; + +import java.util.List; +import java.util.Map; + +public interface StoreApi { + //deleteOrder + void deleteOrder(String orderId, Handler> handler); + + //getInventory + void getInventory(Handler>> handler); + + //getOrderById + void getOrderById(Long orderId, Handler> handler); + + //placeOrder + void placeOrder(Order body, Handler> handler); + +} diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/StoreApiException.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/StoreApiException.java new file mode 100644 index 0000000000..3b8f0ab204 --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/StoreApiException.java @@ -0,0 +1,18 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.Order; + +public final class StoreApiException extends MainApiException { + public StoreApiException(int statusCode, String statusMessage) { + super(statusCode, statusMessage); + } + + public static final StoreApiException Store_deleteOrder_400_Exception = new StoreApiException(400, "Invalid ID supplied"); + public static final StoreApiException Store_deleteOrder_404_Exception = new StoreApiException(404, "Order not found"); + public static final StoreApiException Store_getOrderById_400_Exception = new StoreApiException(400, "Invalid ID supplied"); + public static final StoreApiException Store_getOrderById_404_Exception = new StoreApiException(404, "Order not found"); + public static final StoreApiException Store_placeOrder_400_Exception = new StoreApiException(400, "Invalid Order"); + + +} \ No newline at end of file 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 new file mode 100644 index 0000000000..9299a08e01 --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/StoreApiVerticle.java @@ -0,0 +1,120 @@ +package io.swagger.server.api.verticle; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.eventbus.Message; +import io.vertx.core.json.Json; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; + +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.Order; + +import java.util.List; +import java.util.Map; + +public class StoreApiVerticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger(StoreApiVerticle.class); + + final static String DELETEORDER_SERVICE_ID = "deleteOrder"; + final static String GETINVENTORY_SERVICE_ID = "getInventory"; + final static String GETORDERBYID_SERVICE_ID = "getOrderById"; + final static String PLACEORDER_SERVICE_ID = "placeOrder"; + + //TODO : create Implementation + StoreApi service = new StoreApiImpl(); + + @Override + public void start() throws Exception { + + //Consumer for deleteOrder + vertx.eventBus(). consumer(DELETEORDER_SERVICE_ID).handler(message -> { + try { + String orderId = message.body().getString("orderId"); + service.deleteOrder(orderId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "deleteOrder"); + } + }); + } catch (Exception e) { + logUnexpectedError("deleteOrder", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for getInventory + vertx.eventBus(). consumer(GETINVENTORY_SERVICE_ID).handler(message -> { + try { + service.getInventory(result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "getInventory"); + } + }); + } catch (Exception e) { + logUnexpectedError("getInventory", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for getOrderById + vertx.eventBus(). consumer(GETORDERBYID_SERVICE_ID).handler(message -> { + try { + Long orderId = Json.mapper.readValue(message.body().getString("orderId"), Long.class); + service.getOrderById(orderId, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "getOrderById"); + } + }); + } catch (Exception e) { + logUnexpectedError("getOrderById", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for placeOrder + vertx.eventBus(). consumer(PLACEORDER_SERVICE_ID).handler(message -> { + try { + Order body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), Order.class); + service.placeOrder(body, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "placeOrder"); + } + }); + } catch (Exception e) { + logUnexpectedError("placeOrder", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + } + + private void manageError(Message message, Throwable cause, String serviceName) { + int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); + String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); + if (cause instanceof MainApiException) { + code = ((MainApiException)cause).getStatusCode(); + statusMessage = ((MainApiException)cause).getStatusMessage(); + } else { + logUnexpectedError(serviceName, cause); + } + + message.fail(code, statusMessage); + } + + private void logUnexpectedError(String serviceName, Throwable cause) { + LOGGER.error("Unexpected error in "+ serviceName, cause); + } +} diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/UserApi.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/UserApi.java new file mode 100644 index 0000000000..5de0be646c --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/UserApi.java @@ -0,0 +1,37 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.User; + +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; + +import java.util.List; +import java.util.Map; + +public interface UserApi { + //createUser + void createUser(User body, Handler> handler); + + //createUsersWithArrayInput + void createUsersWithArrayInput(List body, Handler> handler); + + //createUsersWithListInput + void createUsersWithListInput(List body, Handler> handler); + + //deleteUser + void deleteUser(String username, Handler> handler); + + //getUserByName + void getUserByName(String username, Handler> handler); + + //loginUser + void loginUser(String username, String password, Handler> handler); + + //logoutUser + void logoutUser(Handler> handler); + + //updateUser + void updateUser(String username, User body, Handler> handler); + +} diff --git a/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/UserApiException.java b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/UserApiException.java new file mode 100644 index 0000000000..337f5b4353 --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/UserApiException.java @@ -0,0 +1,20 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.User; + +public final class UserApiException extends MainApiException { + public UserApiException(int statusCode, String statusMessage) { + super(statusCode, statusMessage); + } + + public static final UserApiException User_deleteUser_400_Exception = new UserApiException(400, "Invalid username supplied"); + public static final UserApiException User_deleteUser_404_Exception = new UserApiException(404, "User not found"); + public static final UserApiException User_getUserByName_400_Exception = new UserApiException(400, "Invalid username supplied"); + public static final UserApiException User_getUserByName_404_Exception = new UserApiException(404, "User not found"); + public static final UserApiException User_loginUser_400_Exception = new UserApiException(400, "Invalid username/password supplied"); + public static final UserApiException User_updateUser_400_Exception = new UserApiException(400, "Invalid user supplied"); + public static final UserApiException User_updateUser_404_Exception = new UserApiException(404, "User not found"); + + +} \ No newline at end of file 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 new file mode 100644 index 0000000000..0ad1f5eb98 --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/UserApiVerticle.java @@ -0,0 +1,200 @@ +package io.swagger.server.api.verticle; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.eventbus.Message; +import io.vertx.core.json.Json; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; + +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.User; + +import java.util.List; +import java.util.Map; + +public class UserApiVerticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger(UserApiVerticle.class); + + final static String CREATEUSER_SERVICE_ID = "createUser"; + final static String CREATEUSERSWITHARRAYINPUT_SERVICE_ID = "createUsersWithArrayInput"; + final static String CREATEUSERSWITHLISTINPUT_SERVICE_ID = "createUsersWithListInput"; + final static String DELETEUSER_SERVICE_ID = "deleteUser"; + final static String GETUSERBYNAME_SERVICE_ID = "getUserByName"; + final static String LOGINUSER_SERVICE_ID = "loginUser"; + final static String LOGOUTUSER_SERVICE_ID = "logoutUser"; + final static String UPDATEUSER_SERVICE_ID = "updateUser"; + + //TODO : create Implementation + UserApi service = new UserApiImpl(); + + @Override + public void start() throws Exception { + + //Consumer for createUser + vertx.eventBus(). consumer(CREATEUSER_SERVICE_ID).handler(message -> { + try { + User body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), User.class); + service.createUser(body, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "createUser"); + } + }); + } catch (Exception e) { + logUnexpectedError("createUser", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //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)); + service.createUsersWithArrayInput(body, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "createUsersWithArrayInput"); + } + }); + } catch (Exception e) { + logUnexpectedError("createUsersWithArrayInput", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //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)); + service.createUsersWithListInput(body, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "createUsersWithListInput"); + } + }); + } catch (Exception e) { + logUnexpectedError("createUsersWithListInput", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for deleteUser + vertx.eventBus(). consumer(DELETEUSER_SERVICE_ID).handler(message -> { + try { + String username = message.body().getString("username"); + service.deleteUser(username, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "deleteUser"); + } + }); + } catch (Exception e) { + logUnexpectedError("deleteUser", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for getUserByName + vertx.eventBus(). consumer(GETUSERBYNAME_SERVICE_ID).handler(message -> { + try { + String username = message.body().getString("username"); + service.getUserByName(username, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "getUserByName"); + } + }); + } catch (Exception e) { + logUnexpectedError("getUserByName", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for loginUser + vertx.eventBus(). consumer(LOGINUSER_SERVICE_ID).handler(message -> { + try { + String username = message.body().getString("username"); + String password = message.body().getString("password"); + service.loginUser(username, password, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "loginUser"); + } + }); + } catch (Exception e) { + logUnexpectedError("loginUser", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for logoutUser + vertx.eventBus(). consumer(LOGOUTUSER_SERVICE_ID).handler(message -> { + try { + service.logoutUser(result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "logoutUser"); + } + }); + } catch (Exception e) { + logUnexpectedError("logoutUser", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //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); + service.updateUser(username, body, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "updateUser"); + } + }); + } catch (Exception e) { + logUnexpectedError("updateUser", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + } + + private void manageError(Message message, Throwable cause, String serviceName) { + int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); + String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); + if (cause instanceof MainApiException) { + code = ((MainApiException)cause).getStatusCode(); + statusMessage = ((MainApiException)cause).getStatusMessage(); + } else { + logUnexpectedError(serviceName, cause); + } + + message.fail(code, statusMessage); + } + + private void logUnexpectedError(String serviceName, Throwable cause) { + LOGGER.error("Unexpected error in "+ serviceName, cause); + } +} 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 new file mode 100644 index 0000000000..25192459c6 --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/resources/swagger.json @@ -0,0 +1,870 @@ +{ + "swagger" : "2.0", + "info" : { + "description" : "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.", + "version" : "1.0.0", + "title" : "Swagger Petstore", + "termsOfService" : "http://swagger.io/terms/", + "contact" : { + "email" : "apiteam@swagger.io" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host" : "petstore.swagger.io", + "basePath" : "/v2", + "tags" : [ { + "name" : "pet", + "description" : "Everything about your Pets", + "externalDocs" : { + "description" : "Find out more", + "url" : "http://swagger.io" + } + }, { + "name" : "store", + "description" : "Access to Petstore orders" + }, { + "name" : "user", + "description" : "Operations about user", + "externalDocs" : { + "description" : "Find out more about our store", + "url" : "http://swagger.io" + } + } ], + "schemes" : [ "http" ], + "paths" : { + "/pet" : { + "post" : { + "tags" : [ "pet" ], + "summary" : "Add a new pet to the store", + "description" : "", + "operationId" : "addPet", + "consumes" : [ "application/json", "application/xml" ], + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Pet object that needs to be added to the store", + "required" : true, + "schema" : { + "$ref" : "#/definitions/Pet" + } + } ], + "responses" : { + "405" : { + "description" : "Invalid input" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + }, + "put" : { + "tags" : [ "pet" ], + "summary" : "Update an existing pet", + "description" : "", + "operationId" : "updatePet", + "consumes" : [ "application/json", "application/xml" ], + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Pet object that needs to be added to the store", + "required" : true, + "schema" : { + "$ref" : "#/definitions/Pet" + } + } ], + "responses" : { + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Pet not found" + }, + "405" : { + "description" : "Validation exception" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/pet/findByStatus" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Finds Pets by status", + "description" : "Multiple status values can be provided with comma separated strings", + "operationId" : "findPetsByStatus", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "status", + "in" : "query", + "description" : "Status values that need to be considered for filter", + "required" : true, + "type" : "array", + "items" : { + "type" : "string", + "default" : "available", + "enum" : [ "available", "pending", "sold" ] + }, + "collectionFormat" : "csv" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Pet" + } + } + }, + "400" : { + "description" : "Invalid status value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/pet/findByTags" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Finds Pets by tags", + "description" : "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + "operationId" : "findPetsByTags", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "tags", + "in" : "query", + "description" : "Tags to filter by", + "required" : true, + "type" : "array", + "items" : { + "type" : "string" + }, + "collectionFormat" : "csv" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Pet" + } + } + }, + "400" : { + "description" : "Invalid tag value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/pet/{petId}" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Find pet by ID", + "description" : "Returns a single pet", + "operationId" : "getPetById", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet to return", + "required" : true, + "type" : "integer", + "format" : "int64" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/Pet" + } + }, + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Pet not found" + } + }, + "security" : [ { + "api_key" : [ ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + }, + "post" : { + "tags" : [ "pet" ], + "summary" : "Updates a pet in the store with form data", + "description" : "", + "operationId" : "updatePetWithForm", + "consumes" : [ "application/x-www-form-urlencoded" ], + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet that needs to be updated", + "required" : true, + "type" : "integer", + "format" : "int64" + }, { + "name" : "name", + "in" : "formData", + "description" : "Updated name of the pet", + "required" : false, + "type" : "string" + }, { + "name" : "status", + "in" : "formData", + "description" : "Updated status of the pet", + "required" : false, + "type" : "string" + } ], + "responses" : { + "405" : { + "description" : "Invalid input" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/x-www-form-urlencoded", + "x-accepts" : "application/json" + }, + "delete" : { + "tags" : [ "pet" ], + "summary" : "Deletes a pet", + "description" : "", + "operationId" : "deletePet", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "api_key", + "in" : "header", + "required" : false, + "type" : "string" + }, { + "name" : "petId", + "in" : "path", + "description" : "Pet id to delete", + "required" : true, + "type" : "integer", + "format" : "int64" + } ], + "responses" : { + "400" : { + "description" : "Invalid pet value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/pet/{petId}/uploadImage" : { + "post" : { + "tags" : [ "pet" ], + "summary" : "uploads an image", + "description" : "", + "operationId" : "uploadFile", + "consumes" : [ "multipart/form-data" ], + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet to update", + "required" : true, + "type" : "integer", + "format" : "int64" + }, { + "name" : "additionalMetadata", + "in" : "formData", + "description" : "Additional data to pass to server", + "required" : false, + "type" : "string" + }, { + "name" : "file", + "in" : "formData", + "description" : "file to upload", + "required" : false, + "type" : "file" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/ApiResponse" + } + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "multipart/form-data", + "x-accepts" : "application/json" + } + }, + "/store/inventory" : { + "get" : { + "tags" : [ "store" ], + "summary" : "Returns pet inventories by status", + "description" : "Returns a map of status codes to quantities", + "operationId" : "getInventory", + "produces" : [ "application/json" ], + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "object", + "additionalProperties" : { + "type" : "integer", + "format" : "int32" + } + } + } + }, + "security" : [ { + "api_key" : [ ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/store/order" : { + "post" : { + "tags" : [ "store" ], + "summary" : "Place an order for a pet", + "description" : "", + "operationId" : "placeOrder", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "order placed for purchasing the pet", + "required" : true, + "schema" : { + "$ref" : "#/definitions/Order" + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/Order" + } + }, + "400" : { + "description" : "Invalid Order" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/store/order/{orderId}" : { + "get" : { + "tags" : [ "store" ], + "summary" : "Find purchase order by ID", + "description" : "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", + "operationId" : "getOrderById", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "orderId", + "in" : "path", + "description" : "ID of pet that needs to be fetched", + "required" : true, + "type" : "integer", + "maximum" : 5, + "minimum" : 1, + "format" : "int64" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/Order" + } + }, + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Order not found" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + }, + "delete" : { + "tags" : [ "store" ], + "summary" : "Delete purchase order by ID", + "description" : "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", + "operationId" : "deleteOrder", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "orderId", + "in" : "path", + "description" : "ID of the order that needs to be deleted", + "required" : true, + "type" : "string" + } ], + "responses" : { + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Order not found" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Create user", + "description" : "This can only be done by the logged in user.", + "operationId" : "createUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Created user object", + "required" : true, + "schema" : { + "$ref" : "#/definitions/User" + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user/createWithArray" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Creates list of users with given input array", + "description" : "", + "operationId" : "createUsersWithArrayInput", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "List of user object", + "required" : true, + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/User" + } + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user/createWithList" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Creates list of users with given input array", + "description" : "", + "operationId" : "createUsersWithListInput", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "List of user object", + "required" : true, + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/User" + } + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user/login" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Logs user into the system", + "description" : "", + "operationId" : "loginUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "query", + "description" : "The user name for login", + "required" : true, + "type" : "string" + }, { + "name" : "password", + "in" : "query", + "description" : "The password for login in clear text", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "string" + }, + "headers" : { + "X-Rate-Limit" : { + "type" : "integer", + "format" : "int32", + "description" : "calls per hour allowed by the user" + }, + "X-Expires-After" : { + "type" : "string", + "format" : "date-time", + "description" : "date in UTC when toekn expires" + } + } + }, + "400" : { + "description" : "Invalid username/password supplied" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user/logout" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Logs out current logged in user session", + "description" : "", + "operationId" : "logoutUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user/{username}" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Get user by user name", + "description" : "", + "operationId" : "getUserByName", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "The name that needs to be fetched. Use user1 for testing. ", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/User" + } + }, + "400" : { + "description" : "Invalid username supplied" + }, + "404" : { + "description" : "User not found" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + }, + "put" : { + "tags" : [ "user" ], + "summary" : "Updated user", + "description" : "This can only be done by the logged in user.", + "operationId" : "updateUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "name that need to be deleted", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "body", + "description" : "Updated user object", + "required" : true, + "schema" : { + "$ref" : "#/definitions/User" + } + } ], + "responses" : { + "400" : { + "description" : "Invalid user supplied" + }, + "404" : { + "description" : "User not found" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + }, + "delete" : { + "tags" : [ "user" ], + "summary" : "Delete user", + "description" : "This can only be done by the logged in user.", + "operationId" : "deleteUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "The name that needs to be deleted", + "required" : true, + "type" : "string" + } ], + "responses" : { + "400" : { + "description" : "Invalid username supplied" + }, + "404" : { + "description" : "User not found" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + } + }, + "securityDefinitions" : { + "petstore_auth" : { + "type" : "oauth2", + "authorizationUrl" : "http://petstore.swagger.io/api/oauth/dialog", + "flow" : "implicit", + "scopes" : { + "write:pets" : "modify pets in your account", + "read:pets" : "read your pets" + } + }, + "api_key" : { + "type" : "apiKey", + "name" : "api_key", + "in" : "header" + } + }, + "definitions" : { + "Order" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "petId" : { + "type" : "integer", + "format" : "int64" + }, + "quantity" : { + "type" : "integer", + "format" : "int32" + }, + "shipDate" : { + "type" : "string", + "format" : "date-time" + }, + "status" : { + "type" : "string", + "description" : "Order Status", + "enum" : [ "placed", "approved", "delivered" ] + }, + "complete" : { + "type" : "boolean", + "default" : false + } + }, + "title" : "Pet Order", + "description" : "An order for a pets from the pet store", + "xml" : { + "name" : "Order" + } + }, + "Category" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "name" : { + "type" : "string" + } + }, + "title" : "Pet catehgry", + "description" : "A category for a pet", + "xml" : { + "name" : "Category" + } + }, + "User" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "username" : { + "type" : "string" + }, + "firstName" : { + "type" : "string" + }, + "lastName" : { + "type" : "string" + }, + "email" : { + "type" : "string" + }, + "password" : { + "type" : "string" + }, + "phone" : { + "type" : "string" + }, + "userStatus" : { + "type" : "integer", + "format" : "int32", + "description" : "User Status" + } + }, + "title" : "a User", + "description" : "A User who is purchasing from the pet store", + "xml" : { + "name" : "User" + } + }, + "Tag" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "name" : { + "type" : "string" + } + }, + "title" : "Pet Tag", + "description" : "A tag for a pet", + "xml" : { + "name" : "Tag" + } + }, + "Pet" : { + "type" : "object", + "required" : [ "name", "photoUrls" ], + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "category" : { + "$ref" : "#/definitions/Category" + }, + "name" : { + "type" : "string", + "example" : "doggie" + }, + "photoUrls" : { + "type" : "array", + "xml" : { + "name" : "photoUrl", + "wrapped" : true + }, + "items" : { + "type" : "string" + } + }, + "tags" : { + "type" : "array", + "xml" : { + "name" : "tag", + "wrapped" : true + }, + "items" : { + "$ref" : "#/definitions/Tag" + } + }, + "status" : { + "type" : "string", + "description" : "pet status in the store", + "enum" : [ "available", "pending", "sold" ] + } + }, + "title" : "a Pet", + "description" : "A pet for sale in the pet store", + "xml" : { + "name" : "Pet" + } + }, + "ApiResponse" : { + "type" : "object", + "properties" : { + "code" : { + "type" : "integer", + "format" : "int32" + }, + "type" : { + "type" : "string" + }, + "message" : { + "type" : "string" + } + }, + "title" : "An uploaded response", + "description" : "Describes the result of uploading an image resource" + } + }, + "externalDocs" : { + "description" : "Find out more about Swagger", + "url" : "http://swagger.io" + } +} \ No newline at end of file diff --git a/samples/server/petstore/java-vertx/async/src/main/resources/vertx-default-jul-logging.properties b/samples/server/petstore/java-vertx/async/src/main/resources/vertx-default-jul-logging.properties new file mode 100644 index 0000000000..706d6d9b2f --- /dev/null +++ b/samples/server/petstore/java-vertx/async/src/main/resources/vertx-default-jul-logging.properties @@ -0,0 +1,30 @@ +# +# Copyright 2014 Red Hat, Inc. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# and Apache License v2.0 which accompanies this distribution. +# +# The Eclipse Public License is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# The Apache License v2.0 is available at +# http://www.opensource.org/licenses/apache2.0.php +# +# You may elect to redistribute this code under either of these licenses. +# +handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler +java.util.logging.SimpleFormatter.format=%5$s %6$s\n +java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter +java.util.logging.ConsoleHandler.level=FINEST +java.util.logging.FileHandler.level=INFO +java.util.logging.FileHandler.formatter=io.vertx.core.logging.VertxLoggerFormatter + +# Put the log in the system temporary directory +java.util.logging.FileHandler.pattern=vertx.log + +.level=INFO +io.vertx.ext.web.level=FINEST +io.vertx.level=INFO +com.hazelcast.level=INFO +io.netty.util.internal.PlatformDependent.level=SEVERE \ No newline at end of file diff --git a/samples/server/petstore/java-vertx/rx/.swagger-codegen-ignore b/samples/server/petstore/java-vertx/rx/.swagger-codegen-ignore new file mode 100644 index 0000000000..c5fa491b4c --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/.swagger-codegen-ignore @@ -0,0 +1,23 @@ +# Swagger Codegen Ignore +# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/server/petstore/java-vertx/rx/.swagger-codegen/VERSION b/samples/server/petstore/java-vertx/rx/.swagger-codegen/VERSION new file mode 100644 index 0000000000..7fea99011a --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/java-vertx/rx/README.md b/samples/server/petstore/java-vertx/rx/README.md new file mode 100644 index 0000000000..4e3fdccda9 --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/README.md @@ -0,0 +1 @@ +Project generated on : 2017-07-08T16:03:26.358+02:00 diff --git a/samples/server/petstore/java-vertx/rx/pom.xml b/samples/server/petstore/java-vertx/rx/pom.xml new file mode 100644 index 0000000000..8e1a96f88e --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/pom.xml @@ -0,0 +1,91 @@ + + 4.0.0 + + io.swagger + swagger-java-vertx-server + 1.0.0-SNAPSHOT + jar + + Swagger Petstore + + + UTF-8 + 1.8 + 4.12 + 3.4.1 + 3.3 + 1.2.0 + 2.3 + 2.7.4 + + + + + junit + junit + ${junit.version} + test + + + + io.vertx + vertx-unit + ${vertx.version} + test + + + + com.github.phiz71 + vertx-swagger-router + ${vertx-swagger-router.version} + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson-datatype-jsr310.version} + + + + + + + + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${java.version} + ${java.version} + + + + + org.apache.maven.plugins + maven-shade-plugin + ${maven-shade-plugin.version} + + + package + + shade + + + + + + io.vertx.core.Starter + io.swagger.server.api.MainApiVerticle + + + + + ${project.build.directory}/${project.artifactId}-${project.version}-fat.jar + + + + + + + \ No newline at end of file diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/MainApiException.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/MainApiException.java new file mode 100644 index 0000000000..8eb8f720d6 --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/MainApiException.java @@ -0,0 +1,22 @@ +package io.swagger.server.api; + +public class MainApiException extends Exception { + private int statusCode; + private String statusMessage; + + public MainApiException(int statusCode, String statusMessage) { + super(); + this.statusCode = statusCode; + this.statusMessage = statusMessage; + } + + public int getStatusCode() { + return statusCode; + } + + public String getStatusMessage() { + return statusMessage; + } + + public static final MainApiException INTERNAL_SERVER_ERROR = new MainApiException(500, "Internal Server Error"); +} \ No newline at end of file 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 new file mode 100644 index 0000000000..8fb3ae2f3c --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/MainApiVerticle.java @@ -0,0 +1,75 @@ +package io.swagger.server.api; + +import java.nio.charset.Charset; + +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.github.phiz71.vertx.swagger.router.OperationIdServiceIdResolver; +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.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.ext.web.Router; + +public class MainApiVerticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger(MainApiVerticle.class); + + final Router router = Router.router(vertx); + + @Override + public void start(Future startFuture) throws Exception { + Json.mapper.registerModule(new JavaTimeModule()); + FileSystem vertxFileSystem = vertx.fileSystem(); + 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()); + + deployVerticles(startFuture); + + vertx.createHttpServer() + .requestHandler(swaggerRouter::accept) + .listen(8080); + startFuture.complete(); + } else { + startFuture.fail(readFile.cause()); + } + }); + } + + public void deployVerticles(Future startFuture) { + + vertx.deployVerticle("io.swagger.server.api.verticle.PetApiVerticle", res -> { + if (res.succeeded()) { + LOGGER.info("PetApiVerticle : Deployed"); + } else { + startFuture.fail(res.cause()); + LOGGER.error("PetApiVerticle : Deployement failed"); + } + }); + + vertx.deployVerticle("io.swagger.server.api.verticle.StoreApiVerticle", res -> { + if (res.succeeded()) { + LOGGER.info("StoreApiVerticle : Deployed"); + } else { + startFuture.fail(res.cause()); + LOGGER.error("StoreApiVerticle : Deployement failed"); + } + }); + + vertx.deployVerticle("io.swagger.server.api.verticle.UserApiVerticle", res -> { + if (res.succeeded()) { + LOGGER.info("UserApiVerticle : Deployed"); + } else { + startFuture.fail(res.cause()); + LOGGER.error("UserApiVerticle : Deployement failed"); + } + }); + + } +} \ No newline at end of file diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/Category.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/Category.java new file mode 100644 index 0000000000..1065963542 --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/Category.java @@ -0,0 +1,83 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A category for a pet + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Category { + + private Long id = null; + private String name = null; + + public Category () { + + } + + public Category (Long id, String name) { + this.id = id; + this.name = name; + } + + + @JsonProperty("id") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + @JsonProperty("name") + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Category category = (Category) o; + return Objects.equals(id, category.id) && + Objects.equals(name, category.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Category {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/ModelApiResponse.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/ModelApiResponse.java new file mode 100644 index 0000000000..ef5261c7ed --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/ModelApiResponse.java @@ -0,0 +1,96 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Describes the result of uploading an image resource + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ModelApiResponse { + + private Integer code = null; + private String type = null; + private String message = null; + + public ModelApiResponse () { + + } + + public ModelApiResponse (Integer code, String type, String message) { + this.code = code; + this.type = type; + this.message = message; + } + + + @JsonProperty("code") + public Integer getCode() { + return code; + } + public void setCode(Integer code) { + this.code = code; + } + + + @JsonProperty("type") + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + + @JsonProperty("message") + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ModelApiResponse _apiResponse = (ModelApiResponse) o; + return Objects.equals(code, _apiResponse.code) && + Objects.equals(type, _apiResponse.type) && + Objects.equals(message, _apiResponse.message); + } + + @Override + public int hashCode() { + return Objects.hash(code, type, message); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ModelApiResponse {\n"); + + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" message: ").append(toIndentedString(message)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/Order.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/Order.java new file mode 100644 index 0000000000..9e7d41ff04 --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/Order.java @@ -0,0 +1,157 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.time.OffsetDateTime; + +/** + * An order for a pets from the pet store + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Order { + + private Long id = null; + private Long petId = null; + private Integer quantity = null; + private OffsetDateTime shipDate = null; + + + public enum StatusEnum { + PLACED("placed"), + APPROVED("approved"), + DELIVERED("delivered"); + + private String value; + + StatusEnum(String value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return value; + } + } + + private StatusEnum status = null; + private Boolean complete = false; + + public Order () { + + } + + public Order (Long id, Long petId, Integer quantity, OffsetDateTime shipDate, StatusEnum status, Boolean complete) { + this.id = id; + this.petId = petId; + this.quantity = quantity; + this.shipDate = shipDate; + this.status = status; + this.complete = complete; + } + + + @JsonProperty("id") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + @JsonProperty("petId") + public Long getPetId() { + return petId; + } + public void setPetId(Long petId) { + this.petId = petId; + } + + + @JsonProperty("quantity") + public Integer getQuantity() { + return quantity; + } + public void setQuantity(Integer quantity) { + this.quantity = quantity; + } + + + @JsonProperty("shipDate") + public OffsetDateTime getShipDate() { + return shipDate; + } + public void setShipDate(OffsetDateTime shipDate) { + this.shipDate = shipDate; + } + + + @JsonProperty("status") + public StatusEnum getStatus() { + return status; + } + public void setStatus(StatusEnum status) { + this.status = status; + } + + + @JsonProperty("complete") + public Boolean getComplete() { + return complete; + } + public void setComplete(Boolean complete) { + this.complete = complete; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Order order = (Order) o; + return Objects.equals(id, order.id) && + Objects.equals(petId, order.petId) && + Objects.equals(quantity, order.quantity) && + Objects.equals(shipDate, order.shipDate) && + Objects.equals(status, order.status) && + Objects.equals(complete, order.complete); + } + + @Override + public int hashCode() { + return Objects.hash(id, petId, quantity, shipDate, status, complete); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Order {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" petId: ").append(toIndentedString(petId)).append("\n"); + sb.append(" quantity: ").append(toIndentedString(quantity)).append("\n"); + sb.append(" shipDate: ").append(toIndentedString(shipDate)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" complete: ").append(toIndentedString(complete)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/Pet.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/Pet.java new file mode 100644 index 0000000000..8b3181be26 --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/Pet.java @@ -0,0 +1,160 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import io.swagger.server.api.model.Category; +import io.swagger.server.api.model.Tag; +import java.util.ArrayList; +import java.util.List; + +/** + * A pet for sale in the pet store + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Pet { + + private Long id = null; + private Category category = null; + private String name = null; + private List photoUrls = new ArrayList(); + private List tags = new ArrayList(); + + + public enum StatusEnum { + AVAILABLE("available"), + PENDING("pending"), + SOLD("sold"); + + private String value; + + StatusEnum(String value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return value; + } + } + + private StatusEnum status = null; + + public Pet () { + + } + + public Pet (Long id, Category category, String name, List photoUrls, List tags, StatusEnum status) { + this.id = id; + this.category = category; + this.name = name; + this.photoUrls = photoUrls; + this.tags = tags; + this.status = status; + } + + + @JsonProperty("id") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + @JsonProperty("category") + public Category getCategory() { + return category; + } + public void setCategory(Category category) { + this.category = category; + } + + + @JsonProperty("name") + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + + @JsonProperty("photoUrls") + public List getPhotoUrls() { + return photoUrls; + } + public void setPhotoUrls(List photoUrls) { + this.photoUrls = photoUrls; + } + + + @JsonProperty("tags") + public List getTags() { + return tags; + } + public void setTags(List tags) { + this.tags = tags; + } + + + @JsonProperty("status") + public StatusEnum getStatus() { + return status; + } + public void setStatus(StatusEnum status) { + this.status = status; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Pet pet = (Pet) o; + return Objects.equals(id, pet.id) && + Objects.equals(category, pet.category) && + Objects.equals(name, pet.name) && + Objects.equals(photoUrls, pet.photoUrls) && + Objects.equals(tags, pet.tags) && + Objects.equals(status, pet.status); + } + + @Override + public int hashCode() { + return Objects.hash(id, category, name, photoUrls, tags, status); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Pet {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" category: ").append(toIndentedString(category)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" photoUrls: ").append(toIndentedString(photoUrls)).append("\n"); + sb.append(" tags: ").append(toIndentedString(tags)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/Tag.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/Tag.java new file mode 100644 index 0000000000..f00a458e3d --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/Tag.java @@ -0,0 +1,83 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A tag for a pet + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Tag { + + private Long id = null; + private String name = null; + + public Tag () { + + } + + public Tag (Long id, String name) { + this.id = id; + this.name = name; + } + + + @JsonProperty("id") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + @JsonProperty("name") + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Tag tag = (Tag) o; + return Objects.equals(id, tag.id) && + Objects.equals(name, tag.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Tag {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/User.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/User.java new file mode 100644 index 0000000000..6e7331cd23 --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/model/User.java @@ -0,0 +1,161 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A User who is purchasing from the pet store + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class User { + + private Long id = null; + private String username = null; + private String firstName = null; + private String lastName = null; + private String email = null; + private String password = null; + private String phone = null; + private Integer userStatus = null; + + public User () { + + } + + public User (Long id, String username, String firstName, String lastName, String email, String password, String phone, Integer userStatus) { + this.id = id; + this.username = username; + this.firstName = firstName; + this.lastName = lastName; + this.email = email; + this.password = password; + this.phone = phone; + this.userStatus = userStatus; + } + + + @JsonProperty("id") + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + @JsonProperty("username") + public String getUsername() { + return username; + } + public void setUsername(String username) { + this.username = username; + } + + + @JsonProperty("firstName") + public String getFirstName() { + return firstName; + } + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + + @JsonProperty("lastName") + public String getLastName() { + return lastName; + } + public void setLastName(String lastName) { + this.lastName = lastName; + } + + + @JsonProperty("email") + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + + + @JsonProperty("password") + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } + + + @JsonProperty("phone") + public String getPhone() { + return phone; + } + public void setPhone(String phone) { + this.phone = phone; + } + + + @JsonProperty("userStatus") + public Integer getUserStatus() { + return userStatus; + } + public void setUserStatus(Integer userStatus) { + this.userStatus = userStatus; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + User user = (User) o; + return Objects.equals(id, user.id) && + Objects.equals(username, user.username) && + Objects.equals(firstName, user.firstName) && + Objects.equals(lastName, user.lastName) && + Objects.equals(email, user.email) && + Objects.equals(password, user.password) && + Objects.equals(phone, user.phone) && + Objects.equals(userStatus, user.userStatus); + } + + @Override + public int hashCode() { + return Objects.hash(id, username, firstName, lastName, email, password, phone, userStatus); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class User {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" username: ").append(toIndentedString(username)).append("\n"); + sb.append(" firstName: ").append(toIndentedString(firstName)).append("\n"); + sb.append(" lastName: ").append(toIndentedString(lastName)).append("\n"); + sb.append(" email: ").append(toIndentedString(email)).append("\n"); + sb.append(" password: ").append(toIndentedString(password)).append("\n"); + sb.append(" phone: ").append(toIndentedString(phone)).append("\n"); + sb.append(" userStatus: ").append(toIndentedString(userStatus)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/PetApi.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/PetApi.java new file mode 100644 index 0000000000..755000999a --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/PetApi.java @@ -0,0 +1,39 @@ +package io.swagger.server.api.verticle; + +import java.io.File; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.ModelApiResponse; +import io.swagger.server.api.model.Pet; + +import rx.Completable; +import rx.Single; + +import java.util.List; +import java.util.Map; + +public interface PetApi { + //addPet + public Completable addPet(Pet body); + + //deletePet + public Completable deletePet(Long petId,String apiKey); + + //findPetsByStatus + public Single> findPetsByStatus(List status); + + //findPetsByTags + public Single> findPetsByTags(List tags); + + //getPetById + public Single getPetById(Long petId); + + //updatePet + public Completable updatePet(Pet body); + + //updatePetWithForm + public Completable updatePetWithForm(Long petId,String name,String status); + + //uploadFile + public Single uploadFile(Long petId,String additionalMetadata,File file); + +} diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/PetApiException.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/PetApiException.java new file mode 100644 index 0000000000..c618e243e0 --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/PetApiException.java @@ -0,0 +1,25 @@ +package io.swagger.server.api.verticle; + +import java.io.File; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.ModelApiResponse; +import io.swagger.server.api.model.Pet; + +public final class PetApiException extends MainApiException { + public PetApiException(int statusCode, String statusMessage) { + super(statusCode, statusMessage); + } + + public static final PetApiException Pet_addPet_405_Exception = new PetApiException(405, "Invalid input"); + public static final PetApiException Pet_deletePet_400_Exception = new PetApiException(400, "Invalid pet value"); + public static final PetApiException Pet_findPetsByStatus_400_Exception = new PetApiException(400, "Invalid status value"); + public static final PetApiException Pet_findPetsByTags_400_Exception = new PetApiException(400, "Invalid tag value"); + public static final PetApiException Pet_getPetById_400_Exception = new PetApiException(400, "Invalid ID supplied"); + public static final PetApiException Pet_getPetById_404_Exception = new PetApiException(404, "Pet not found"); + public static final PetApiException Pet_updatePet_400_Exception = new PetApiException(400, "Invalid ID supplied"); + public static final PetApiException Pet_updatePet_404_Exception = new PetApiException(404, "Pet not found"); + public static final PetApiException Pet_updatePet_405_Exception = new PetApiException(405, "Validation exception"); + public static final PetApiException Pet_updatePetWithForm_405_Exception = new PetApiException(405, "Invalid input"); + + +} \ 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 new file mode 100644 index 0000000000..6eada5ae46 --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/PetApiVerticle.java @@ -0,0 +1,198 @@ +package io.swagger.server.api.verticle; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.eventbus.Message; +import io.vertx.core.json.Json; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; + +import java.io.File; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.ModelApiResponse; +import io.swagger.server.api.model.Pet; + +import java.util.List; +import java.util.Map; + +public class PetApiVerticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger(PetApiVerticle.class); + + final static String ADDPET_SERVICE_ID = "addPet"; + final static String DELETEPET_SERVICE_ID = "deletePet"; + final static String FINDPETSBYSTATUS_SERVICE_ID = "findPetsByStatus"; + final static String FINDPETSBYTAGS_SERVICE_ID = "findPetsByTags"; + final static String GETPETBYID_SERVICE_ID = "getPetById"; + final static String UPDATEPET_SERVICE_ID = "updatePet"; + final static String UPDATEPETWITHFORM_SERVICE_ID = "updatePetWithForm"; + final static String UPLOADFILE_SERVICE_ID = "uploadFile"; + + //TODO : create Implementation + PetApi service = new PetApiImpl(); + + @Override + public void start() throws Exception { + + //Consumer for addPet + vertx.eventBus(). consumer(ADDPET_SERVICE_ID).handler(message -> { + try { + Pet body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), Pet.class); + service.addPet(body).subscribe( + () -> { + message.reply(null); + }, + error -> { + manageError(message, error, "addPet"); + }); + } catch (Exception e) { + logUnexpectedError("addPet", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //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"); + service.deletePet(petId, apiKey).subscribe( + () -> { + message.reply(null); + }, + error -> { + manageError(message, error, "deletePet"); + }); + } catch (Exception e) { + logUnexpectedError("deletePet", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //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)); + service.findPetsByStatus(status).subscribe( + result -> { + message.reply(new JsonArray(Json.encode(result)).encodePrettily()); + }, + error -> { + manageError(message, error, "findPetsByStatus"); + }); + } catch (Exception e) { + logUnexpectedError("findPetsByStatus", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //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)); + service.findPetsByTags(tags).subscribe( + result -> { + message.reply(new JsonArray(Json.encode(result)).encodePrettily()); + }, + error -> { + manageError(message, error, "findPetsByTags"); + }); + } catch (Exception e) { + logUnexpectedError("findPetsByTags", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for getPetById + vertx.eventBus(). consumer(GETPETBYID_SERVICE_ID).handler(message -> { + try { + Long petId = Json.mapper.readValue(message.body().getString("petId"), Long.class); + service.getPetById(petId).subscribe( + result -> { + message.reply(new JsonObject(Json.encode(result)).encodePrettily()); + }, + error -> { + manageError(message, error, "getPetById"); + }); + } catch (Exception e) { + logUnexpectedError("getPetById", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for updatePet + vertx.eventBus(). consumer(UPDATEPET_SERVICE_ID).handler(message -> { + try { + Pet body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), Pet.class); + service.updatePet(body).subscribe( + () -> { + message.reply(null); + }, + error -> { + manageError(message, error, "updatePet"); + }); + } catch (Exception e) { + logUnexpectedError("updatePet", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //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"); + service.updatePetWithForm(petId, name, status).subscribe( + () -> { + message.reply(null); + }, + error -> { + manageError(message, error, "updatePetWithForm"); + }); + } catch (Exception e) { + logUnexpectedError("updatePetWithForm", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //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); + service.uploadFile(petId, additionalMetadata, file).subscribe( + result -> { + message.reply(new JsonObject(Json.encode(result)).encodePrettily()); + }, + error -> { + manageError(message, error, "uploadFile"); + }); + } catch (Exception e) { + logUnexpectedError("uploadFile", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + } + + private void manageError(Message message, Throwable cause, String serviceName) { + int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); + String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); + if (cause instanceof MainApiException) { + code = ((MainApiException)cause).getStatusCode(); + statusMessage = ((MainApiException)cause).getStatusMessage(); + } else { + logUnexpectedError(serviceName, cause); + } + + message.fail(code, statusMessage); + } + + private void logUnexpectedError(String serviceName, Throwable cause) { + LOGGER.error("Unexpected error in "+ serviceName, cause); + } +} diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/StoreApi.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/StoreApi.java new file mode 100644 index 0000000000..54b242527f --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/StoreApi.java @@ -0,0 +1,25 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.Order; + +import rx.Completable; +import rx.Single; + +import java.util.List; +import java.util.Map; + +public interface StoreApi { + //deleteOrder + public Completable deleteOrder(String orderId); + + //getInventory + public Single> getInventory(); + + //getOrderById + public Single getOrderById(Long orderId); + + //placeOrder + public Single placeOrder(Order body); + +} diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/StoreApiException.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/StoreApiException.java new file mode 100644 index 0000000000..3b8f0ab204 --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/StoreApiException.java @@ -0,0 +1,18 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.Order; + +public final class StoreApiException extends MainApiException { + public StoreApiException(int statusCode, String statusMessage) { + super(statusCode, statusMessage); + } + + public static final StoreApiException Store_deleteOrder_400_Exception = new StoreApiException(400, "Invalid ID supplied"); + public static final StoreApiException Store_deleteOrder_404_Exception = new StoreApiException(404, "Order not found"); + public static final StoreApiException Store_getOrderById_400_Exception = new StoreApiException(400, "Invalid ID supplied"); + public static final StoreApiException Store_getOrderById_404_Exception = new StoreApiException(404, "Order not found"); + public static final StoreApiException Store_placeOrder_400_Exception = new StoreApiException(400, "Invalid Order"); + + +} \ No newline at end of file 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 new file mode 100644 index 0000000000..b648fef059 --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/StoreApiVerticle.java @@ -0,0 +1,116 @@ +package io.swagger.server.api.verticle; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.eventbus.Message; +import io.vertx.core.json.Json; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; + +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.Order; + +import java.util.List; +import java.util.Map; + +public class StoreApiVerticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger(StoreApiVerticle.class); + + final static String DELETEORDER_SERVICE_ID = "deleteOrder"; + final static String GETINVENTORY_SERVICE_ID = "getInventory"; + final static String GETORDERBYID_SERVICE_ID = "getOrderById"; + final static String PLACEORDER_SERVICE_ID = "placeOrder"; + + //TODO : create Implementation + StoreApi service = new StoreApiImpl(); + + @Override + public void start() throws Exception { + + //Consumer for deleteOrder + vertx.eventBus(). consumer(DELETEORDER_SERVICE_ID).handler(message -> { + try { + String orderId = message.body().getString("orderId"); + service.deleteOrder(orderId).subscribe( + () -> { + message.reply(null); + }, + error -> { + manageError(message, error, "deleteOrder"); + }); + } catch (Exception e) { + logUnexpectedError("deleteOrder", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for getInventory + vertx.eventBus(). consumer(GETINVENTORY_SERVICE_ID).handler(message -> { + try { + service.getInventory().subscribe( + result -> { + message.reply(new JsonObject(Json.encode(result)).encodePrettily()); + }, + error -> { + manageError(message, error, "getInventory"); + }); + } catch (Exception e) { + logUnexpectedError("getInventory", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for getOrderById + vertx.eventBus(). consumer(GETORDERBYID_SERVICE_ID).handler(message -> { + try { + Long orderId = Json.mapper.readValue(message.body().getString("orderId"), Long.class); + service.getOrderById(orderId).subscribe( + result -> { + message.reply(new JsonObject(Json.encode(result)).encodePrettily()); + }, + error -> { + manageError(message, error, "getOrderById"); + }); + } catch (Exception e) { + logUnexpectedError("getOrderById", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for placeOrder + vertx.eventBus(). consumer(PLACEORDER_SERVICE_ID).handler(message -> { + try { + Order body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), Order.class); + service.placeOrder(body).subscribe( + result -> { + message.reply(new JsonObject(Json.encode(result)).encodePrettily()); + }, + error -> { + manageError(message, error, "placeOrder"); + }); + } catch (Exception e) { + logUnexpectedError("placeOrder", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + } + + private void manageError(Message message, Throwable cause, String serviceName) { + int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); + String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); + if (cause instanceof MainApiException) { + code = ((MainApiException)cause).getStatusCode(); + statusMessage = ((MainApiException)cause).getStatusMessage(); + } else { + logUnexpectedError(serviceName, cause); + } + + message.fail(code, statusMessage); + } + + private void logUnexpectedError(String serviceName, Throwable cause) { + LOGGER.error("Unexpected error in "+ serviceName, cause); + } +} diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/UserApi.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/UserApi.java new file mode 100644 index 0000000000..356d3c809a --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/UserApi.java @@ -0,0 +1,37 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.User; + +import rx.Completable; +import rx.Single; + +import java.util.List; +import java.util.Map; + +public interface UserApi { + //createUser + public Completable createUser(User body); + + //createUsersWithArrayInput + public Completable createUsersWithArrayInput(List body); + + //createUsersWithListInput + public Completable createUsersWithListInput(List body); + + //deleteUser + public Completable deleteUser(String username); + + //getUserByName + public Single getUserByName(String username); + + //loginUser + public Single loginUser(String username,String password); + + //logoutUser + public Completable logoutUser(); + + //updateUser + public Completable updateUser(String username,User body); + +} diff --git a/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/UserApiException.java b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/UserApiException.java new file mode 100644 index 0000000000..337f5b4353 --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/UserApiException.java @@ -0,0 +1,20 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.User; + +public final class UserApiException extends MainApiException { + public UserApiException(int statusCode, String statusMessage) { + super(statusCode, statusMessage); + } + + public static final UserApiException User_deleteUser_400_Exception = new UserApiException(400, "Invalid username supplied"); + public static final UserApiException User_deleteUser_404_Exception = new UserApiException(404, "User not found"); + public static final UserApiException User_getUserByName_400_Exception = new UserApiException(400, "Invalid username supplied"); + public static final UserApiException User_getUserByName_404_Exception = new UserApiException(404, "User not found"); + public static final UserApiException User_loginUser_400_Exception = new UserApiException(400, "Invalid username/password supplied"); + public static final UserApiException User_updateUser_400_Exception = new UserApiException(400, "Invalid user supplied"); + public static final UserApiException User_updateUser_404_Exception = new UserApiException(404, "User not found"); + + +} \ No newline at end of file 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 new file mode 100644 index 0000000000..0bdd10a153 --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/UserApiVerticle.java @@ -0,0 +1,192 @@ +package io.swagger.server.api.verticle; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.eventbus.Message; +import io.vertx.core.json.Json; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; + +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.User; + +import java.util.List; +import java.util.Map; + +public class UserApiVerticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger(UserApiVerticle.class); + + final static String CREATEUSER_SERVICE_ID = "createUser"; + final static String CREATEUSERSWITHARRAYINPUT_SERVICE_ID = "createUsersWithArrayInput"; + final static String CREATEUSERSWITHLISTINPUT_SERVICE_ID = "createUsersWithListInput"; + final static String DELETEUSER_SERVICE_ID = "deleteUser"; + final static String GETUSERBYNAME_SERVICE_ID = "getUserByName"; + final static String LOGINUSER_SERVICE_ID = "loginUser"; + final static String LOGOUTUSER_SERVICE_ID = "logoutUser"; + final static String UPDATEUSER_SERVICE_ID = "updateUser"; + + //TODO : create Implementation + UserApi service = new UserApiImpl(); + + @Override + public void start() throws Exception { + + //Consumer for createUser + vertx.eventBus(). consumer(CREATEUSER_SERVICE_ID).handler(message -> { + try { + User body = Json.mapper.readValue(message.body().getJsonObject("body").encode(), User.class); + service.createUser(body).subscribe( + () -> { + message.reply(null); + }, + error -> { + manageError(message, error, "createUser"); + }); + } catch (Exception e) { + logUnexpectedError("createUser", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //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)); + service.createUsersWithArrayInput(body).subscribe( + () -> { + message.reply(null); + }, + error -> { + manageError(message, error, "createUsersWithArrayInput"); + }); + } catch (Exception e) { + logUnexpectedError("createUsersWithArrayInput", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //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)); + service.createUsersWithListInput(body).subscribe( + () -> { + message.reply(null); + }, + error -> { + manageError(message, error, "createUsersWithListInput"); + }); + } catch (Exception e) { + logUnexpectedError("createUsersWithListInput", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for deleteUser + vertx.eventBus(). consumer(DELETEUSER_SERVICE_ID).handler(message -> { + try { + String username = message.body().getString("username"); + service.deleteUser(username).subscribe( + () -> { + message.reply(null); + }, + error -> { + manageError(message, error, "deleteUser"); + }); + } catch (Exception e) { + logUnexpectedError("deleteUser", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for getUserByName + vertx.eventBus(). consumer(GETUSERBYNAME_SERVICE_ID).handler(message -> { + try { + String username = message.body().getString("username"); + service.getUserByName(username).subscribe( + result -> { + message.reply(new JsonObject(Json.encode(result)).encodePrettily()); + }, + error -> { + manageError(message, error, "getUserByName"); + }); + } catch (Exception e) { + logUnexpectedError("getUserByName", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for loginUser + vertx.eventBus(). consumer(LOGINUSER_SERVICE_ID).handler(message -> { + try { + String username = message.body().getString("username"); + String password = message.body().getString("password"); + service.loginUser(username, password).subscribe( + result -> { + message.reply(new JsonObject(Json.encode(result)).encodePrettily()); + }, + error -> { + manageError(message, error, "loginUser"); + }); + } catch (Exception e) { + logUnexpectedError("loginUser", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for logoutUser + vertx.eventBus(). consumer(LOGOUTUSER_SERVICE_ID).handler(message -> { + try { + service.logoutUser().subscribe( + () -> { + message.reply(null); + }, + error -> { + manageError(message, error, "logoutUser"); + }); + } catch (Exception e) { + logUnexpectedError("logoutUser", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //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); + service.updateUser(username, body).subscribe( + () -> { + message.reply(null); + }, + error -> { + manageError(message, error, "updateUser"); + }); + } catch (Exception e) { + logUnexpectedError("updateUser", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + } + + private void manageError(Message message, Throwable cause, String serviceName) { + int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); + String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); + if (cause instanceof MainApiException) { + code = ((MainApiException)cause).getStatusCode(); + statusMessage = ((MainApiException)cause).getStatusMessage(); + } else { + logUnexpectedError(serviceName, cause); + } + + message.fail(code, statusMessage); + } + + private void logUnexpectedError(String serviceName, Throwable cause) { + LOGGER.error("Unexpected error in "+ serviceName, cause); + } +} 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 new file mode 100644 index 0000000000..25192459c6 --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/resources/swagger.json @@ -0,0 +1,870 @@ +{ + "swagger" : "2.0", + "info" : { + "description" : "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.", + "version" : "1.0.0", + "title" : "Swagger Petstore", + "termsOfService" : "http://swagger.io/terms/", + "contact" : { + "email" : "apiteam@swagger.io" + }, + "license" : { + "name" : "Apache 2.0", + "url" : "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host" : "petstore.swagger.io", + "basePath" : "/v2", + "tags" : [ { + "name" : "pet", + "description" : "Everything about your Pets", + "externalDocs" : { + "description" : "Find out more", + "url" : "http://swagger.io" + } + }, { + "name" : "store", + "description" : "Access to Petstore orders" + }, { + "name" : "user", + "description" : "Operations about user", + "externalDocs" : { + "description" : "Find out more about our store", + "url" : "http://swagger.io" + } + } ], + "schemes" : [ "http" ], + "paths" : { + "/pet" : { + "post" : { + "tags" : [ "pet" ], + "summary" : "Add a new pet to the store", + "description" : "", + "operationId" : "addPet", + "consumes" : [ "application/json", "application/xml" ], + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Pet object that needs to be added to the store", + "required" : true, + "schema" : { + "$ref" : "#/definitions/Pet" + } + } ], + "responses" : { + "405" : { + "description" : "Invalid input" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + }, + "put" : { + "tags" : [ "pet" ], + "summary" : "Update an existing pet", + "description" : "", + "operationId" : "updatePet", + "consumes" : [ "application/json", "application/xml" ], + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Pet object that needs to be added to the store", + "required" : true, + "schema" : { + "$ref" : "#/definitions/Pet" + } + } ], + "responses" : { + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Pet not found" + }, + "405" : { + "description" : "Validation exception" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/pet/findByStatus" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Finds Pets by status", + "description" : "Multiple status values can be provided with comma separated strings", + "operationId" : "findPetsByStatus", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "status", + "in" : "query", + "description" : "Status values that need to be considered for filter", + "required" : true, + "type" : "array", + "items" : { + "type" : "string", + "default" : "available", + "enum" : [ "available", "pending", "sold" ] + }, + "collectionFormat" : "csv" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Pet" + } + } + }, + "400" : { + "description" : "Invalid status value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/pet/findByTags" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Finds Pets by tags", + "description" : "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + "operationId" : "findPetsByTags", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "tags", + "in" : "query", + "description" : "Tags to filter by", + "required" : true, + "type" : "array", + "items" : { + "type" : "string" + }, + "collectionFormat" : "csv" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/Pet" + } + } + }, + "400" : { + "description" : "Invalid tag value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/pet/{petId}" : { + "get" : { + "tags" : [ "pet" ], + "summary" : "Find pet by ID", + "description" : "Returns a single pet", + "operationId" : "getPetById", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet to return", + "required" : true, + "type" : "integer", + "format" : "int64" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/Pet" + } + }, + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Pet not found" + } + }, + "security" : [ { + "api_key" : [ ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + }, + "post" : { + "tags" : [ "pet" ], + "summary" : "Updates a pet in the store with form data", + "description" : "", + "operationId" : "updatePetWithForm", + "consumes" : [ "application/x-www-form-urlencoded" ], + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet that needs to be updated", + "required" : true, + "type" : "integer", + "format" : "int64" + }, { + "name" : "name", + "in" : "formData", + "description" : "Updated name of the pet", + "required" : false, + "type" : "string" + }, { + "name" : "status", + "in" : "formData", + "description" : "Updated status of the pet", + "required" : false, + "type" : "string" + } ], + "responses" : { + "405" : { + "description" : "Invalid input" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/x-www-form-urlencoded", + "x-accepts" : "application/json" + }, + "delete" : { + "tags" : [ "pet" ], + "summary" : "Deletes a pet", + "description" : "", + "operationId" : "deletePet", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "api_key", + "in" : "header", + "required" : false, + "type" : "string" + }, { + "name" : "petId", + "in" : "path", + "description" : "Pet id to delete", + "required" : true, + "type" : "integer", + "format" : "int64" + } ], + "responses" : { + "400" : { + "description" : "Invalid pet value" + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/pet/{petId}/uploadImage" : { + "post" : { + "tags" : [ "pet" ], + "summary" : "uploads an image", + "description" : "", + "operationId" : "uploadFile", + "consumes" : [ "multipart/form-data" ], + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "petId", + "in" : "path", + "description" : "ID of pet to update", + "required" : true, + "type" : "integer", + "format" : "int64" + }, { + "name" : "additionalMetadata", + "in" : "formData", + "description" : "Additional data to pass to server", + "required" : false, + "type" : "string" + }, { + "name" : "file", + "in" : "formData", + "description" : "file to upload", + "required" : false, + "type" : "file" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/ApiResponse" + } + } + }, + "security" : [ { + "petstore_auth" : [ "write:pets", "read:pets" ] + } ], + "x-contentType" : "multipart/form-data", + "x-accepts" : "application/json" + } + }, + "/store/inventory" : { + "get" : { + "tags" : [ "store" ], + "summary" : "Returns pet inventories by status", + "description" : "Returns a map of status codes to quantities", + "operationId" : "getInventory", + "produces" : [ "application/json" ], + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "object", + "additionalProperties" : { + "type" : "integer", + "format" : "int32" + } + } + } + }, + "security" : [ { + "api_key" : [ ] + } ], + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/store/order" : { + "post" : { + "tags" : [ "store" ], + "summary" : "Place an order for a pet", + "description" : "", + "operationId" : "placeOrder", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "order placed for purchasing the pet", + "required" : true, + "schema" : { + "$ref" : "#/definitions/Order" + } + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/Order" + } + }, + "400" : { + "description" : "Invalid Order" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/store/order/{orderId}" : { + "get" : { + "tags" : [ "store" ], + "summary" : "Find purchase order by ID", + "description" : "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", + "operationId" : "getOrderById", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "orderId", + "in" : "path", + "description" : "ID of pet that needs to be fetched", + "required" : true, + "type" : "integer", + "maximum" : 5, + "minimum" : 1, + "format" : "int64" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/Order" + } + }, + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Order not found" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + }, + "delete" : { + "tags" : [ "store" ], + "summary" : "Delete purchase order by ID", + "description" : "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", + "operationId" : "deleteOrder", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "orderId", + "in" : "path", + "description" : "ID of the order that needs to be deleted", + "required" : true, + "type" : "string" + } ], + "responses" : { + "400" : { + "description" : "Invalid ID supplied" + }, + "404" : { + "description" : "Order not found" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Create user", + "description" : "This can only be done by the logged in user.", + "operationId" : "createUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "Created user object", + "required" : true, + "schema" : { + "$ref" : "#/definitions/User" + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user/createWithArray" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Creates list of users with given input array", + "description" : "", + "operationId" : "createUsersWithArrayInput", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "List of user object", + "required" : true, + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/User" + } + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user/createWithList" : { + "post" : { + "tags" : [ "user" ], + "summary" : "Creates list of users with given input array", + "description" : "", + "operationId" : "createUsersWithListInput", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "body", + "description" : "List of user object", + "required" : true, + "schema" : { + "type" : "array", + "items" : { + "$ref" : "#/definitions/User" + } + } + } ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user/login" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Logs user into the system", + "description" : "", + "operationId" : "loginUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "query", + "description" : "The user name for login", + "required" : true, + "type" : "string" + }, { + "name" : "password", + "in" : "query", + "description" : "The password for login in clear text", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "type" : "string" + }, + "headers" : { + "X-Rate-Limit" : { + "type" : "integer", + "format" : "int32", + "description" : "calls per hour allowed by the user" + }, + "X-Expires-After" : { + "type" : "string", + "format" : "date-time", + "description" : "date in UTC when toekn expires" + } + } + }, + "400" : { + "description" : "Invalid username/password supplied" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user/logout" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Logs out current logged in user session", + "description" : "", + "operationId" : "logoutUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ ], + "responses" : { + "default" : { + "description" : "successful operation" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/user/{username}" : { + "get" : { + "tags" : [ "user" ], + "summary" : "Get user by user name", + "description" : "", + "operationId" : "getUserByName", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "The name that needs to be fetched. Use user1 for testing. ", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/User" + } + }, + "400" : { + "description" : "Invalid username supplied" + }, + "404" : { + "description" : "User not found" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + }, + "put" : { + "tags" : [ "user" ], + "summary" : "Updated user", + "description" : "This can only be done by the logged in user.", + "operationId" : "updateUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "name that need to be deleted", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "body", + "description" : "Updated user object", + "required" : true, + "schema" : { + "$ref" : "#/definitions/User" + } + } ], + "responses" : { + "400" : { + "description" : "Invalid user supplied" + }, + "404" : { + "description" : "User not found" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + }, + "delete" : { + "tags" : [ "user" ], + "summary" : "Delete user", + "description" : "This can only be done by the logged in user.", + "operationId" : "deleteUser", + "produces" : [ "application/xml", "application/json" ], + "parameters" : [ { + "name" : "username", + "in" : "path", + "description" : "The name that needs to be deleted", + "required" : true, + "type" : "string" + } ], + "responses" : { + "400" : { + "description" : "Invalid username supplied" + }, + "404" : { + "description" : "User not found" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + } + }, + "securityDefinitions" : { + "petstore_auth" : { + "type" : "oauth2", + "authorizationUrl" : "http://petstore.swagger.io/api/oauth/dialog", + "flow" : "implicit", + "scopes" : { + "write:pets" : "modify pets in your account", + "read:pets" : "read your pets" + } + }, + "api_key" : { + "type" : "apiKey", + "name" : "api_key", + "in" : "header" + } + }, + "definitions" : { + "Order" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "petId" : { + "type" : "integer", + "format" : "int64" + }, + "quantity" : { + "type" : "integer", + "format" : "int32" + }, + "shipDate" : { + "type" : "string", + "format" : "date-time" + }, + "status" : { + "type" : "string", + "description" : "Order Status", + "enum" : [ "placed", "approved", "delivered" ] + }, + "complete" : { + "type" : "boolean", + "default" : false + } + }, + "title" : "Pet Order", + "description" : "An order for a pets from the pet store", + "xml" : { + "name" : "Order" + } + }, + "Category" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "name" : { + "type" : "string" + } + }, + "title" : "Pet catehgry", + "description" : "A category for a pet", + "xml" : { + "name" : "Category" + } + }, + "User" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "username" : { + "type" : "string" + }, + "firstName" : { + "type" : "string" + }, + "lastName" : { + "type" : "string" + }, + "email" : { + "type" : "string" + }, + "password" : { + "type" : "string" + }, + "phone" : { + "type" : "string" + }, + "userStatus" : { + "type" : "integer", + "format" : "int32", + "description" : "User Status" + } + }, + "title" : "a User", + "description" : "A User who is purchasing from the pet store", + "xml" : { + "name" : "User" + } + }, + "Tag" : { + "type" : "object", + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "name" : { + "type" : "string" + } + }, + "title" : "Pet Tag", + "description" : "A tag for a pet", + "xml" : { + "name" : "Tag" + } + }, + "Pet" : { + "type" : "object", + "required" : [ "name", "photoUrls" ], + "properties" : { + "id" : { + "type" : "integer", + "format" : "int64" + }, + "category" : { + "$ref" : "#/definitions/Category" + }, + "name" : { + "type" : "string", + "example" : "doggie" + }, + "photoUrls" : { + "type" : "array", + "xml" : { + "name" : "photoUrl", + "wrapped" : true + }, + "items" : { + "type" : "string" + } + }, + "tags" : { + "type" : "array", + "xml" : { + "name" : "tag", + "wrapped" : true + }, + "items" : { + "$ref" : "#/definitions/Tag" + } + }, + "status" : { + "type" : "string", + "description" : "pet status in the store", + "enum" : [ "available", "pending", "sold" ] + } + }, + "title" : "a Pet", + "description" : "A pet for sale in the pet store", + "xml" : { + "name" : "Pet" + } + }, + "ApiResponse" : { + "type" : "object", + "properties" : { + "code" : { + "type" : "integer", + "format" : "int32" + }, + "type" : { + "type" : "string" + }, + "message" : { + "type" : "string" + } + }, + "title" : "An uploaded response", + "description" : "Describes the result of uploading an image resource" + } + }, + "externalDocs" : { + "description" : "Find out more about Swagger", + "url" : "http://swagger.io" + } +} \ No newline at end of file diff --git a/samples/server/petstore/java-vertx/rx/src/main/resources/vertx-default-jul-logging.properties b/samples/server/petstore/java-vertx/rx/src/main/resources/vertx-default-jul-logging.properties new file mode 100644 index 0000000000..706d6d9b2f --- /dev/null +++ b/samples/server/petstore/java-vertx/rx/src/main/resources/vertx-default-jul-logging.properties @@ -0,0 +1,30 @@ +# +# Copyright 2014 Red Hat, Inc. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# and Apache License v2.0 which accompanies this distribution. +# +# The Eclipse Public License is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# The Apache License v2.0 is available at +# http://www.opensource.org/licenses/apache2.0.php +# +# You may elect to redistribute this code under either of these licenses. +# +handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler +java.util.logging.SimpleFormatter.format=%5$s %6$s\n +java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter +java.util.logging.ConsoleHandler.level=FINEST +java.util.logging.FileHandler.level=INFO +java.util.logging.FileHandler.formatter=io.vertx.core.logging.VertxLoggerFormatter + +# Put the log in the system temporary directory +java.util.logging.FileHandler.pattern=vertx.log + +.level=INFO +io.vertx.ext.web.level=FINEST +io.vertx.level=INFO +com.hazelcast.level=INFO +io.netty.util.internal.PlatformDependent.level=SEVERE \ No newline at end of file