Skip to content

Commit 739d41e

Browse files
committed
Update swagger
1 parent e90c826 commit 739d41e

File tree

5 files changed

+55
-14
lines changed

5 files changed

+55
-14
lines changed

src/main/java/com/github/throyer/common/springboot/controllers/api/ApiController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.github.throyer.common.springboot.utils.Hello;
44

5+
import io.swagger.v3.oas.annotations.Operation;
56
import org.springframework.web.bind.annotation.GetMapping;
67
import org.springframework.web.bind.annotation.RequestMapping;
78
import org.springframework.web.bind.annotation.RestController;
@@ -11,6 +12,7 @@
1112
public class ApiController {
1213

1314
@GetMapping
15+
@Operation(hidden = true)
1416
public Hello index() {
1517
return () -> "Is a live!";
1618
}

src/main/java/com/github/throyer/common/springboot/controllers/api/RecoveriesController.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import com.github.throyer.common.springboot.domain.recovery.model.RecoveryRequest;
1010
import com.github.throyer.common.springboot.domain.recovery.model.RecoveryUpdate;
1111

12+
import io.swagger.v3.oas.annotations.Operation;
13+
import io.swagger.v3.oas.annotations.tags.Tag;
1214
import org.springframework.beans.factory.annotation.Autowired;
1315
import org.springframework.web.bind.annotation.PostMapping;
1416
import org.springframework.web.bind.annotation.RequestBody;
@@ -17,31 +19,45 @@
1719
import org.springframework.web.bind.annotation.RestController;
1820

1921
@RestController
22+
@Tag(name = "Password recovery")
2023
@RequestMapping("/api/recoveries")
2124
public class RecoveriesController {
2225

26+
private final RecoveryService recoveryService;
27+
private final RecoveryConfirmService confirmService;
28+
private final RecoveryUpdateService updateService;
29+
2330
@Autowired
24-
private RecoveryService recoveryService;
25-
26-
@Autowired
27-
private RecoveryConfirmService confirmService;
28-
29-
@Autowired
30-
private RecoveryUpdateService updateService;
31+
public RecoveriesController(
32+
RecoveryService recoveryService,
33+
RecoveryConfirmService confirmService,
34+
RecoveryUpdateService updateService
35+
) {
36+
this.recoveryService = recoveryService;
37+
this.confirmService = confirmService;
38+
this.updateService = updateService;
39+
}
3140

3241
@PostMapping
3342
@ResponseStatus(NO_CONTENT)
34-
public void index(@RequestBody RecoveryRequest request) {
43+
@Operation(
44+
summary = "Starts recovery password process",
45+
description = "Sends a email to user with recovery code"
46+
)
47+
public void recovery(@RequestBody RecoveryRequest request) {
3548
recoveryService.recovery(request.getEmail());
3649
}
3750

3851
@PostMapping("/confirm")
39-
public void confirm(@RequestBody RecoveryConfirm confirm) {
52+
@ResponseStatus(NO_CONTENT)
53+
@Operation(summary = "Confirm recovery code")
54+
public void confirm(@RequestBody RecoveryConfirm confirm) {
4055
confirmService.confirm(confirm.getEmail(), confirm.getCode());
4156
}
4257

4358
@PostMapping("/update")
4459
@ResponseStatus(NO_CONTENT)
60+
@Operation(summary = "Update user password")
4561
public void update(@RequestBody RecoveryUpdate update) {
4662
updateService.update(update.getEmail(), update.getCode(), update.getPassword());
4763
}

src/main/java/com/github/throyer/common/springboot/controllers/api/RolesController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
import com.github.throyer.common.springboot.domain.role.entity.Role;
88
import com.github.throyer.common.springboot.domain.role.repository.RoleRepository;
9+
import io.swagger.v3.oas.annotations.Operation;
910
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
1011

12+
import io.swagger.v3.oas.annotations.tags.Tag;
1113
import org.springframework.beans.factory.annotation.Autowired;
1214
import org.springframework.http.ResponseEntity;
1315
import org.springframework.security.access.prepost.PreAuthorize;
@@ -16,6 +18,7 @@
1618
import org.springframework.web.bind.annotation.RestController;
1719

1820
@RestController
21+
@Tag(name = "Roles")
1922
@RequestMapping("/api/roles")
2023
@SecurityRequirement(name = "token")
2124
@PreAuthorize("hasAnyAuthority('ADM')")
@@ -25,6 +28,7 @@ public class RolesController {
2528
private RoleRepository repository;
2629

2730
@GetMapping
31+
@Operation(summary = "Returns a list of roles")
2832
public ResponseEntity<List<Role>> index() {
2933
return ok(repository.findAll());
3034
}

src/main/java/com/github/throyer/common/springboot/controllers/api/SessionsController.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.github.throyer.common.springboot.domain.session.service.RefreshTokenService;
1111
import static com.github.throyer.common.springboot.utils.Responses.ok;
1212

13+
import io.swagger.v3.oas.annotations.Operation;
14+
import io.swagger.v3.oas.annotations.tags.Tag;
1315
import org.springframework.beans.factory.annotation.Autowired;
1416
import org.springframework.http.ResponseEntity;
1517
import org.springframework.web.bind.annotation.PostMapping;
@@ -18,22 +20,31 @@
1820
import org.springframework.web.bind.annotation.RestController;
1921

2022
@RestController
23+
@Tag(name = "Authentication")
2124
@RequestMapping("/api/sessions")
2225
public class SessionsController {
2326

27+
private final CreateTokenService createService;
28+
private final RefreshTokenService refreshService;
29+
2430
@Autowired
25-
private CreateTokenService createService;
26-
27-
@Autowired
28-
private RefreshTokenService refreshService;
31+
public SessionsController(
32+
CreateTokenService createService,
33+
RefreshTokenService refreshService
34+
) {
35+
this.createService = createService;
36+
this.refreshService = refreshService;
37+
}
2938

3039
@PostMapping
40+
@Operation(summary = "Create a jwt token")
3141
public ResponseEntity<TokenResponse> create(@RequestBody @Valid TokenRequest request) {
3242
var token = createService.create(request);
3343
return ok(token);
3444
}
3545

3646
@PostMapping("/refresh")
47+
@Operation(summary = "Create a new jwt token from refresh code")
3748
public ResponseEntity<RefreshTokenResponse> refresh(@RequestBody @Valid RefreshTokenRequest request) {
3849
var token = refreshService.refresh(request);
3950
return ok(token);

src/main/java/com/github/throyer/common/springboot/controllers/api/UsersController.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
import com.github.throyer.common.springboot.domain.user.service.UpdateUserService;
1717
import com.github.throyer.common.springboot.domain.user.model.UserDetails;
1818

19+
import io.swagger.v3.oas.annotations.Operation;
1920
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
2021

2122
import java.util.Optional;
2223

24+
import io.swagger.v3.oas.annotations.tags.Tag;
2325
import org.springframework.beans.factory.annotation.Autowired;
2426
import org.springframework.http.ResponseEntity;
2527
import org.springframework.security.access.prepost.PreAuthorize;
@@ -35,6 +37,7 @@
3537
import org.springframework.web.bind.annotation.RestController;
3638

3739
@RestController
40+
@Tag(name = "Users")
3841
@RequestMapping("/api/users")
3942
public class UsersController {
4043

@@ -58,10 +61,11 @@ public UsersController(
5861
this.findService = findService;
5962
this.findByIdService = findByIdService;
6063
}
61-
64+
6265
@GetMapping
6366
@SecurityRequirement(name = "token")
6467
@PreAuthorize("hasAnyAuthority('ADM')")
68+
@Operation(summary = "Returns a list of users")
6569
public ResponseEntity<Page<UserDetails>> index(
6670
Optional<Integer> page,
6771
Optional<Integer> size
@@ -73,13 +77,15 @@ public ResponseEntity<Page<UserDetails>> index(
7377
@GetMapping("/{id}")
7478
@SecurityRequirement(name = "token")
7579
@PreAuthorize("hasAnyAuthority('ADM', 'USER')")
80+
@Operation(summary = "Show user info")
7681
public ResponseEntity<UserDetails> show(@PathVariable Long id) {
7782
var user = findByIdService.find(id);
7883
return ok(user);
7984
}
8085

8186
@PostMapping
8287
@ResponseStatus(CREATED)
88+
@Operation(summary = "Register a new user", description = "Returns the new user")
8389
public ResponseEntity<UserDetails> save(
8490
@Validated @RequestBody CreateUserProps props
8591
) {
@@ -91,6 +97,7 @@ public ResponseEntity<UserDetails> save(
9197
@PutMapping("/{id}")
9298
@SecurityRequirement(name = "token")
9399
@PreAuthorize("hasAnyAuthority('ADM', 'USER')")
100+
@Operation(summary = "Update user data")
94101
public ResponseEntity<UserDetails> update(
95102
@PathVariable Long id,
96103
@RequestBody @Validated UpdateUserProps body
@@ -102,6 +109,7 @@ public ResponseEntity<UserDetails> update(
102109
@DeleteMapping("/{id}")
103110
@ResponseStatus(NO_CONTENT)
104111
@SecurityRequirement(name = "token")
112+
@Operation(summary = "Delete user")
105113
public void destroy(@PathVariable Long id) {
106114
removeService.remove(id);
107115
}

0 commit comments

Comments
 (0)