Skip to content

Commit

Permalink
upgrade to spring-boot 2.5.5 and open-api 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Mondejar committed Oct 3, 2021
1 parent 6d1500e commit 0c123a4
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 151 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ open http://localhost:8080/h2-console
API Documentation (Swagger):

```
open http://localhost:8080/v2/api-docs
open http://localhost:8080/v3/api-docs
open http://localhost:8080/swagger-ui.html
```
30 changes: 10 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'org.springframework.boot' version '2.1.9.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'org.springframework.boot' version '2.5.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'jacoco'
}
Expand All @@ -20,27 +20,17 @@ repositories {
}

dependencies {

implementation 'org.springframework.boot:spring-boot-starter-web'

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'mysql:mysql-connector-java'

implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
compile 'org.modelmapper:modelmapper:2.3.5'

compile 'io.springfox:springfox-swagger2:2.9.2'
compile 'io.springfox:springfox-swagger-ui:2.9.2'

//test
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.4.2'

testImplementation 'org.springframework.boot:spring-boot-starter-test'

implementation 'org.springdoc:springdoc-openapi-ui:1.5.10'
runtimeOnly 'mysql:mysql-connector-java'
implementation 'org.modelmapper:modelmapper:2.4.4'
}

test {
Expand Down
84 changes: 30 additions & 54 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.9.RELEASE</version>
<version>2.5.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>example</groupId>
Expand All @@ -15,30 +16,33 @@
<properties>
<java.version>11</java.version>
<start-class>example.Application</start-class>
<springfox.version>2.9.2</springfox.version>
<lombok.version>1.18.4</lombok.version>
<modelmapper.version>2.3.5</modelmapper.version>
<maven.jacoco.version>0.8.5</maven.jacoco.version>
<springdoc-openapi.version>1.5.10</springdoc-openapi.version>
<modelmapper.version>2.4.4</modelmapper.version>
<maven.jacoco.version>0.8.7</maven.jacoco.version>
</properties>

<dependencies>
<!-- spring -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${project.parent.version}</version>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<!-- database -->
Expand All @@ -54,12 +58,6 @@
</dependency>

<!-- common -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
Expand All @@ -68,37 +66,9 @@

<!-- swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox.version}</version>
</dependency>

<!-- testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc-openapi.version}</version>
</dependency>

</dependencies>
Expand All @@ -108,7 +78,14 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${project.parent.version}</version>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
Expand All @@ -129,7 +106,6 @@
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down
26 changes: 0 additions & 26 deletions src/main/java/example/config/SwaggerConfig.java

This file was deleted.

33 changes: 16 additions & 17 deletions src/main/java/example/controller/AuthorResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import example.dto.AuthorDto;
import example.service.AuthorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
Expand All @@ -15,7 +15,6 @@
import javax.validation.Valid;
import java.net.URI;

@Api(value="Author Resource Endpoint")
@RestController
@RequestMapping("/api/v1")
@Slf4j
Expand All @@ -28,13 +27,13 @@ public AuthorResource(AuthorService authorService) {
this.authorService = authorService;
}

@ApiOperation(value = "Creates a new author")
@Operation(summary = "Creates a new author")
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Created"),
@ApiResponse(code = 400, message = "Bad Request"),
@ApiResponse(code = 422, message = "Unprocessable Entity"),
@ApiResponse(code = 500, message = "Internal Server Error")
})
@ApiResponse(responseCode = "201", description = "Created the author"),
@ApiResponse(responseCode = "400", description = "Bad request",
content = @Content),
@ApiResponse(responseCode = "500", description = "Internal Server Error",
content = @Content) })
@PostMapping(path = "/authors", consumes = {"application/json"})
public ResponseEntity<Void> create(@Valid @RequestBody AuthorDto authorData) {

Expand All @@ -47,13 +46,13 @@ public ResponseEntity<Void> create(@Valid @RequestBody AuthorDto authorData) {
return ResponseEntity.created(location).build();
}

@ApiOperation(value = "Removes the requested author")
@Operation(summary = "Removes a requested author")
@ApiResponses(value = {
@ApiResponse(code = 204, message = "No Content"),
@ApiResponse(code = 400, message = "Bad Request"),
@ApiResponse(code = 404, message = "Not Found"),
@ApiResponse(code = 500, message = "Internal Server Error")
})
@ApiResponse(responseCode = "204", description = "No Content"),
@ApiResponse(responseCode = "400", description = "Bad request"),
@ApiResponse(responseCode = "404", description = "Not Found"),
@ApiResponse(responseCode = "500", description = "Internal Server Error",
content = @Content) })
@DeleteMapping(path = "/authors/{id}", produces = {"application/json"})
public ResponseEntity<Void> delete(@PathVariable("id") Long authorId) {

Expand Down
51 changes: 26 additions & 25 deletions src/main/java/example/controller/BookResource.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package example.controller;

import java.net.URI;
import java.util.List;

import javax.validation.Valid;

import example.dto.BookDto;
import example.service.BookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.v3.oas.annotations.*;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

@Api(value="Book Resource Endpoint")
import java.net.URI;
import java.util.List;
import javax.validation.Valid;

@RestController
@RequestMapping("/api/v1")
@Slf4j
Expand All @@ -30,9 +28,11 @@ public BookResource(BookService bookService) {
this.bookService = bookService;
}

@ApiOperation(value = "Gets the list of available books")
@Operation(summary = "Gets the list of available books")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = List.class)
@ApiResponse(responseCode = "200", description = "Found the books",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = List.class)) }),
})
@GetMapping(path = "/books", produces = {"application/json"})
public ResponseEntity<List<BookDto>> list() {
Expand All @@ -41,28 +41,29 @@ public ResponseEntity<List<BookDto>> list() {
return ResponseEntity.ok(bookService.list());
}

@ApiOperation(value = "Retrieves the requested book")
@Operation(summary = "Get a book by its id")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = BookDto.class),
@ApiResponse(code = 400, message = "Bbook Request"),
@ApiResponse(code = 404, message = "Not Found"),
@ApiResponse(code = 422, message = "Unprocessable Entity"),
@ApiResponse(code = 500, message = "Internal Server Error")
})
@ApiResponse(responseCode = "200", description = "Found the book",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = BookDto.class)) }),
@ApiResponse(responseCode = "400", description = "Invalid id supplied",
content = @Content),
@ApiResponse(responseCode = "404", description = "Book not found",
content = @Content) })
@GetMapping(path = "/books/{id}", produces = {"application/json"})
public ResponseEntity<BookDto> get(@PathVariable("id") Long bookId) {

log.info("GET /api/v1/books/"+bookId);
return ResponseEntity.ok(bookService.get(bookId));
}

@ApiOperation(value = "Creates a new book")
@Operation(summary = "Creates a new book")
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Created"),
@ApiResponse(code = 400, message = "Bbook Request"),
@ApiResponse(code = 422, message = "Unprocessable Entity"),
@ApiResponse(code = 500, message = "Internal Server Error")
})
@ApiResponse(responseCode = "201", description = "Created the book"),
@ApiResponse(responseCode = "400", description = "Bad request",
content = @Content),
@ApiResponse(responseCode = "500", description = "Internal Server Error",
content = @Content) })
@PostMapping(path = "/books", consumes = {"application/json"})
public ResponseEntity<Void> create(@Valid @RequestBody BookDto bookDto) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import javax.validation.ConstraintViolationException;

import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
Expand All @@ -18,6 +17,7 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.validation.ConstraintViolationException;

@Slf4j
@ControllerAdvice
Expand Down

0 comments on commit 0c123a4

Please sign in to comment.