Skip to content

Commit 45da167

Browse files
authored
[online] Revert GENERATOR_HOST explicit setting (#3287)
1 parent 109808e commit 45da167

3 files changed

Lines changed: 47 additions & 19 deletions

File tree

modules/openapi-generator-online/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ WORKDIR /generator
44

55
COPY target/openapi-generator-online.jar /generator/openapi-generator-online.jar
66

7-
ENV GENERATOR_HOST=http://localhost
7+
# GENERATOR_HOST can be used to determine the target location of a download link.
8+
# The default value asumes binding to host via: docker -p 8080:8080 image_name
9+
ENV GENERATOR_HOST=http://localhost:8080
810

911
EXPOSE 8080
1012

11-
CMD ["java", "-jar", "/generator/openapi-generator-online.jar"]
12-
13+
CMD ["java", "-jar", "/generator/openapi-generator-online.jar" ]
Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,54 @@
11
# OpenAPI generated server
22

3-
Spring Boot Server
3+
A Spring Boot Server application which hosts a client/server generator API.
44

55

66
## Overview
7+
78
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
8-
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub.
9+
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub or one of 100+ client packages.
10+
911
This is an example of building a OpenAPI-enabled server in Java using the SpringBoot framework.
1012

1113
The underlying library integrating OpenAPI to SpringBoot is [springfox](https://github.com/springfox/springfox)
1214

13-
Start your server as a simple java application
15+
## Building
16+
17+
Refer to [root README](../../README.md) for build directions.
18+
19+
## Running
20+
21+
### Via command line
22+
23+
Running is as simple as:
24+
25+
```
26+
java -jar ./target/openapi-generator-online.jar
27+
```
28+
29+
This exposes the API on local port 8080.
30+
31+
Springfox supports configuration of the "host" value in the output OpenAPI document by setting the `Host` HTTP header in the request.
32+
To set this explicitly, pass the system property `springfox.documentation.swagger.v2.host` with the desired host. For example:
33+
34+
```
35+
java -Dspringfox.documentation.swagger.v2.host=example.com:8888 -jar ./target/openapi-generator-online.jar
36+
```
37+
38+
### Via Docker
39+
40+
After building from source, change to this module directory (`cd modules/openapi-generator-online`) and build the docker image:
41+
42+
```
43+
docker build -t openapitools/openapi-generator-online:latest .
44+
```
45+
46+
Now, run the docker image:
47+
48+
```
49+
docker run -d -p 8888:8080 \
50+
-e GENERATOR_HOST=http://localhost:8888 \
51+
openapitools/openapi-generator-online
52+
```
1453

15-
Change default port value in application.properties
54+
The `GENERATOR_HOST` variable is used here to ensure download links generated by the API refer to the proper API location.

modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/configuration/OpenAPIDocumentationConfig.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ ApiInfo apiInfo() {
5252

5353
String version = properties.getProperty("version", "unknown");
5454

55-
5655
return new ApiInfoBuilder()
5756
.title("OpenAPI Generator Online")
5857
.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() {
6665

6766
@Bean
6867
public Docket customImplementation(){
69-
String host;
70-
try {
71-
String baseUrl = System.getenv("GENERATOR_HOST");
72-
if (baseUrl == null) {
73-
baseUrl = System.getProperty("generator.host", "http://localhost");
74-
}
75-
host = new URI(baseUrl).getHost();
76-
} catch (URISyntaxException e) {
77-
host = "";
78-
}
7968
return new Docket(DocumentationType.SWAGGER_2)
80-
.host(host)
8169
.select()
8270
.apis(RequestHandlerSelectors.basePackage("org.openapitools.codegen.online.api"))
8371
.build()

0 commit comments

Comments
 (0)