diff --git a/modules/openapi-generator-online/Dockerfile b/modules/openapi-generator-online/Dockerfile index 14d448eda8f8..4740683ef843 100644 --- a/modules/openapi-generator-online/Dockerfile +++ b/modules/openapi-generator-online/Dockerfile @@ -1,8 +1,8 @@ FROM openjdk:8-jre-alpine - + WORKDIR /generator -COPY target/openapi-generator-online-3.0.0-SNAPSHOT.jar /generator/openapi-generator-online.jar +COPY target/*.jar /generator/openapi-generator-online.jar ENV GENERATOR_HOST=http://localhost diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/OpenAPI2SpringBoot.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/OpenAPI2SpringBoot.java index c23a56fa1726..45000a9bdde7 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/OpenAPI2SpringBoot.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/OpenAPI2SpringBoot.java @@ -28,13 +28,13 @@ public class OpenAPI2SpringBoot implements CommandLineRunner { @Override - public void run(String... arg0) throws Exception { + public void run(String... arg0) { if (arg0.length > 0 && arg0[0].equals("exitcode")) { throw new ExitException(); } } - public static void main(String[] args) throws Exception { + public static void main(String[] args) { new SpringApplication(OpenAPI2SpringBoot.class).run(args); } diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/GenApi.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/GenApi.java index 8e39e7a3e163..a2c25535b027 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/GenApi.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/GenApi.java @@ -32,6 +32,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.multipart.MultipartFile; import javax.validation.Valid; import java.util.List; @@ -51,9 +52,9 @@ default ResponseEntity> clientOptions() { } - @ApiOperation(value = "Downloads a pre-generated file", nickname = "downloadFile", notes = "A valid `fileId` is generated by the `/clients/{language}` or `/servers/{language}` POST operations. The fileId code can be used just once, after which a new `fileId` will need to be requested.", response = String.class, tags={ "clients","servers", }) + @ApiOperation(value = "Downloads a pre-generated file", nickname = "downloadFile", notes = "A valid `fileId` is generated by the `/clients/{language}` or `/servers/{language}` POST operations. The fileId code can be used just once, after which a new `fileId` will need to be requested.", response = MultipartFile.class, tags={ "clients","servers", }) @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = String.class) }) + @ApiResponse(code = 200, message = "successful operation", response = MultipartFile.class) }) @RequestMapping(value = "/gen/download/{fileId}", produces = { "application/octet-stream" }, method = RequestMethod.GET) @@ -82,9 +83,9 @@ default ResponseEntity generateServerForLanguage(@ApiParam(value = } - @ApiOperation(value = "Returns options for a client library", nickname = "getClientOptions", notes = "", response = CliOption.class, responseContainer = "Map", tags={ "clients", }) + @ApiOperation(value = "Returns options for a client library", nickname = "getClientOptions", notes = "", tags={ "clients", }) @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = CliOption.class, responseContainer = "Map") }) + @ApiResponse(code = 200, message = "successful operation") }) @RequestMapping(value = "/gen/clients/{language}", produces = { "application/json" }, method = RequestMethod.GET) @@ -93,9 +94,9 @@ default ResponseEntity> getClientOptions(@ApiParam(value } - @ApiOperation(value = "Returns options for a server framework", nickname = "getServerOptions", notes = "", response = CliOption.class, responseContainer = "Map", tags={ "servers", }) + @ApiOperation(value = "Returns options for a server framework", nickname = "getServerOptions", notes = "", tags={ "servers", }) @ApiResponses(value = { - @ApiResponse(code = 200, message = "successful operation", response = CliOption.class, responseContainer = "Map") }) + @ApiResponse(code = 200, message = "successful operation") }) @RequestMapping(value = "/gen/servers/{framework}", produces = { "application/json" }, method = RequestMethod.GET) diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/GenApiController.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/GenApiController.java index 601a23d3c1e8..9bc0953512f0 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/GenApiController.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/GenApiController.java @@ -19,8 +19,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; @Controller +@RequestMapping("/api") public class GenApiController implements GenApi { private final GenApiDelegate delegate; diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/configuration/HomeController.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/configuration/HomeController.java index 5f7a6e2d4304..187d0b415629 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/configuration/HomeController.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/configuration/HomeController.java @@ -27,7 +27,6 @@ public class HomeController { @RequestMapping(value = "/") public String index() { - System.out.println("swagger-ui.html"); return "redirect:swagger-ui.html"; } } diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/configuration/OpenAPIDocumentationConfig.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/configuration/OpenAPIDocumentationConfig.java index fd4226ae3b57..6a0fdbe131ab 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/configuration/OpenAPIDocumentationConfig.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/configuration/OpenAPIDocumentationConfig.java @@ -17,9 +17,10 @@ package org.openapitools.codegen.online.configuration; +import com.fasterxml.jackson.databind.JsonNode; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; - +import org.springframework.core.io.Resource; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; @@ -28,6 +29,8 @@ import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; +import java.io.InputStream; + @Configuration @EnableSwagger2 @@ -51,8 +54,12 @@ public Docket customImplementation(){ .select() .apis(RequestHandlerSelectors.basePackage("org.openapitools.codegen.online.api")) .build() + .forCodeGeneration(true) .directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class) .directModelSubstitute(java.time.OffsetDateTime.class, java.util.Date.class) + .directModelSubstitute(JsonNode.class, java.lang.Object.class) + .ignoredParameterTypes(Resource.class) + .ignoredParameterTypes(InputStream.class) .apiInfo(apiInfo()); } diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/GeneratorInput.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/GeneratorInput.java index 3e7d075b4d42..3672506d213a 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/GeneratorInput.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/GeneratorInput.java @@ -39,7 +39,6 @@ public void setAuthorizationValue(AuthorizationValue authorizationValue) { this.authorizationValue = authorizationValue; } - @ApiModelProperty(dataType = "Object") public JsonNode getSpec() { return spec; } diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java index 69ea454525ff..9bef912f138f 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java @@ -37,17 +37,17 @@ import java.util.Map; public class Generator { - static Logger LOGGER = LoggerFactory.getLogger(Generator.class); + private static Logger LOGGER = LoggerFactory.getLogger(Generator.class); public static Map getOptions(String language) { - CodegenConfig config = null; + CodegenConfig config; try { config = CodegenConfigLoader.forName(language); } catch (Exception e) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, String.format("Unsupported target %s supplied. %s", language, e)); } - Map map = new LinkedHashMap(); + Map map = new LinkedHashMap<>(); for (CliOption option : config.cliOptions()) { map.put(option.getOpt(), option); } @@ -102,7 +102,7 @@ private static String generate(String language, GeneratorInput opts, Type type) throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "No OpenAPI specification was supplied"); } } else if (opts.getAuthorizationValue() != null) { - List authorizationValues = new ArrayList(); + List authorizationValues = new ArrayList<>(); authorizationValues.add(opts.getAuthorizationValue()); openapi = new OpenAPIParser().readContents(node.toString(), authorizationValues, parseOptions).getOpenAPI(); @@ -115,7 +115,7 @@ private static String generate(String language, GeneratorInput opts, Type type) String destPath = null; - if (opts != null && opts.getOptions() != null) { + if (opts.getOptions() != null) { destPath = opts.getOptions().get("outputFolder"); } if (destPath == null) { @@ -129,7 +129,7 @@ private static String generate(String language, GeneratorInput opts, Type type) clientOptInput.opts(clientOpts).openAPI(openapi); - CodegenConfig codegenConfig = null; + CodegenConfig codegenConfig; try { codegenConfig = CodegenConfigLoader.forName(language); } catch (RuntimeException e) { @@ -150,7 +150,7 @@ private static String generate(String language, GeneratorInput opts, Type type) try { List files = new DefaultGenerator().opts(clientOptInput).generate(); if (files.size() > 0) { - List filesToAdd = new ArrayList(); + List filesToAdd = new ArrayList<>(); LOGGER.debug("adding to " + outputFolder); filesToAdd.add(new File(outputFolder)); ZipUtil zip = new ZipUtil(); @@ -177,7 +177,7 @@ private static String generate(String language, GeneratorInput opts, Type type) return outputFilename; } - protected static File getTmpFolder() { + private static File getTmpFolder() { try { File outputFolder = File.createTempFile("codegen-", "-tmp"); outputFolder.delete(); diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/ZipUtil.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/ZipUtil.java index 0fb9bc8504b9..ec7f6f3d77e1 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/ZipUtil.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/ZipUtil.java @@ -49,7 +49,7 @@ public class ZipUtil { * @throws IOException if IO exception occurs */ public void compressFiles(List listFiles, String destZipFile) - throws FileNotFoundException, IOException { + throws IOException { ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(destZipFile)); diff --git a/modules/openapi-generator-online/src/main/resources/application.properties b/modules/openapi-generator-online/src/main/resources/application.properties index 1088b03c094f..8a3fc27449e9 100644 --- a/modules/openapi-generator-online/src/main/resources/application.properties +++ b/modules/openapi-generator-online/src/main/resources/application.properties @@ -1,5 +1,4 @@ springfox.documentation.swagger.v2.path=/api-docs -server.servlet.context-path=/api server.port=8080 spring.jackson.date-format=org.openapitools.codegen.online.RFC3339DateFormat spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false