Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions modules/openapi-generator-online/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a ser

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)
The underlying library integrating OpenAPI to SpringBoot is [springdoc](https://github.com/springdoc/springdoc-openapi)

## Building

Expand All @@ -28,13 +28,6 @@ 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:
Expand Down
48 changes: 22 additions & 26 deletions modules/openapi-generator-online/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
<packaging>jar</packaging>
<name>openapi-generator-online</name>
<properties>
<spring-boot.version>2.5.14</spring-boot.version>
<springfox-version>3.0.0</springfox-version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<spring-boot.version>3.5.7</spring-boot.version>
<springdoc-version>2.8.14</springdoc-version>
<sonar.exclusions>**/org/openapitools/codegen/online/**/*</sonar.exclusions>
</properties>
<dependencyManagement>
Expand Down Expand Up @@ -46,13 +48,27 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<parameters>true</parameters>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>${project.parent.basedir}${file.separator}google_checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<junitArtifactName>org.junit.jupiter:junit-jupiter</junitArtifactName>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down Expand Up @@ -101,25 +117,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--SpringFox dependencies -->
<!--SpringDoc dependencies -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version>
<exclusions>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc-version}</version>
</dependency>

<!-- Bean Validation API support -->
Expand All @@ -133,12 +135,6 @@
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("*").allowedHeaders("Content-Type");
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedHeaders("Content-Type");
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package org.openapitools.codegen.online.api;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;


public class ApiOriginFilter implements javax.servlet.Filter {
public class ApiOriginFilter implements jakarta.servlet.Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import org.springframework.web.context.request.NativeWebRequest;

import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ApiUtil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,94 +22,125 @@
*/
package org.openapitools.codegen.online.api;

import io.swagger.annotations.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
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.GetMapping;
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 org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.PostMapping;

import javax.validation.Valid;
import jakarta.validation.Valid;
import java.util.List;
import java.util.Map;

@Api(value = "gen", description = "the gen API")
@Tag(name = "clients", description = "Client generation APIs")
@Tag(name = "servers", description = "Server generation APIs")
public interface GenApi {
GenApiDelegate getDelegate();

@ApiOperation(value = "Gets languages supported by the client generator", nickname = "clientOptions", notes = "", response = String.class, responseContainer = "List", tags = {"clients",})
@Operation(summary = "Gets languages supported by the client generator", operationId = "clientOptions", tags = {"clients"})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class, responseContainer = "List")})
@RequestMapping(value = "/gen/clients",
method = RequestMethod.GET)
@ApiResponse(responseCode = "200", description = "successful operation")})
@GetMapping("/gen/clients")
default ResponseEntity<List<String>> 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 = MultipartFile.class, tags = {"clients", "servers",})
@Operation(summary = "Downloads a pre-generated file", operationId = "downloadFile", description = "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.", tags = {"clients", "servers"})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = MultipartFile.class)})
@RequestMapping(value = "/gen/download/{fileId}",
produces = {"application/octet-stream"},
method = RequestMethod.GET)
default ResponseEntity<Resource> downloadFile(@ApiParam(value = "", required = true) @PathVariable("fileId") String fileId) {
@ApiResponse(responseCode = "200", description = "successful operation")})
@GetMapping(value = "/gen/download/{fileId}",
produces = {"application/octet-stream"})
default ResponseEntity<Resource> downloadFile(@Parameter(description = "", required = true) @PathVariable 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",})
@Operation(summary = "Generates a client library", operationId = "generateClient", description = "Accepts a `GeneratorInput` options map for spec location and generation options", tags = {"clients"})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = ResponseCode.class)})
@RequestMapping(value = "/gen/clients/{language}",
method = RequestMethod.POST)
default ResponseEntity<ResponseCode> generateClient(@ApiParam(value = "The target language for the client library", required = true) @PathVariable("language") String language, @ApiParam(value = "Configuration for building the client library", required = true) @Valid @RequestBody GeneratorInput generatorInput) {
@ApiResponse(responseCode = "200", description = "successful operation")})
@PostMapping(value = "/gen/clients/{language}", consumes = "application/json", produces = "application/json")
default ResponseEntity<ResponseCode> generateClient(
@Parameter(description = "The target language for the client library", required = true, example = "java")
@PathVariable String language,
@RequestBody(description = "Configuration for building the client library", required = true,
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = GeneratorInput.class),
examples = {
@ExampleObject(name = "Basic Example",
summary = "Basic client generation with OpenAPI URL",
value = "{\"openAPIUrl\": \"https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml\", \"options\": {\"packageName\": \"com.example.client\", \"clientPackage\": \"com.example.client\"}}"),
@ExampleObject(name = "With Options",
summary = "Client generation with additional options",
value = "{\"openAPIUrl\": \"https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml\", \"options\": {\"packageName\": \"com.example.petstore\", \"clientPackage\": \"com.example.petstore.client\", \"groupId\": \"com.example\", \"artifactId\": \"petstore-client\", \"artifactVersion\": \"1.0.0\"}}")
}))
@Valid
@org.springframework.web.bind.annotation.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",})
@Operation(summary = "Generates a server library", operationId = "generateServerForLanguage", description = "Accepts a `GeneratorInput` options map for spec location and generation options.", tags = {"servers"})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = ResponseCode.class)})
@RequestMapping(value = "/gen/servers/{framework}",
method = RequestMethod.POST)
default ResponseEntity<ResponseCode> generateServerForLanguage(@ApiParam(value = "framework", required = true) @PathVariable("framework") String framework, @ApiParam(value = "parameters", required = true) @Valid @RequestBody GeneratorInput generatorInput) {
@ApiResponse(responseCode = "200", description = "successful operation")})
@PostMapping(value = "/gen/servers/{framework}", consumes = "application/json", produces = "application/json")
default ResponseEntity<ResponseCode> generateServerForLanguage(
@Parameter(description = "The target server framework", required = true, example = "spring")
@PathVariable String framework,
@RequestBody(description = "Configuration for building the server library", required = true,
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = GeneratorInput.class),
examples = {
@ExampleObject(name = "Basic Example",
summary = "Basic server generation with OpenAPI URL",
value = "{\"openAPIUrl\": \"https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml\", \"options\": {\"packageName\": \"com.example.server\", \"basePackage\": \"com.example.server\"}}"),
@ExampleObject(name = "Spring Boot Server",
summary = "Spring Boot server generation with options",
value = "{\"openAPIUrl\": \"https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml\", \"options\": {\"packageName\": \"com.example.petstore.server\", \"basePackage\": \"com.example.petstore\", \"groupId\": \"com.example\", \"artifactId\": \"petstore-server\", \"artifactVersion\": \"1.0.0\"}}")
}))
@Valid
@org.springframework.web.bind.annotation.RequestBody
GeneratorInput generatorInput) {
return getDelegate().generateServerForLanguage(framework, generatorInput);
}


@ApiOperation(value = "Returns options for a client library", nickname = "getClientOptions", notes = "", tags = {"clients",})
@Operation(summary = "Returns options for a client library", operationId = "getClientOptions", tags = {"clients"})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation")})
@RequestMapping(value = "/gen/clients/{language}",
produces = {"application/json"},
method = RequestMethod.GET)
default ResponseEntity<Map<String, CliOption>> getClientOptions(@ApiParam(value = "The target language for the client library", required = true) @PathVariable("language") String language) {
@ApiResponse(responseCode = "200", description = "successful operation")})
@GetMapping(value = "/gen/clients/{language}",
produces = {"application/json"})
default ResponseEntity<Map<String, CliOption>> getClientOptions(@Parameter(description = "The target language for the client library", required = true) @PathVariable String language) {
return getDelegate().getClientOptions(language);
}


@ApiOperation(value = "Returns options for a server framework", nickname = "getServerOptions", notes = "", tags = {"servers",})
@Operation(summary = "Returns options for a server framework", operationId = "getServerOptions", tags = {"servers"})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation")})
@RequestMapping(value = "/gen/servers/{framework}",
produces = {"application/json"},
method = RequestMethod.GET)
default ResponseEntity<Map<String, CliOption>> getServerOptions(@ApiParam(value = "The target language for the server framework", required = true) @PathVariable("framework") String framework) {
@ApiResponse(responseCode = "200", description = "successful operation")})
@GetMapping(value = "/gen/servers/{framework}",
produces = {"application/json"})
default ResponseEntity<Map<String, CliOption>> getServerOptions(@Parameter(description = "The target language for the server framework", required = true) @PathVariable 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",})
@Operation(summary = "Gets languages supported by the server generator", operationId = "serverOptions", tags = {"servers"})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = String.class, responseContainer = "List")})
@RequestMapping(value = "/gen/servers",
method = RequestMethod.GET)
@ApiResponse(responseCode = "200", description = "successful operation")})
@GetMapping("/gen/servers")
default ResponseEntity<List<String>> serverOptions() {
return getDelegate().serverOptions();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.openapitools.codegen.online.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

Expand All @@ -27,7 +26,6 @@ public class GenApiController implements GenApi {

private final GenApiDelegate delegate;

@Autowired
public GenApiController(GenApiDelegate delegate) {
this.delegate = delegate;
}
Expand Down
Loading