Skip to content

Commit

Permalink
Lec 47 Добавление swagger в проект
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Radkevich committed Jul 27, 2023
1 parent facf0b6 commit 0ba5030
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<artifactId>liquibase-core</artifactId>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.4</version>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package pl.pingwit.pingwitdemospring.config.swagger;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @author Pavel Radkevich
* @since 27.07.23
*/
@Configuration
public class OpenAPIConfig {

@Bean
public OpenAPI myOpenAPI() {

Contact contact = new Contact();
contact.setEmail("[email protected]");
contact.setName("Pavel Radkevich");
contact.setUrl("https://github.com/RadkevichP/");

License mitLicense = new License().name("MIT License").url("https://choosealicense.com/licenses/mit/");

Info info = new Info()
.title("Pingwit Shop API")
.version("1.0")
.contact(contact)
.description("API for Pingwit Shop System")
.license(mitLicense);

return new OpenAPI().info(info);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pl.pingwit.pingwitdemospring.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
Expand All @@ -12,6 +13,7 @@
* @author Pavel Radkevich
* @since 13.07.23
*/
@Tag(name = "Order management API", description = "API for CRUD operations with orders")
@RestController
@RequestMapping("/orders")
public class OrderController {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pl.pingwit.pingwitdemospring.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -17,8 +19,7 @@
* @author Pavel Radkevich
* @since 22.06.23
*/
// SOLID
// CRUD
@Tag(name = "User management API", description = "API for CRUD operations with users")
@RestController
@RequestMapping("/users")
public class UserController {
Expand All @@ -31,6 +32,7 @@ public UserController(UserService userService) {
this.userService = userService;
}

@Operation(description = "Get user by user id. If user not found 404 status code is returned")
@GetMapping("/{id}")
public UserDTO getById(@PathVariable Integer id) {
return userService.getById(id);
Expand All @@ -47,6 +49,7 @@ public List<UserDTO> getAll() {
return userService.getAllUsers();
}

@Operation(description = "Create a new user. Only user with admin rights can use it")
@PostMapping
public Integer createUser(@RequestBody @Valid UserDTO userToCreate) {
return userService.createUser(userToCreate);
Expand All @@ -63,7 +66,7 @@ public UserDTO update(@PathVariable Integer id, @RequestBody @Valid UserDTO user
}

@PostMapping("/search")
public List<UserDTO> search(@RequestBody UserFilterDTO filter) {
public List<UserDTO> search(@RequestBody UserFilterDTO filter) {
return userService.search(filter);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pl.pingwit.pingwitdemospring.converter;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ spring.liquibase.change-log=classpath:db/changelog.xml

logging.level.org.springframework=ERROR
logging.level.pl.pingwit=DEBUG


springdoc.swagger-ui.path=/pingwit-shop-documentation
springdoc.api-docs.path=/pingwit-shop-api-docs

springdoc.packages-to-scan=pl.pingwit.pingwitdemospring.controller
springdoc.swagger-ui.tryItOutEnabled=false

0 comments on commit 0ba5030

Please sign in to comment.