From 45da167f8e2c3b48b99579c55bc0b1c802d5035a Mon Sep 17 00:00:00 2001 From: Jim Schubert Date: Sat, 6 Jul 2019 17:18:34 -0400 Subject: [PATCH] [online] Revert GENERATOR_HOST explicit setting (#3287) --- modules/openapi-generator-online/Dockerfile | 7 +-- modules/openapi-generator-online/README.md | 47 +++++++++++++++++-- .../OpenAPIDocumentationConfig.java | 12 ----- 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/modules/openapi-generator-online/Dockerfile b/modules/openapi-generator-online/Dockerfile index 59cc58135550..71e238dbb5e6 100644 --- a/modules/openapi-generator-online/Dockerfile +++ b/modules/openapi-generator-online/Dockerfile @@ -4,9 +4,10 @@ WORKDIR /generator COPY target/openapi-generator-online.jar /generator/openapi-generator-online.jar -ENV GENERATOR_HOST=http://localhost +# GENERATOR_HOST can be used to determine the target location of a download link. +# The default value asumes binding to host via: docker -p 8080:8080 image_name +ENV GENERATOR_HOST=http://localhost:8080 EXPOSE 8080 -CMD ["java", "-jar", "/generator/openapi-generator-online.jar"] - +CMD ["java", "-jar", "/generator/openapi-generator-online.jar" ] diff --git a/modules/openapi-generator-online/README.md b/modules/openapi-generator-online/README.md index b6dde7e276c6..b3c5ffc244f1 100644 --- a/modules/openapi-generator-online/README.md +++ b/modules/openapi-generator-online/README.md @@ -1,15 +1,54 @@ # OpenAPI generated server -Spring Boot Server +A Spring Boot Server application which hosts a client/server generator API. ## 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. +By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub or one of 100+ client packages. + 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 a simple java application +## Building + +Refer to [root README](../../README.md) for build directions. + +## Running + +### Via command line + +Running is as simple as: + +``` +java -jar ./target/openapi-generator-online.jar +``` + +This exposes the API on local port 8080. + +Springfox supports configuration of the "host" value in the output OpenAPI document by setting the `Host` HTTP header in the request. +To set this explicitly, pass the system property `springfox.documentation.swagger.v2.host` with the desired host. For example: + +``` +java -Dspringfox.documentation.swagger.v2.host=example.com:8888 -jar ./target/openapi-generator-online.jar +``` + +### Via Docker + +After building from source, change to this module directory (`cd modules/openapi-generator-online`) and build the docker image: + +``` +docker build -t openapitools/openapi-generator-online:latest . +``` + +Now, run the docker image: + +``` +docker run -d -p 8888:8080 \ + -e GENERATOR_HOST=http://localhost:8888 \ + openapitools/openapi-generator-online +``` -Change default port value in application.properties +The `GENERATOR_HOST` variable is used here to ensure download links generated by the API refer to the proper API location. 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 07e6001fb35b..39fb8bb2a5f2 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 @@ -52,7 +52,6 @@ ApiInfo apiInfo() { String version = properties.getProperty("version", "unknown"); - return new ApiInfoBuilder() .title("OpenAPI Generator Online") .description("This is an online openapi generator server. You can find out more at https://github.com/OpenAPITools/openapi-generator.") @@ -66,18 +65,7 @@ ApiInfo apiInfo() { @Bean public Docket customImplementation(){ - String host; - try { - String baseUrl = System.getenv("GENERATOR_HOST"); - if (baseUrl == null) { - baseUrl = System.getProperty("generator.host", "http://localhost"); - } - host = new URI(baseUrl).getHost(); - } catch (URISyntaxException e) { - host = ""; - } return new Docket(DocumentationType.SWAGGER_2) - .host(host) .select() .apis(RequestHandlerSelectors.basePackage("org.openapitools.codegen.online.api")) .build()