Add Swagger documentation
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -16,6 +16,7 @@
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<modelmapper.version>3.1.1</modelmapper.version>
|
||||
<springdoc-openapi.version>2.1.0</springdoc-openapi.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -39,6 +40,11 @@
|
||||
<artifactId>modelmapper</artifactId>
|
||||
<version>${modelmapper.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||
<version>${springdoc-openapi.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.kapcake.bankingservice.controllers;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.validation.Valid;
|
||||
@@ -27,6 +29,8 @@ public class AuthController {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@SecurityRequirement(name = "basic")
|
||||
@Operation(summary = "Login using basic authentication to get a session cookie")
|
||||
@PostMapping("/login")
|
||||
public void login(HttpServletRequest request) {
|
||||
Authentication auth = (Authentication) request.getUserPrincipal();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.kapcake.bankingservice.controllers;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import jakarta.validation.Valid;
|
||||
import net.kapcake.bankingservice.exceptions.ValidationException;
|
||||
import net.kapcake.bankingservice.model.dtos.BankAccountDTO;
|
||||
@@ -43,7 +44,10 @@ public class BankingServiceController {
|
||||
}
|
||||
|
||||
@GetMapping("/payments")
|
||||
public List<PaymentDTO> getPayments(@AuthenticationPrincipal UserDetailsImpl authenticatedUser, @RequestBody(required = false) @Valid PaymentFilter paymentFilter, BindingResult bindingResult) {
|
||||
public List<PaymentDTO> getPayments(@AuthenticationPrincipal UserDetailsImpl authenticatedUser,
|
||||
@Parameter(description = "Filter to be applied")
|
||||
@RequestBody(required = false) @Valid PaymentFilter paymentFilter,
|
||||
BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
String errorString = getErrorString(bindingResult);
|
||||
throw new ValidationException("Payment filter is invalid: " + errorString);
|
||||
|
||||
Reference in New Issue
Block a user