BAEL-5032 Swagger to PDF
This commit is contained in:
parent
679df8513e
commit
99cc4be41e
@ -25,6 +25,21 @@
|
|||||||
<artifactId>springfox-boot-starter</artifactId>
|
<artifactId>springfox-boot-starter</artifactId>
|
||||||
<version>${springfox.version}</version>
|
<version>${springfox.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-swagger2</artifactId>
|
||||||
|
<version>${springfox-swagger2.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.swagger.core.v3</groupId>
|
||||||
|
<artifactId>swagger-jaxrs2</artifactId>
|
||||||
|
<version>${swagger-jaxrs2.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.ws.rs</groupId>
|
||||||
|
<artifactId>javax.ws.rs-api</artifactId>
|
||||||
|
<version>${javax.ws.rs-api.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -33,11 +48,103 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.github.kongchen</groupId>
|
||||||
|
<artifactId>swagger-maven-plugin</artifactId>
|
||||||
|
<version>3.1.3</version>
|
||||||
|
<configuration>
|
||||||
|
<apiSources>
|
||||||
|
<apiSource>
|
||||||
|
<springmvc>false</springmvc>
|
||||||
|
<locations>com.baeldung.swagger2pdf.controller.UserController</locations>
|
||||||
|
<basePath>/api</basePath>
|
||||||
|
<info>
|
||||||
|
<title>DEMO REST API</title>
|
||||||
|
<description>A simple DEMO project for REST API documentation</description>
|
||||||
|
<version>v1</version>
|
||||||
|
</info>
|
||||||
|
<swaggerDirectory>${project.build.directory}/api</swaggerDirectory>
|
||||||
|
<attachSwaggerArtifact>true</attachSwaggerArtifact>
|
||||||
|
</apiSource>
|
||||||
|
</apiSources>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>generate</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>io.github.robwin</groupId>
|
||||||
|
<artifactId>swagger2markup-maven-plugin</artifactId>
|
||||||
|
<version>0.9.3</version>
|
||||||
|
<configuration>
|
||||||
|
<inputDirectory>${project.build.directory}/api</inputDirectory>
|
||||||
|
<outputDirectory>${generated.asciidoc.directory}</outputDirectory>
|
||||||
|
<markupLanguage>asciidoc</markupLanguage>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>process-swagger</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.asciidoctor</groupId>
|
||||||
|
<artifactId>asciidoctor-maven-plugin</artifactId>
|
||||||
|
<version>2.2.1</version>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.asciidoctor</groupId>
|
||||||
|
<artifactId>asciidoctorj-pdf</artifactId>
|
||||||
|
<version>1.6.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<configuration>
|
||||||
|
<sourceDirectory>${project.build.outputDirectory}/../asciidoc</sourceDirectory>
|
||||||
|
<sourceDocumentName>overview.adoc</sourceDocumentName>
|
||||||
|
<attributes>
|
||||||
|
<doctype>book</doctype>
|
||||||
|
<toc>left</toc>
|
||||||
|
<toclevels>2</toclevels>
|
||||||
|
<generated>${generated.asciidoc.directory}</generated>
|
||||||
|
</attributes>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
|
||||||
|
<id>asciidoc-to-pdf</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>process-asciidoc</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<backend>pdf</backend>
|
||||||
|
<outputDirectory>${project.build.outputDirectory}/api/pdf</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<springfox.version>3.0.0</springfox.version>
|
<springfox.version>3.0.0</springfox.version>
|
||||||
|
<generated.asciidoc.directory>${project.build.outputDirectory}/asciidoc</generated.asciidoc.directory>
|
||||||
|
<springfox-swagger2.version>2.10.5</springfox-swagger2.version>
|
||||||
|
<swagger-jaxrs2.version>2.1.11</swagger-jaxrs2.version>
|
||||||
|
<javax.ws.rs-api.version>2.1</javax.ws.rs-api.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -0,0 +1,63 @@
|
|||||||
|
package com.baeldung.swagger2pdf.controller;
|
||||||
|
|
||||||
|
import com.baeldung.swagger2pdf.objects.User;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@Api(value = "/api", description = "A controller for user management")
|
||||||
|
@RequestMapping("/user")
|
||||||
|
@ResponseStatus(HttpStatus.OK)
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
static List<User> users;
|
||||||
|
|
||||||
|
static {
|
||||||
|
users = new ArrayList<>();
|
||||||
|
users.add(new User("Mark", "Thompson", 23));
|
||||||
|
users.add(new User("Kate", "Jordan", 22));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "Retrieves all the users")
|
||||||
|
@RequestMapping(value = "/users",
|
||||||
|
method = RequestMethod.GET,
|
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
public List<User> getUsers() {
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "Retrieves a user based on first name")
|
||||||
|
@RequestMapping(value = "/user",
|
||||||
|
method = RequestMethod.GET,
|
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
public User getUser(@NonNull @RequestParam String firstName) {
|
||||||
|
|
||||||
|
if (firstName.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return users.stream()
|
||||||
|
.filter(user -> user.getFirstName().equals(firstName))
|
||||||
|
.findAny()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "Adds a user.")
|
||||||
|
@RequestMapping(value = "/user",
|
||||||
|
method = RequestMethod.POST,
|
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
public List<User> addUser(@NonNull @RequestBody User user) {
|
||||||
|
users.add(user);
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.baeldung.swagger2pdf.objects;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class User {
|
||||||
|
private String firstName;
|
||||||
|
private String lastName;
|
||||||
|
private int age;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user