Skip to content

Commit

Permalink
Merge pull request #10 from pavelfomin/feature/spring-boot-2.6
Browse files Browse the repository at this point in the history
spring boot 2.6.3, springfox -> springdoc, swagger v3
  • Loading branch information
pavelfomin committed Jan 26, 2022
2 parents aaf10c4 + 3f4163d commit 13d2bb2
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 81 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Spring boot example with REST and spring data JPA

### Running tests
* Maven: `./mvnw clean test`
* Gradle: `./gradlew clean test`

### Endpoints

Expand Down
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ dependencies {
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-oauth2-resource-server"

implementation "io.springfox:springfox-swagger2:2.5.0"
implementation "io.springfox:springfox-swagger-ui:2.5.0"

implementation 'org.springdoc:springdoc-openapi-ui:1.6.5'
implementation "com.h2database:h2:2.1.210"

testImplementation "org.springframework.boot:spring-boot-starter-test"
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=2.5.9.3
version=2.6.3.0

springBootVersion=2.5.9
springBootVersion=2.6.3
springBootDependencyManagement=1.0.11.RELEASE
15 changes: 5 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

<groupId>com.droidablebee</groupId>
<artifactId>spring-boot-rest-example</artifactId>
<version>2.5.9.3</version>
<version>2.6.3.0</version>
<name>Spring boot example with REST and spring data JPA</name>

<packaging>jar</packaging>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.9</version>
<version>2.6.3</version>
</parent>

<properties>
Expand Down Expand Up @@ -56,14 +56,9 @@

<!-- swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.5.0</version>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.5</version>
</dependency>

<!-- data access -->
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Value("${spring.security.oauth2.resourceserver.jwt.jwk-set-uri}")
private String issuerUri;

@Value("${app.security.ignore:/swagger/**, /swagger-resources/**, /swagger-ui.html, /webjars/**, /v2/api-docs, /actuator/info}")
@Value("${app.security.ignore:/swagger/**, /swagger-resources/**, /swagger-ui/**, /swagger-ui.html, /webjars/**, /v3/api-docs/**, /actuator/info}")
private String[] ignorePatterns;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.droidablebee.springboot.rest.domain.Person;
import com.droidablebee.springboot.rest.service.PersonService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand Down Expand Up @@ -45,13 +45,12 @@ public class PersonEndpoint extends BaseEndpoint {

@PreAuthorize("hasAuthority('SCOPE_" + PERSON_READ_PERMISSION + "')")
@RequestMapping(path = "/v1/persons", method = RequestMethod.GET)
@ApiOperation(
value = "Get all persons",
notes = "Returns first N persons specified by the size parameter with page offset specified by page parameter.",
response = Page.class)
@Operation(
summary = "Get all persons",
description = "Returns first N persons specified by the size parameter with page offset specified by page parameter.")
public Page<Person> getAll(
@ApiParam("The size of the page to be returned") @RequestParam(required = false) Integer size,
@ApiParam("Zero-based page index") @RequestParam(required = false) Integer page) {
@Parameter(description = "The size of the page to be returned") @RequestParam(required = false) Integer size,
@Parameter(description = "Zero-based page index") @RequestParam(required = false) Integer page) {

if (size == null) {
size = DEFAULT_PAGE_SIZE;
Expand All @@ -68,23 +67,21 @@ public Page<Person> getAll(

@PreAuthorize("hasAuthority('SCOPE_" + PERSON_READ_PERMISSION + "')")
@RequestMapping(path = "/v1/person/{id}", method = RequestMethod.GET)
@ApiOperation(
value = "Get person by id",
notes = "Returns person for id specified.",
response = Person.class)
@ApiResponses(value = {@ApiResponse(code = 404, message = "Person not found") })
public ResponseEntity<Person> get(@ApiParam("Person id") @PathVariable("id") Long id) {
@Operation(
summary = "Get person by id",
description = "Returns person for id specified.")
@ApiResponses(value = {@ApiResponse(responseCode = "404", description = "Person not found") })
public ResponseEntity<Person> get(@Parameter(description = "Person id") @PathVariable("id") Long id) {

Person person = personService.findOne(id);
return (person == null ? ResponseEntity.status(HttpStatus.NOT_FOUND) : ResponseEntity.ok()).body(person);
}

@PreAuthorize("hasAuthority('SCOPE_" + PERSON_WRITE_PERMISSION + "')")
@RequestMapping(path = "/v1/person", method = RequestMethod.PUT, consumes = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ApiOperation(
value = "Create new or update existing person",
notes = "Creates new or updates existing person. Returns created/updated person with id.",
response = Person.class)
@Operation(
summary = "Create new or update existing person",
description = "Creates new or updates existing person. Returns created/updated person with id.")
public ResponseEntity<Person> add(
@Valid @RequestBody Person person,
@Valid @Size(max = 40, min = 8, message = "user id size 8-40") @RequestHeader(name = HEADER_USER_ID) String userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,47 @@ public class SwaggerEndpointTest extends BaseEndpointTest {

@Test
public void getApiDocs() throws Exception {

MvcResult result = mockMvc.perform(get("/v2/api-docs"))
.andExpect(status().isOk())
.andExpect(content().contentType(JSON_MEDIA_TYPE))
.andExpect(jsonPath("$.swagger", is("2.0")))
.andExpect(jsonPath("$.info", isA(Object.class)))
.andExpect(jsonPath("$.paths", isA(Object.class)))
.andExpect(jsonPath("$.definitions", isA(Object.class)))
.andReturn()
;

logger.debug("content="+ result.getResponse().getContentAsString());

MvcResult result = mockMvc.perform(get("/v3/api-docs"))
.andExpect(status().isOk())
.andExpect(content().contentType(JSON_MEDIA_TYPE))
.andExpect(jsonPath("$.openapi", is("3.0.1")))
.andExpect(jsonPath("$.info", isA(Object.class)))
.andExpect(jsonPath("$.servers", isA(Object.class)))
.andExpect(jsonPath("$.paths", isA(Object.class)))
.andExpect(jsonPath("$.components", isA(Object.class)))
.andReturn();

logger.debug("content=" + result.getResponse().getContentAsString());
}

@Test
public void getApiDocSwaggerConfig() throws Exception {

mockMvc.perform(get("/v3/api-docs/swagger-config"))
.andExpect(status().isOk())
.andExpect(content().contentType(JSON_MEDIA_TYPE))
.andExpect(jsonPath("$.configUrl", isA(String.class)))
.andExpect(jsonPath("$.oauth2RedirectUrl", isA(String.class)))
.andExpect(jsonPath("$.url", isA(String.class)))
.andExpect(jsonPath("$.validatorUrl", isA(String.class)))
;
}

@Test
public void getSwaggerHtml() throws Exception {

mockMvc.perform(get("/swagger-ui.html"))
.andExpect(status().isOk())
;

mockMvc.perform(get("/swagger-ui.html"))
.andExpect(status().isFound())
;
}

@Test
public void getSwaggerHtmlIndex() throws Exception {

mockMvc.perform(get("/swagger-ui/index.html"))
.andExpect(status().isOk())
;
}

}

0 comments on commit 13d2bb2

Please sign in to comment.