diff --git a/modules/openapi-generator-online/.openapi-generator-ignore b/modules/openapi-generator-online/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/modules/openapi-generator-online/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# 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 OpenAPI Generator 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/modules/openapi-generator-online/.openapi-generator/VERSION b/modules/openapi-generator-online/.openapi-generator/VERSION new file mode 100644 index 00000000000..096bf47efe3 --- /dev/null +++ b/modules/openapi-generator-online/.openapi-generator/VERSION @@ -0,0 +1 @@ +3.0.0-SNAPSHOT \ No newline at end of file diff --git a/modules/openapi-generator-online/Dockerfile b/modules/openapi-generator-online/Dockerfile deleted file mode 100644 index ba999000e16..00000000000 --- a/modules/openapi-generator-online/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM openjdk:8-jre-alpine - -WORKDIR /generator - -COPY target/lib/jetty-runner* /generator/jetty-runner.jar -COPY target/*.war /generator/swagger-generator.war - -ENV GENERATOR_HOST=https://generator.swaggerhub.com/api/swagger.json - -EXPOSE 8080 - -CMD ["java", "-jar", "/generator/jetty-runner.jar", "/generator/swagger-generator.war"] - diff --git a/modules/openapi-generator-online/README.md b/modules/openapi-generator-online/README.md new file mode 100644 index 00000000000..a12a59c79ed --- /dev/null +++ b/modules/openapi-generator-online/README.md @@ -0,0 +1,15 @@ +# OpenAPI generated server + +Spring Boot Server + + +## Overview +This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. +By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub. +This is an example of building a OpenAPI-enabled server in Java using the SpringBoot framework. + +The underlying library integrating OpenAPI to SpringBoot is [springfox](https://github.com/springfox/springfox) + +Start your server as an simple java application + +Change default port value in application.properties \ No newline at end of file diff --git a/modules/openapi-generator-online/pom.xml b/modules/openapi-generator-online/pom.xml index df6110365d9..2911defd50a 100644 --- a/modules/openapi-generator-online/pom.xml +++ b/modules/openapi-generator-online/pom.xml @@ -1,5 +1,4 @@ - + 4.0.0 org.openapitools @@ -8,229 +7,82 @@ ../.. openapi-generator-online - war + jar openapi-generator-online + 1.0.0 + + 1.8 + ${java.version} + ${java.version} + 2.8.0 + + + + + org.springframework.boot + spring-boot-dependencies + 2.0.2.RELEASE + pom + import + + + src/main/java - - - src/main/resources - true - - **/version.prop - logback.xml - - - - maven-dependency-plugin - - - package - - copy-dependencies - - - ${project.build.directory}/lib - - - - - - org.apache.maven.plugins - maven-war-plugin - 3.1.0 - - - - - ${project.build.directory}/swagger-ui-master/dist - - index.html - - - - - - - maven-failsafe-plugin - 2.6 + org.springframework.boot + spring-boot-maven-plugin - integration-test - verify + repackage - - org.eclipse.jetty - jetty-maven-plugin - ${jetty-version} - - - / - - target/${project.artifactId}-${project.version} - 8079 - stopit - - 60000 - - - - - start-jetty - pre-integration-test - - start - - - 0 - - - - stop-jetty - post-integration-test - - stop - - - - - - com.googlecode.maven-download-plugin - download-maven-plugin - 1.2.1 - - - swagger-ui - - wget - - - https://github.com/swagger-api/swagger-ui/archive/master.tar.gz - true - - ${project.build.directory} - - - - - - net.revelc.code - formatter-maven-plugin - - - ${project.basedir}${file.separator}${project.parent.relativePath}${file.separator}eclipse-formatter.xml - - - io.swagger - swagger-jersey2-jaxrs - 1.5.18 + org.springframework.boot + spring-boot-starter-web + - org.openapitools - openapi-generator - ${project.parent.version} - - - org.openapitools - openapi-generator - ${project.parent.version} - test-jar - test - - - ch.qos.logback - logback-classic - ${logback-version} - - - ch.qos.logback - logback-core - ${logback-version} - - - - javax.servlet - servlet-api - ${servlet-api-version} - - - org.glassfish.jersey.containers - jersey-container-servlet-core - ${jersey2-version} - - - org.glassfish.jersey.media - jersey-media-multipart - ${jersey2-version} - - - net.lingala.zip4j - zip4j - ${zip-version} - - - org.eclipse.jetty - jetty-server - ${jetty-version} - - - org.eclipse.jetty - jetty-start - ${jetty-version} - - - org.eclipse.jetty - jetty-xml - ${jetty-version} - - - org.eclipse.jetty - jetty-webapp - ${jetty-version} - - - org.eclipse.jetty - jetty-deploy - ${jetty-version} - - - org.eclipse.jetty - jetty-runner - ${jetty-version} + io.springfox + springfox-swagger2 + ${springfox-version} - org.glassfish - javax.el + io.swagger + swagger-annotations + + + io.swagger + swagger-models - org.testng - testng + io.springfox + springfox-swagger-ui + ${springfox-version} + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + + javax.validation + validation-api - com.fasterxml.jackson.jaxrs - jackson-jaxrs-json-provider - ${jackson-version} + org.openapitools + openapi-generator + ${project.parent.version} - - 2.5 - 1.0.1 - 1.0.0 - 2.5 - 1.3.2 - 9.2.9.v20150224 - 2.6 - diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/Bootstrap.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/Bootstrap.java deleted file mode 100644 index 1f72eab252f..00000000000 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/Bootstrap.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openapitools.codegen.online; - -import org.apache.commons.io.IOUtils; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import java.io.IOException; -import java.io.InputStream; - -public class Bootstrap extends HttpServlet { - private static final long serialVersionUID = 1400930071893332856L; - - @Override - public void init(ServletConfig config) throws ServletException { - DynamicConfig bc = new DynamicConfig(); - bc.setBasePath("/api"); - bc.setTitle("OpenAPI Generator"); - bc.setDescription("This is an online OpenAPI generator. You can find out more " - + "at https://github.com/openapi-tools/openapi-generator"); - bc.setTermsOfServiceUrl("https://www.apache.org/licenses/LICENSE-2.0"); - bc.setContact("openapi-generator@gmail.com"); - bc.setLicense("Apache 2.0"); - InputStream stream = getClass().getResourceAsStream("/version.prop"); - if (stream == null) { - bc.setVersion("0.0.0"); - } else { - try { - bc.setVersion(IOUtils.toString(stream, "UTF-8")); - stream.close(); - } catch (IOException e) { - bc.setVersion("0.0.0"); - } - } - - bc.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html"); - bc.setResourcePackage("org.openapitools.codegen.online.resource"); - bc.setScan(true); - } -} diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/DynamicConfig.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/DynamicConfig.java deleted file mode 100644 index a41c30e38b1..00000000000 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/DynamicConfig.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openapitools.codegen.online; - -import org.openapitools.codegen.CodegenConfig; -import org.openapitools.codegen.CodegenConfigLoader; -import org.openapitools.codegen.CodegenType; -import io.swagger.jaxrs.config.BeanConfig; -import io.swagger.models.Operation; -import io.swagger.models.Path; -import io.swagger.models.Swagger; -import io.swagger.models.parameters.Parameter; -import io.swagger.models.parameters.PathParameter; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class DynamicConfig extends BeanConfig { - static List clients = new ArrayList(); - static List servers = new ArrayList(); - - static { - List extensions = CodegenConfigLoader.getAll(); - for (CodegenConfig config : extensions) { - if (config.getTag().equals(CodegenType.CLIENT) - || config.getTag().equals(CodegenType.DOCUMENTATION)) { - clients.add(config.getName()); - } else if (config.getTag().equals(CodegenType.SERVER)) { - servers.add(config.getName()); - } - } - Collections.sort(clients, String.CASE_INSENSITIVE_ORDER); - Collections.sort(servers, String.CASE_INSENSITIVE_ORDER); - } - - @Override - public Swagger configure(Swagger swagger) { - Path clientPath = swagger.getPaths().get("/gen/clients/{language}"); - // update the path description based on what clients are available via SPI - if (clientPath != null) { - Operation post = clientPath.getPost(); - Parameter framework = post.getParameters().get(0); - if (framework instanceof PathParameter) { - PathParameter param = (PathParameter) framework; - param.setEnum(clients); - } - - Operation get = clientPath.getGet(); - if (get != null) { - framework = get.getParameters().get(0); - if (framework instanceof PathParameter) { - PathParameter param = (PathParameter) framework; - param.setEnum(clients); - } - } - } - - Path serverPath = swagger.getPaths().get("/gen/servers/{framework}"); - if (serverPath != null) { - Operation post = serverPath.getPost(); - Parameter framework = post.getParameters().get(0); - if (framework instanceof PathParameter) { - PathParameter param = (PathParameter) framework; - param.setEnum(servers); - } - - Operation get = serverPath.getGet(); - if (get != null) { - framework = get.getParameters().get(0); - if (framework instanceof PathParameter) { - PathParameter param = (PathParameter) framework; - param.setEnum(servers); - } - } - } - - return swagger.info(getInfo()).host(getHost()).basePath("/api"); - } -} 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 new file mode 100644 index 00000000000..09b7610877e --- /dev/null +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/OpenAPI2SpringBoot.java @@ -0,0 +1,33 @@ +package org.openapitools.codegen.online; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.ExitCodeGenerator; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication +@ComponentScan(basePackages = { "org.openapitools.codegen.online", "org.openapitools.codegen.online.api", "org.openapitools.codegen.online.configuration"}) +public class OpenAPI2SpringBoot implements CommandLineRunner { + + @Override + public void run(String... arg0) throws Exception { + if (arg0.length > 0 && arg0[0].equals("exitcode")) { + throw new ExitException(); + } + } + + public static void main(String[] args) throws Exception { + new SpringApplication(OpenAPI2SpringBoot.class).run(args); + } + + class ExitException extends RuntimeException implements ExitCodeGenerator { + private static final long serialVersionUID = 1L; + + @Override + public int getExitCode() { + return 10; + } + + } +} diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/RFC3339DateFormat.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/RFC3339DateFormat.java new file mode 100644 index 00000000000..a29a8771fc5 --- /dev/null +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/RFC3339DateFormat.java @@ -0,0 +1,22 @@ +package org.openapitools.codegen.online; + +import com.fasterxml.jackson.databind.util.ISO8601DateFormat; +import com.fasterxml.jackson.databind.util.ISO8601Utils; + +import java.text.FieldPosition; +import java.util.Date; + + +public class RFC3339DateFormat extends ISO8601DateFormat { + + private static final long serialVersionUID = 1L; + + // Same as ISO8601DateFormat but serializing milliseconds. + @Override + public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { + String value = ISO8601Utils.format(date, true); + toAppendTo.append(value); + return toAppendTo; + } + +} \ No newline at end of file diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/ApiOriginFilter.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/ApiOriginFilter.java new file mode 100644 index 00000000000..7f81cf93278 --- /dev/null +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/ApiOriginFilter.java @@ -0,0 +1,27 @@ +package org.openapitools.codegen.online.api; + +import java.io.IOException; + +import javax.servlet.*; +import javax.servlet.http.HttpServletResponse; + + +public class ApiOriginFilter implements javax.servlet.Filter { + @Override + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + HttpServletResponse res = (HttpServletResponse) response; + res.addHeader("Access-Control-Allow-Origin", "*"); + res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); + res.addHeader("Access-Control-Allow-Headers", "Content-Type"); + chain.doFilter(request, response); + } + + @Override + public void destroy() { + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + } +} diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/ApiUtil.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/ApiUtil.java new file mode 100644 index 00000000000..a75835ccd07 --- /dev/null +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/ApiUtil.java @@ -0,0 +1,17 @@ +package org.openapitools.codegen.online.api; + +import org.springframework.web.context.request.NativeWebRequest; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class ApiUtil { + public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { + try { + req.getNativeResponse(HttpServletResponse.class).addHeader("Content-Type", contentType); + req.getNativeResponse(HttpServletResponse.class).getOutputStream().print(example); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} \ No newline at end of file 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 new file mode 100644 index 00000000000..d6271c23c80 --- /dev/null +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/GenApi.java @@ -0,0 +1,99 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (3.0.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package org.openapitools.codegen.online.api; + +import io.swagger.annotations.*; +import org.openapitools.codegen.CliOption; +import org.openapitools.codegen.online.model.GeneratorInput; +import org.openapitools.codegen.online.model.ResponseCode; +import org.springframework.core.io.Resource; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import javax.validation.Valid; +import java.util.List; +import java.util.Map; + +@Api(value = "gen", description = "the gen API") +public interface GenApi { + GenApiDelegate getDelegate(); + + @ApiOperation(value = "Gets languages supported by the client generator", nickname = "clientOptions", notes = "", response = String.class, responseContainer = "List", tags={ "clients", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = String.class, responseContainer = "List") }) + @RequestMapping(value = "/gen/clients", + method = RequestMethod.GET) + default ResponseEntity> clientOptions() { + return getDelegate().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", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = String.class) }) + @RequestMapping(value = "/gen/download/{fileId}", + produces = { "application/octet-stream" }, + method = RequestMethod.GET) + default ResponseEntity downloadFile(@ApiParam(value = "",required=true) @PathVariable("fileId") String fileId) { + return getDelegate().downloadFile(fileId); + } + + + @ApiOperation(value = "Generates a client library", nickname = "generateClient", notes = "Accepts a `GeneratorInput` options map for spec location and generation options", response = ResponseCode.class, tags={ "clients", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = ResponseCode.class) }) + @RequestMapping(value = "/gen/clients/{language}", + method = RequestMethod.POST) + default ResponseEntity generateClient(@ApiParam(value = "The target language for the client library",required=true, allowableValues = "ada, akka-scala, android, apex, bash, clojure, cpprest, csharp, csharp-dotnet2, cwiki, dart, dynamic-html, eiffel, elixir, elm, erlang-client, flash, go, groovy, haskell-http-client, html, html2, java, javascript, javascript-closure-angular, jaxrs-cxf-client, jmeter, kotlin, lua, objc, perl, php, powershell, python, qt5cpp, r, ruby, rust, scala, scalaz, swagger, swagger-yaml, swift, swift3, swift4, tizen, typescript-angular, typescript-angularjs, typescript-aurelia, typescript-fetch, typescript-jquery, typescript-node") @PathVariable("language") String language,@ApiParam(value = "Configuration for building the client library" ,required=true ) @Valid @RequestBody GeneratorInput generatorInput) { + return getDelegate().generateClient(language, generatorInput); + } + + + @ApiOperation(value = "Generates a server library", nickname = "generateServerForLanguage", notes = "Accepts a `GeneratorInput` options map for spec location and generation options.", response = ResponseCode.class, tags={ "servers", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = ResponseCode.class) }) + @RequestMapping(value = "/gen/servers/{framework}", + method = RequestMethod.POST) + default ResponseEntity generateServerForLanguage(@ApiParam(value = "framework",required=true, allowableValues = "ada-server, aspnetcore, erlang-server, finch, go-server, haskell, inflector, java-pkmst, java-play-framework, java-vertx, jaxrs, jaxrs-cxf, jaxrs-cxf-cdi, jaxrs-resteasy, jaxrs-resteasy-eap, jaxrs-spec, lumen, msf4j, nancyfx, nodejs-server, php-silex, php-symfony, pistache-server, python-flask, rails5, restbed, rust-server, scala-lagom-server, scalatra, sinatra, slim, spring, undertow, ze-ph") @PathVariable("framework") String framework,@ApiParam(value = "parameters" ,required=true ) @Valid @RequestBody GeneratorInput generatorInput) { + return getDelegate().generateServerForLanguage(framework, generatorInput); + } + + + @ApiOperation(value = "Returns options for a client library", nickname = "getClientOptions", notes = "", response = CliOption.class, responseContainer = "Map", tags={ "clients", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = CliOption.class, responseContainer = "Map") }) + @RequestMapping(value = "/gen/clients/{language}", + produces = { "application/json" }, + method = RequestMethod.GET) + default ResponseEntity> getClientOptions(@ApiParam(value = "The target language for the client library",required=true, allowableValues = "ada, akka-scala, android, apex, bash, clojure, cpprest, csharp, csharp-dotnet2, cwiki, dart, dynamic-html, eiffel, elixir, elm, erlang-client, flash, go, groovy, haskell-http-client, html, html2, java, javascript, javascript-closure-angular, jaxrs-cxf-client, jmeter, kotlin, lua, objc, perl, php, powershell, python, qt5cpp, r, ruby, rust, scala, scalaz, swagger, swagger-yaml, swift, swift3, swift4, tizen, typescript-angular, typescript-angularjs, typescript-aurelia, typescript-fetch, typescript-jquery, typescript-node") @PathVariable("language") String language) { + return getDelegate().getClientOptions(language); + } + + + @ApiOperation(value = "Returns options for a server framework", nickname = "getServerOptions", notes = "", response = CliOption.class, responseContainer = "Map", tags={ "servers", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = CliOption.class, responseContainer = "Map") }) + @RequestMapping(value = "/gen/servers/{framework}", + produces = { "application/json" }, + method = RequestMethod.GET) + default ResponseEntity> getServerOptions(@ApiParam(value = "The target language for the server framework",required=true, allowableValues = "ada-server, aspnetcore, erlang-server, finch, go-server, haskell, inflector, java-pkmst, java-play-framework, java-vertx, jaxrs, jaxrs-cxf, jaxrs-cxf-cdi, jaxrs-resteasy, jaxrs-resteasy-eap, jaxrs-spec, lumen, msf4j, nancyfx, nodejs-server, php-silex, php-symfony, pistache-server, python-flask, rails5, restbed, rust-server, scala-lagom-server, scalatra, sinatra, slim, spring, undertow, ze-ph") @PathVariable("framework") String framework) { + return getDelegate().getServerOptions(framework); + } + + + @ApiOperation(value = "Gets languages supported by the server generator", nickname = "serverOptions", notes = "", response = String.class, responseContainer = "List", tags={ "servers", }) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "successful operation", response = String.class, responseContainer = "List") }) + @RequestMapping(value = "/gen/servers", + method = RequestMethod.GET) + default ResponseEntity> serverOptions() { + return getDelegate().serverOptions(); + } + +} 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 new file mode 100644 index 00000000000..57fa927a6b2 --- /dev/null +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/GenApiController.java @@ -0,0 +1,20 @@ +package org.openapitools.codegen.online.api; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; + +@Controller +public class GenApiController implements GenApi { + + private final GenApiDelegate delegate; + + @Autowired + public GenApiController(GenApiDelegate delegate) { + this.delegate = delegate; + } + + @Override + public GenApiDelegate getDelegate() { + return delegate; + } +} diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/GenApiDelegate.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/GenApiDelegate.java new file mode 100644 index 00000000000..b64fbb0e078 --- /dev/null +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/api/GenApiDelegate.java @@ -0,0 +1,117 @@ +package org.openapitools.codegen.online.api; + +import org.openapitools.codegen.CliOption; +import org.openapitools.codegen.online.model.GeneratorInput; +import org.openapitools.codegen.online.model.ResponseCode; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.context.request.NativeWebRequest; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * A delegate to be called by the {@link GenApiController}}. + * Implement this interface with a {@link org.springframework.stereotype.Service} annotated class. + */ + +public interface GenApiDelegate { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * @see GenApi#clientOptions + */ + default ResponseEntity> clientOptions() { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { + ApiUtil.setExampleResponse(request, "*/*", "\"\""); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** + * @see GenApi#downloadFile + */ + default ResponseEntity downloadFile(String fileId) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** + * @see GenApi#generateClient + */ + default ResponseEntity generateClient( String language, + GeneratorInput generatorInput) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { + ApiUtil.setExampleResponse(request, "*/*", "{ \"code\" : \"d40029be-eda6-4d62-b1ef-d05e2e91a72a\", \"link\" : \"http://generator.swagger.io:80/api/gen/download/d40029be-eda6-4d62-b1ef-d05e2e91a72a\"}"); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** + * @see GenApi#generateServerForLanguage + */ + default ResponseEntity generateServerForLanguage( String framework, + GeneratorInput generatorInput) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { + ApiUtil.setExampleResponse(request, "*/*", "{ \"code\" : \"d40029be-eda6-4d62-b1ef-d05e2e91a72a\", \"link\" : \"http://generator.swagger.io:80/api/gen/download/d40029be-eda6-4d62-b1ef-d05e2e91a72a\"}"); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** + * @see GenApi#getClientOptions + */ + default ResponseEntity> getClientOptions(String language) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** + * @see GenApi#getServerOptions + */ + default ResponseEntity> getServerOptions( String framework) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + /** + * @see GenApi#serverOptions + */ + default ResponseEntity> serverOptions() { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("*/*"))) { + ApiUtil.setExampleResponse(request, "*/*", "\"\""); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + +} 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 new file mode 100644 index 00000000000..e6474a7d720 --- /dev/null +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/configuration/HomeController.java @@ -0,0 +1,16 @@ +package org.openapitools.codegen.online.configuration; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * Home redirection to swagger api documentation + */ +@Controller +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 new file mode 100644 index 00000000000..5347dc257be --- /dev/null +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/configuration/OpenAPIDocumentationConfig.java @@ -0,0 +1,42 @@ +package org.openapitools.codegen.online.configuration; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + + +@Configuration +@EnableSwagger2 +public class OpenAPIDocumentationConfig { + + ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("Swagger Generator") + .description("This is an online swagger codegen server. You can find out more at https://github.com/swagger-api/swagger-codegen or on [irc.freenode.net, #swagger](http://swagger.io/irc/).") + .license("Apache 2.0") + .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") + .termsOfServiceUrl("") + .version("2.3.1") + .contact(new Contact("","", "")) + .build(); + } + + @Bean + public Docket customImplementation(){ + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.basePackage("org.openapitools.codegen.online.api")) + .build() + .directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class) + .directModelSubstitute(java.time.OffsetDateTime.class, java.util.Date.class) + .apiInfo(apiInfo()); + } + +} diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/exception/ApiException.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/exception/ApiException.java deleted file mode 100644 index 0b41e97a777..00000000000 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/exception/ApiException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openapitools.codegen.online.exception; - -public class ApiException extends Exception { - private static final long serialVersionUID = -5085112752305370687L; - private int code; - - public ApiException(int code, String msg) { - super(msg); - this.code = code; - } - - public int getCode() { - return code; - } -} diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/exception/BadRequestException.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/exception/BadRequestException.java deleted file mode 100644 index 3ca46bfe675..00000000000 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/exception/BadRequestException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openapitools.codegen.online.exception; - -import org.apache.http.HttpStatus; - -public class BadRequestException extends ApiException { - private static final long serialVersionUID = -5540416398447252055L; - - public BadRequestException(String msg) { - super(HttpStatus.SC_BAD_REQUEST, msg); - } -} diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/exception/NotFoundException.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/exception/NotFoundException.java deleted file mode 100644 index 70bb05e8249..00000000000 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/exception/NotFoundException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openapitools.codegen.online.exception; - -import org.apache.http.HttpStatus; - -public class NotFoundException extends ApiException { - private static final long serialVersionUID = -1223255119112336573L; - - public NotFoundException(String msg) { - super(HttpStatus.SC_NOT_FOUND, msg); - } -} diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/ApiResponse.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/ApiResponse.java index 1db77598bde..b086eda99e7 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/ApiResponse.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/ApiResponse.java @@ -1,18 +1,15 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/** + * Copyright 2016 SmartBear Software + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package org.openapitools.codegen.online.model; diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/Generated.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/Generated.java index e78f201bb78..c806db5efcc 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/Generated.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/Generated.java @@ -1,18 +1,15 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/** + * Copyright 2016 SmartBear Software + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package org.openapitools.codegen.online.model; 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 3f50919fc0d..da24cf1cfb7 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 @@ -1,33 +1,16 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package org.openapitools.codegen.online.model; import com.fasterxml.jackson.databind.JsonNode; import io.swagger.annotations.ApiModelProperty; -import io.swagger.models.auth.AuthorizationValue; import io.swagger.models.auth.SecuritySchemeDefinition; +import io.swagger.v3.parser.core.models.AuthorizationValue; import java.util.Map; public class GeneratorInput { private JsonNode spec; private Map options; - private String swaggerUrl; + private String openAPIUrl; private SecuritySchemeDefinition auth; private AuthorizationValue authorizationValue; @@ -57,12 +40,12 @@ public class GeneratorInput { } @ApiModelProperty(example = "http://petstore.swagger.io/v2/swagger.json") - public String getSwaggerUrl() { - return swaggerUrl; + public String getOpenAPIUrl() { + return openAPIUrl; } - public void setSwaggerUrl(String url) { - this.swaggerUrl = url; + public void setOpenAPIUrl(String url) { + this.openAPIUrl = url; } @Deprecated diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/InputOption.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/InputOption.java deleted file mode 100644 index 75dcd8731e4..00000000000 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/InputOption.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openapitools.codegen.online.model; - -public class InputOption { - private String name; - private String description; - private Boolean required; - private String defaultValue; - - public InputOption() {} - - public InputOption(String name, String description, String defaultValue, Boolean required) { - this.name = name; - this.description = description; - this.defaultValue = defaultValue; - this.required = required; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Boolean getRequired() { - return required; - } - - public void setRequired(Boolean required) { - this.required = required; - } - - public String getDefaultValue() { - return defaultValue; - } - - public void setDefaultValue(String defaultValue) { - this.defaultValue = defaultValue; - } -} diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/ResponseCode.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/ResponseCode.java index 8bf5ef1f668..f21d8623357 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/ResponseCode.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/model/ResponseCode.java @@ -1,20 +1,3 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package org.openapitools.codegen.online.model; import io.swagger.annotations.ApiModelProperty; diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/resource/CodegenResource.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/resource/CodegenResource.java deleted file mode 100644 index b143b985174..00000000000 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/resource/CodegenResource.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openapitools.codegen.online.resource; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import org.openapitools.codegen.CliOption; -import org.openapitools.codegen.CodegenConfig; -import org.openapitools.codegen.CodegenConfigLoader; -import org.openapitools.codegen.CodegenType; -import org.openapitools.codegen.online.exception.BadRequestException; -import org.openapitools.codegen.online.model.Generated; -import org.openapitools.codegen.online.model.GeneratorInput; -import org.openapitools.codegen.online.model.ResponseCode; -import org.openapitools.codegen.online.http.Generator; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.*; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.File; -import java.util.*; - -@Path("/gen") -@Api(value = "/gen", description = "Resource for generating swagger components") -public class CodegenResource { - static List clients = new ArrayList(); - static List servers = new ArrayList(); - private static Map fileMap = new HashMap(); - - static { - List extensions = CodegenConfigLoader.getAll(); - for (CodegenConfig config : extensions) { - if (config.getTag().equals(CodegenType.CLIENT) - || config.getTag().equals(CodegenType.DOCUMENTATION)) { - clients.add(config.getName()); - } else if (config.getTag().equals(CodegenType.SERVER)) { - servers.add(config.getName()); - } - } - - Collections.sort(clients, String.CASE_INSENSITIVE_ORDER); - Collections.sort(servers, String.CASE_INSENSITIVE_ORDER); - } - - @GET - @Path("/download/{fileId}") - @Produces({MediaType.APPLICATION_OCTET_STREAM}) - @ApiOperation( - value = "Downloads a pre-generated file", - 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"}) - public Response downloadFile(@PathParam("fileId") String fileId) throws Exception { - Generated g = fileMap.get(fileId); - System.out.println("looking for fileId " + fileId); - System.out.println("got filename " + g.getFilename()); - if (g.getFilename() != null) { - File file = new java.io.File(g.getFilename()); - byte[] bytes = org.apache.commons.io.FileUtils.readFileToByteArray(file); - - try { - FileUtils.deleteDirectory(file.getParentFile()); - } catch (Exception e) { - System.out.println("failed to delete file " + file.getAbsolutePath()); - } - - return Response - .ok(bytes, "application/zip") - .header("Content-Disposition", - "attachment; filename=\"" + g.getFriendlyName() + "-generated.zip\"") - .header("Accept-Range", "bytes").header("Content-Length", bytes.length).build(); - } else { - return Response.status(404).build(); - } - } - - @POST - @Path("/clients/{language}") - @ApiOperation( - value = "Generates a client library", - notes = "Accepts a `GeneratorInput` options map for spec location and generation options", - response = ResponseCode.class, tags = "clients") - public Response generateClient( - @Context HttpServletRequest request, - @ApiParam(value = "The target language for the client library", required = true) @PathParam("language") String language, - @ApiParam(value = "Configuration for building the client library", required = true) GeneratorInput opts) - throws Exception { - - String filename = Generator.generateClient(language, opts); - String host = System.getenv("GENERATOR_HOST"); - - if (StringUtils.isBlank(host)) { - String scheme = request.getHeader("X-SSL"); - String port = ""; - if ("1".equals(scheme)) { - scheme = "https"; - } else { - scheme = request.getScheme(); - port = ":" + request.getServerPort(); - } - host = scheme + "://" + request.getServerName() + port; - } - - if (filename != null) { - String code = String.valueOf(UUID.randomUUID().toString()); - Generated g = new Generated(); - g.setFilename(filename); - g.setFriendlyName(language + "-client"); - fileMap.put(code, g); - System.out.println(code + ", " + filename); - String link = host + "/api/gen/download/" + code; - return Response.ok().entity(new ResponseCode(code, link)).build(); - } else { - return Response.status(500).build(); - } - } - - @GET - @Path("/clients/{language}") - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Returns options for a client library", response = CliOption.class, - responseContainer = "map", tags = "clients") - public Response getClientOptions( - @SuppressWarnings("unused") @Context HttpServletRequest request, - @ApiParam(value = "The target language for the client library", required = true) @PathParam("language") String language) - throws Exception { - - Map opts = Generator.getOptions(language); - - if (opts != null) { - return Response.ok().entity(opts).build(); - } else { - return Response.status(404).build(); - } - } - - @GET - @Path("/servers/{framework}") - @Produces({MediaType.APPLICATION_JSON}) - @ApiOperation(value = "Returns options for a server framework", response = CliOption.class, - responseContainer = "map", tags = "servers") - public Response getServerOptions( - @SuppressWarnings("unused") @Context HttpServletRequest request, - @ApiParam(value = "The target language for the server framework", required = true) @PathParam("framework") String framework) - throws Exception { - - Map opts = Generator.getOptions(framework); - - if (opts != null) { - return Response.ok().entity(opts).build(); - } else { - return Response.status(404).build(); - } - } - - @GET - @Path("/clients") - @ApiOperation(value = "Gets languages supported by the client generator", - response = String.class, responseContainer = "List", tags = "clients") - public Response clientOptions() { - String[] languages = new String[clients.size()]; - languages = clients.toArray(languages); - return Response.ok().entity(languages).build(); - } - - @GET - @Path("/servers") - @ApiOperation(value = "Gets languages supported by the server generator", - response = String.class, responseContainer = "List", tags = "servers") - public Response serverOptions() { - String[] languages = new String[servers.size()]; - languages = servers.toArray(languages); - return Response.ok().entity(languages).build(); - } - - @POST - @Path("/servers/{framework}") - @ApiOperation( - value = "Generates a server library", - notes = "Accepts a `GeneratorInput` options map for spec location and generation options.", - response = ResponseCode.class, tags = "servers") - public Response generateServerForLanguage(@Context HttpServletRequest request, @ApiParam( - value = "framework", required = true) @PathParam("framework") String framework, - @ApiParam(value = "parameters", required = true) GeneratorInput opts) throws Exception { - if (framework == null) { - throw new BadRequestException("Framework is required"); - } - String filename = Generator.generateServer(framework, opts); - System.out.println("generated name: " + filename); - - String host = - request.getScheme() + "://" + request.getServerName() + ":" - + request.getServerPort(); - - if (filename != null) { - String code = String.valueOf(UUID.randomUUID().toString()); - Generated g = new Generated(); - g.setFilename(filename); - g.setFriendlyName(framework + "-server"); - fileMap.put(code, g); - System.out.println(code + ", " + filename); - String link = host + "/api/gen/download/" + code; - return Response.ok().entity(new ResponseCode(code, link)).build(); - } else { - return Response.status(500).build(); - } - } -} diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/resource/ExceptionWriter.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/resource/ExceptionWriter.java deleted file mode 100644 index aa6be3a599b..00000000000 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/resource/ExceptionWriter.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openapitools.codegen.online.resource; - -import org.openapitools.codegen.online.exception.ApiException; -import org.openapitools.codegen.online.exception.BadRequestException; -import org.openapitools.codegen.online.exception.NotFoundException; -import org.openapitools.codegen.online.model.ApiResponse; -import org.openapitools.codegen.online.util.ValidationException; - -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; - -@Provider -public class ExceptionWriter implements ExceptionMapper { - @Override - public Response toResponse(Exception exception) { - if (exception instanceof javax.ws.rs.WebApplicationException) { - javax.ws.rs.WebApplicationException e = (javax.ws.rs.WebApplicationException) exception; - return Response.status(e.getResponse().getStatus()) - .entity(new ApiResponse(e.getResponse().getStatus(), exception.getMessage())) - .build(); - } else if (exception instanceof com.fasterxml.jackson.core.JsonParseException) { - return Response.status(400).entity(new ApiResponse(400, "bad input")).build(); - } else if (exception instanceof ValidationException) { - ValidationException e = (ValidationException) exception; - return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build(); - } else if (exception instanceof NotFoundException) { - return Response.status(Status.NOT_FOUND) - .entity(new ApiResponse(ApiResponse.ERROR, exception.getMessage())).build(); - } else if (exception instanceof BadRequestException) { - return Response.status(Status.BAD_REQUEST) - .entity(new ApiResponse(ApiResponse.ERROR, exception.getMessage())).build(); - } else if (exception instanceof ApiException) { - return Response.status(Status.BAD_REQUEST) - .entity(new ApiResponse(ApiResponse.ERROR, exception.getMessage())).build(); - } else { - return Response.status(500).entity(new ApiResponse(500, "something bad happened")) - .build(); - } - } -} diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/GenApiService.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/GenApiService.java new file mode 100644 index 00000000000..926c3390cdb --- /dev/null +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/GenApiService.java @@ -0,0 +1,189 @@ +package org.openapitools.codegen.online.service; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.openapitools.codegen.online.api.GenApiDelegate; +import org.openapitools.codegen.CliOption; +import org.openapitools.codegen.CodegenConfig; +import org.openapitools.codegen.CodegenConfigLoader; +import org.openapitools.codegen.CodegenType; +import org.openapitools.codegen.online.model.Generated; +import org.openapitools.codegen.online.model.GeneratorInput; +import org.openapitools.codegen.online.model.ResponseCode; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.server.ResponseStatusException; + +import javax.servlet.http.HttpServletRequest; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; + +@Service +public class GenApiService implements GenApiDelegate { + + private static List clients = new ArrayList<>(); + private static List servers = new ArrayList<>(); + private static Map fileMap = new HashMap<>(); + + static { + List extensions = CodegenConfigLoader.getAll(); + for (CodegenConfig config : extensions) { + if (config.getTag().equals(CodegenType.CLIENT) + || config.getTag().equals(CodegenType.DOCUMENTATION)) { + clients.add(config.getName()); + } else if (config.getTag().equals(CodegenType.SERVER)) { + servers.add(config.getName()); + } + } + + clients.sort(String.CASE_INSENSITIVE_ORDER); + servers.sort(String.CASE_INSENSITIVE_ORDER); + } + + private final NativeWebRequest request; + + @Autowired + public GenApiService(NativeWebRequest request) { + this.request = request; + } + + @Override + public Optional getRequest() { + return Optional.ofNullable(request); + } + + @Override + public ResponseEntity downloadFile(String fileId) { + Generated g = fileMap.get(fileId); + System.out.println("looking for fileId " + fileId); + System.out.println("got filename " + g.getFilename()); + + File file = new File(g.getFilename()); + Path path = Paths.get(file.getAbsolutePath()); + ByteArrayResource resource; + try { + resource = new ByteArrayResource(Files.readAllBytes(path)); + } catch (FileNotFoundException e) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "File not found", e); + } catch (IOException e) { + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "I/O error while reading file", e); + } + try { + FileUtils.deleteDirectory(file.getParentFile()); + } catch (IOException e) { + System.out.println("failed to delete file " + file.getAbsolutePath()); + } + return ResponseEntity + .ok() + .contentType(MediaType.valueOf("application/zip")) + .header("Content-Disposition", + "attachment; filename=\"" + g.getFriendlyName() + "-generated.zip\"") + .header("Accept-Range", "bytes") + //.header("Content-Length", bytes.length) + .body(resource); + } + + @Override + public ResponseEntity generateClient(String language, GeneratorInput generatorInput) { + String filename = Generator.generateClient(language, generatorInput); + String host = System.getenv("GENERATOR_HOST"); + HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class); + + if (StringUtils.isBlank(host)) { + String scheme = servletRequest.getHeader("X-SSL"); + String port = ""; + if ("1".equals(scheme)) { + scheme = "https"; + } else { + scheme = servletRequest.getScheme(); + port = ":" + servletRequest.getServerPort(); + } + host = scheme + "://" + servletRequest.getServerName() + port; + } + + if (filename != null) { + String code = String.valueOf(UUID.randomUUID().toString()); + Generated g = new Generated(); + g.setFilename(filename); + g.setFriendlyName(language + "-client"); + fileMap.put(code, g); + System.out.println(code + ", " + filename); + String link = host + "/api/gen/download/" + code; + return ResponseEntity.ok().body(new ResponseCode(code, link)); + } else { + return ResponseEntity.status(500).build(); + } + } + + @Override + public ResponseEntity> getClientOptions(String language) { + Map opts = Generator.getOptions(language); + + if (opts != null) { + return ResponseEntity.ok().body(opts); + } else { + return ResponseEntity.notFound().build(); + } + } + + @Override + public ResponseEntity> getServerOptions(String framework) { + Map opts = Generator.getOptions(framework); + + if (opts != null) { + return ResponseEntity.ok().body(opts); + } else { + return ResponseEntity.notFound().build(); + } + } + + @Override + public ResponseEntity> clientOptions() { + return ResponseEntity.ok().body(clients); + } + + @Override + public ResponseEntity> serverOptions() { + return ResponseEntity.ok().body(servers); + } + + @Override + public ResponseEntity generateServerForLanguage(String framework, GeneratorInput generatorInput) { + if (framework == null) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Framework is required"); + } + String filename = Generator.generateServer(framework, generatorInput); + System.out.println("generated name: " + filename); + + HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class); + + String host = + servletRequest.getScheme() + "://" + servletRequest.getServerName() + ":" + + servletRequest.getServerPort(); + + if (filename != null) { + String code = String.valueOf(UUID.randomUUID().toString()); + Generated g = new Generated(); + g.setFilename(filename); + g.setFriendlyName(framework + "-server"); + fileMap.put(code, g); + System.out.println(code + ", " + filename); + String link = host + "/api/gen/download/" + code; + return ResponseEntity.ok().body(new ResponseCode(code, link)); + } else { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + +} diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/http/Generator.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java similarity index 61% rename from modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/http/Generator.java rename to modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java index 69c0b31b4fe..471134fdfd9 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/http/Generator.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java @@ -1,35 +1,17 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openapitools.codegen.online.http; +package org.openapitools.codegen.online.service; import com.fasterxml.jackson.databind.JsonNode; +import io.swagger.parser.OpenAPIParser; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.parser.core.models.ParseOptions; import org.openapitools.codegen.*; -import org.openapitools.codegen.online.exception.ApiException; -import org.openapitools.codegen.online.exception.BadRequestException; -import org.openapitools.codegen.online.model.GeneratorInput; -import org.openapitools.codegen.online.model.InputOption; -import org.openapitools.codegen.online.util.ZipUtil; -import io.swagger.models.Swagger; -import io.swagger.models.auth.AuthorizationValue; -import io.swagger.parser.SwaggerParser; +import io.swagger.v3.parser.core.models.AuthorizationValue; import io.swagger.util.Json; +import org.openapitools.codegen.online.model.GeneratorInput; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.web.server.ResponseStatusException; import java.io.File; import java.util.ArrayList; @@ -38,14 +20,14 @@ import java.util.List; import java.util.Map; public class Generator { - private static final Logger LOGGER = LoggerFactory.getLogger(Generator.class); + static Logger LOGGER = LoggerFactory.getLogger(Generator.class); - public static Map getOptions(String language) throws ApiException { + public static Map getOptions(String language) { CodegenConfig config = null; try { config = CodegenConfigLoader.forName(language); } catch (Exception e) { - throw new BadRequestException(String.format("Unsupported target %s supplied. %s", + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, String.format("Unsupported target %s supplied. %s", language, e)); } Map map = new LinkedHashMap(); @@ -69,51 +51,49 @@ public class Generator { } } - public static String generateClient(String language, GeneratorInput opts) throws ApiException { + public static String generateClient(String language, GeneratorInput opts) { return generate(language, opts, Type.CLIENT); } - public static String generateServer(String language, GeneratorInput opts) throws ApiException { + public static String generateServer(String language, GeneratorInput opts) { return generate(language, opts, Type.SERVER); } - private static String generate(String language, GeneratorInput opts, Type type) - throws ApiException { + private static String generate(String language, GeneratorInput opts, Type type) { LOGGER.debug(String.format("generate %s for %s", type.getTypeName(), language)); if (opts == null) { - throw new BadRequestException("No options were supplied"); + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "No options were supplied"); } JsonNode node = opts.getSpec(); if (node != null && "{}".equals(node.toString())) { LOGGER.debug("ignoring empty spec"); node = null; } - Swagger swagger; + OpenAPI openapi; + ParseOptions parseOptions = new ParseOptions(); + parseOptions.setResolve(true); if (node == null) { - if (opts.getSwaggerUrl() != null) { + if (opts.getOpenAPIUrl() != null) { if (opts.getAuthorizationValue() != null) { - List authorizationValues = - new ArrayList(); + List authorizationValues = new ArrayList<>(); authorizationValues.add(opts.getAuthorizationValue()); - - swagger = - new SwaggerParser().read(opts.getSwaggerUrl(), authorizationValues, - true); + openapi = new OpenAPIParser().readLocation(opts.getOpenAPIUrl(), authorizationValues, parseOptions).getOpenAPI(); } else { - swagger = new SwaggerParser().read(opts.getSwaggerUrl()); + openapi = new OpenAPIParser().readLocation(opts.getOpenAPIUrl(), null, parseOptions).getOpenAPI(); } } else { - throw new BadRequestException("No OpenAPI specification was supplied"); + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "No OpenAPI specification was supplied"); } } else if (opts.getAuthorizationValue() != null) { List authorizationValues = new ArrayList(); authorizationValues.add(opts.getAuthorizationValue()); - swagger = new SwaggerParser().read(node, authorizationValues, true); + openapi = new OpenAPIParser().readContents(node.toString(), authorizationValues, parseOptions).getOpenAPI(); + } else { - swagger = new SwaggerParser().read(node, true); + openapi = new OpenAPIParser().readContents(node.toString(), null, parseOptions).getOpenAPI(); } - if (swagger == null) { - throw new BadRequestException("The OpenAPI specification supplied was not valid"); + if (openapi == null) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "The OpenAPI specification supplied was not valid"); } String destPath = null; @@ -130,19 +110,18 @@ public class Generator { String outputFolder = getTmpFolder().getAbsolutePath() + File.separator + destPath; String outputFilename = outputFolder + "-bundle.zip"; - // TODO revise below - //clientOptInput.opts(clientOpts).swagger(swagger); + clientOptInput.opts(clientOpts).openAPI(openapi); CodegenConfig codegenConfig = null; try { codegenConfig = CodegenConfigLoader.forName(language); } catch (RuntimeException e) { - throw new BadRequestException("Unsupported target " + language + " supplied"); + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Unsupported target " + language + " supplied"); } if (opts.getOptions() != null) { codegenConfig.additionalProperties().putAll(opts.getOptions()); - codegenConfig.additionalProperties().put("swagger", swagger); + codegenConfig.additionalProperties().put("openAPI", openapi); } codegenConfig.setOutputDir(outputFolder); @@ -160,35 +139,27 @@ public class Generator { ZipUtil zip = new ZipUtil(); zip.compressFiles(filesToAdd, outputFilename); } else { - throw new BadRequestException( + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "A target generation was attempted, but no files were created!"); } for (File file : files) { try { file.delete(); } catch (Exception e) { - LOGGER.error("unable to delete file " + file.getAbsolutePath()); + LOGGER.error("unable to delete file " + file.getAbsolutePath(), e); } } try { new File(outputFolder).delete(); } catch (Exception e) { - LOGGER.error("unable to delete output folder " + outputFolder); + LOGGER.error("unable to delete output folder " + outputFolder, e); } } catch (Exception e) { - throw new BadRequestException("Unable to build target: " + e.getMessage()); + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Unable to build target: " + e.getMessage(), e); } return outputFilename; } - public static InputOption clientOptions(@SuppressWarnings("unused") String language) { - return null; - } - - public static InputOption serverOptions(@SuppressWarnings("unused") String language) { - return null; - } - protected static File getTmpFolder() { try { File outputFolder = File.createTempFile("codegen-", "-tmp"); diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/util/ZipUtil.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/ZipUtil.java similarity index 85% rename from modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/util/ZipUtil.java rename to modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/ZipUtil.java index ab361b974cc..19da305148f 100644 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/util/ZipUtil.java +++ b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/ZipUtil.java @@ -1,21 +1,18 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/** + * Copyright 2016 SmartBear Software + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ -package org.openapitools.codegen.online.util; +package org.openapitools.codegen.online.service; import java.io.BufferedInputStream; import java.io.File; diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/util/ApiOriginFilter.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/util/ApiOriginFilter.java deleted file mode 100644 index 60eec5eb4ab..00000000000 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/util/ApiOriginFilter.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openapitools.codegen.online.util; - -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -public class ApiOriginFilter implements javax.servlet.Filter { - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws IOException, ServletException { - HttpServletResponse res = (HttpServletResponse) response; - res.addHeader("Access-Control-Allow-Origin", "*"); - res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); - res.addHeader("Access-Control-Allow-Headers", "Content-Type"); - chain.doFilter(request, response); - } - - @Override - public void destroy() {} - - @Override - public void init(FilterConfig filterConfig) throws ServletException {} -} diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/util/JacksonJsonProvider.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/util/JacksonJsonProvider.java deleted file mode 100644 index c664587448b..00000000000 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/util/JacksonJsonProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openapitools.codegen.online.util; - - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; -import io.swagger.util.Json; - -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.ext.Provider; - -@Provider -@Produces({MediaType.APPLICATION_JSON}) -public class JacksonJsonProvider extends JacksonJaxbJsonProvider { - private static ObjectMapper commonMapper = Json.mapper(); - - public JacksonJsonProvider() { - super.setMapper(commonMapper); - } -} diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/util/ValidationException.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/util/ValidationException.java deleted file mode 100644 index 4846ada143d..00000000000 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/util/ValidationException.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openapitools.codegen.online.util; - -public class ValidationException extends Exception { - private static final long serialVersionUID = 6861195361018260380L; - private int code; - private String msg; - - public ValidationException(String msg) { - super(msg); - } - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - @Override - public String getMessage() { - return msg; - } - - public void setMessage(String msg) { - this.msg = msg; - } -} diff --git a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/util/ValidationMessage.java b/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/util/ValidationMessage.java deleted file mode 100644 index d88de25e0ec..00000000000 --- a/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/util/ValidationMessage.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * Copyright 2018 SmartBear Software - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openapitools.codegen.online.util; - -public class ValidationMessage { - private String path, message, severity; - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getSeverity() { - return severity; - } - - public void setSeverity(String severity) { - this.severity = severity; - } -} diff --git a/modules/openapi-generator-online/src/main/resources/application.properties b/modules/openapi-generator-online/src/main/resources/application.properties new file mode 100644 index 00000000000..7d8ff54d75d --- /dev/null +++ b/modules/openapi-generator-online/src/main/resources/application.properties @@ -0,0 +1,5 @@ +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 \ No newline at end of file diff --git a/modules/openapi-generator-online/src/main/resources/logback.xml b/modules/openapi-generator-online/src/main/resources/logback.xml deleted file mode 100644 index d57d5e98a80..00000000000 --- a/modules/openapi-generator-online/src/main/resources/logback.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - diff --git a/modules/openapi-generator-online/src/main/resources/version.prop b/modules/openapi-generator-online/src/main/resources/version.prop deleted file mode 100644 index f2ab45c3b0e..00000000000 --- a/modules/openapi-generator-online/src/main/resources/version.prop +++ /dev/null @@ -1 +0,0 @@ -${project.version} \ No newline at end of file diff --git a/modules/openapi-generator-online/src/main/webapp/WEB-INF/web.xml b/modules/openapi-generator-online/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 190c07f4bd5..00000000000 --- a/modules/openapi-generator-online/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - jersey - org.glassfish.jersey.servlet.ServletContainer - - jersey.config.server.provider.packages - - io.swagger.jaxrs.json, - org.openapitools.codegen.online.resource - - - - jersey.config.server.provider.classnames - - io.swagger.online.ExceptionWriter, - org.openapitools.codegen.online.util.JacksonJsonProvider, - io.swagger.jaxrs.listing.ApiListingResource, - io.swagger.jersey.listing.JerseyApiDeclarationProvider, - io.swagger.jersey.listing.JerseyResourceListingProvider - - - - jersey.config.server.wadl.disableWadl - true - - 1 - - - - jersey - /api/* - - - - ApiOriginFilter - org.openapitools.codegen.online.util.ApiOriginFilter - - - Bootstrap - org.openapitools.codegen.online.Bootstrap - - generator.host - localhost:8080 - - - generator.protocol - http - - 2 - - - ApiOriginFilter - /* - - \ No newline at end of file diff --git a/modules/openapi-generator-online/src/main/webapp/index.html b/modules/openapi-generator-online/src/main/webapp/index.html deleted file mode 100644 index 5e7489a0f57..00000000000 --- a/modules/openapi-generator-online/src/main/webapp/index.html +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - Swagger UI - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - \ No newline at end of file