Skip to content

Commit

Permalink
[OpenAPI] Set tags for every operation
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarciani committed Nov 30, 2024
1 parent 814030d commit 0cbb336
Show file tree
Hide file tree
Showing 23 changed files with 88 additions and 22 deletions.
3 changes: 3 additions & 0 deletions server/src/main/kotlin/com/yawa/server/api/admin/SendMail.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.yawa.server.api.admin

import com.yawa.server.constants.OpenApiTags.ADMINISTRATION
import com.yawa.server.models.users.User
import com.yawa.server.notifications.MailService
import com.yawa.server.notifications.MailType
import io.swagger.v3.oas.annotations.Operation
import jakarta.validation.Valid
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -19,6 +21,7 @@ class SendMail(
@Autowired val mailService: MailService,
) {

@Operation(tags = [ADMINISTRATION])
@PostMapping("/admin/mail", produces = [MediaType.APPLICATION_JSON_VALUE])
fun sendMail(
@Valid @RequestBody request: SendMailRequest,
Expand Down
3 changes: 3 additions & 0 deletions server/src/main/kotlin/com/yawa/server/api/auth/Login.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.yawa.server.api.auth

import com.yawa.server.constants.OpenApiTags.AUTHENTICATION
import com.yawa.server.security.authentication.AuthenticationService
import com.yawa.server.validators.Password
import com.yawa.server.validators.Username
import io.swagger.v3.oas.annotations.Operation
import jakarta.validation.Valid
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -19,6 +21,7 @@ class Login(
@Autowired val authenticationService: AuthenticationService,
) {

@Operation(tags = [AUTHENTICATION])
@PostMapping("/auth/login", produces = [MediaType.APPLICATION_JSON_VALUE])
fun login(
@Valid @RequestBody request: LoginRequest,
Expand Down
3 changes: 3 additions & 0 deletions server/src/main/kotlin/com/yawa/server/api/auth/Logout.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.yawa.server.api.auth

import com.yawa.server.constants.OpenApiTags.AUTHENTICATION
import com.yawa.server.models.users.User
import io.swagger.v3.oas.annotations.Operation
import mu.KotlinLogging
import org.springframework.http.MediaType
import org.springframework.security.core.context.SecurityContextHolder
Expand All @@ -12,6 +14,7 @@ private val log = KotlinLogging.logger {}
@RestController
class Logout {

@Operation(tags = [AUTHENTICATION])
@PostMapping("/auth/logout", produces = [MediaType.APPLICATION_JSON_VALUE])
fun logout(): LogoutResponse {
log.info("Processing request")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.yawa.server.api.auth

import com.yawa.server.constants.OpenApiTags.AUTHENTICATION
import com.yawa.server.security.authentication.AuthenticationService
import io.swagger.v3.oas.annotations.Operation
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
Expand All @@ -17,6 +19,7 @@ class RefreshAuthentication(
@Autowired val authenticationService: AuthenticationService,
) {

@Operation(tags = [AUTHENTICATION])
@GetMapping("/auth/{username}/tokens", produces = [MediaType.APPLICATION_JSON_VALUE])
fun refreshAuthentication(
@PathVariable username: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.yawa.server.api.simple

import com.yawa.server.constants.OpenApiTags.SIMPLE
import com.yawa.server.models.users.User
import io.swagger.v3.oas.annotations.Operation
import mu.KotlinLogging
import org.springframework.http.MediaType
import org.springframework.security.authentication.AnonymousAuthenticationToken
Expand All @@ -13,6 +15,7 @@ private val log = KotlinLogging.logger {}
@RestController
class GetGreetings {

@Operation(tags = [SIMPLE])
@GetMapping("/simple/greetings", produces = [MediaType.APPLICATION_JSON_VALUE])
fun getGreetings(): GetAuthenticatedHelloResponse {
log.info("Processing request")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.yawa.server.api.simple

import com.yawa.server.constants.OpenApiTags.SIMPLE
import com.yawa.server.exceptions.NotAuthorizedException
import com.yawa.server.exceptions.ResourceNotFoundException
import com.yawa.server.exceptions.YawaBadRequestException
import com.yawa.server.exceptions.YawaInternalException
import io.swagger.v3.oas.annotations.Operation
import mu.KotlinLogging
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.GetMapping
Expand All @@ -16,6 +18,7 @@ private val log = KotlinLogging.logger {}
@RestController
class GetOutcome {

@Operation(tags = [SIMPLE])
@GetMapping("/simple/outcome", produces = [MediaType.APPLICATION_JSON_VALUE])
fun getOutcome(
@RequestParam outcome: Outcome,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.yawa.server.api.users.creation

import com.yawa.server.constants.OpenApiTags.USERS
import com.yawa.server.models.tokens.TokenAction
import com.yawa.server.notifications.MailService
import com.yawa.server.notifications.MailType
import com.yawa.server.security.tokens.ActionTokenService
import com.yawa.server.services.UserService
import io.swagger.v3.oas.annotations.Operation
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
Expand All @@ -22,6 +24,7 @@ class ActivateUser(
@Autowired val mailService: MailService,
) {

@Operation(tags = [USERS])
@PostMapping("/users/{username}/activation", produces = [MediaType.APPLICATION_JSON_VALUE])
fun activateUser(
@PathVariable username: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yawa.server.api.users.creation

import com.yawa.server.constants.OpenApiTags.USERS
import com.yawa.server.datastore.repositories.UserRepository
import com.yawa.server.exceptions.DuplicatedResourceException
import com.yawa.server.models.tokens.TokenAction
Expand All @@ -11,6 +12,7 @@ import com.yawa.server.services.UserService
import com.yawa.server.validators.Email
import com.yawa.server.validators.Password
import com.yawa.server.validators.Username
import io.swagger.v3.oas.annotations.Operation
import jakarta.validation.Valid
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -30,6 +32,7 @@ class CreateUser(
@Autowired val mailService: MailService,
) {

@Operation(tags = [USERS])
@PostMapping("/users", produces = [MediaType.APPLICATION_JSON_VALUE])
fun createUser(
@Valid @RequestBody request: CreateUserRequest,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.yawa.server.api.users.creation

import com.yawa.server.constants.OpenApiTags.USERS
import com.yawa.server.exceptions.UserAlreadyEnabledException
import com.yawa.server.models.tokens.TokenAction
import com.yawa.server.notifications.MailService
import com.yawa.server.notifications.MailType
import com.yawa.server.security.tokens.ActionTokenService
import com.yawa.server.services.UserService
import io.swagger.v3.oas.annotations.Operation
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
Expand All @@ -23,6 +25,7 @@ class SendUserActivationToken(
@Autowired val mailService: MailService,
) {

@Operation(tags = [USERS])
@GetMapping("/users/{username}/tokens/activation", produces = [MediaType.APPLICATION_JSON_VALUE])
@PreAuthorize("authentication.principal.username == #username || hasRole('ROLE_ADMIN')")
fun sendUserActivationToken(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.yawa.server.api.users.deletion

import com.yawa.server.constants.OpenApiTags.USERS
import com.yawa.server.models.tokens.TokenAction
import com.yawa.server.notifications.MailService
import com.yawa.server.notifications.MailType
import com.yawa.server.security.tokens.ActionTokenService
import com.yawa.server.services.UserService
import io.swagger.v3.oas.annotations.Operation
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
Expand All @@ -23,6 +25,7 @@ class DeleteUser(
@Autowired val mailService: MailService,
) {

@Operation(tags = [USERS])
@DeleteMapping("/users/{username}", produces = [MediaType.APPLICATION_JSON_VALUE])
@PreAuthorize("authentication.principal.username == #username || hasRole('ROLE_ADMIN')")
fun deleteUser(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.yawa.server.api.users.deletion

import com.yawa.server.constants.OpenApiTags.USERS
import com.yawa.server.models.tokens.TokenAction
import com.yawa.server.notifications.MailService
import com.yawa.server.notifications.MailType
import com.yawa.server.security.tokens.ActionTokenService
import com.yawa.server.services.UserService
import io.swagger.v3.oas.annotations.Operation
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
Expand All @@ -22,6 +24,7 @@ class SendUserDeletionToken(
@Autowired val mailService: MailService,
) {

@Operation(tags = [USERS])
@GetMapping("/users/{username}/tokens/deletion", produces = [MediaType.APPLICATION_JSON_VALUE])
@PreAuthorize("authentication.principal.username == #username || hasRole('ROLE_ADMIN')")
fun sendUserDeletionToken(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.yawa.server.api.users.password

import com.yawa.server.constants.OpenApiTags.USERS
import com.yawa.server.models.tokens.TokenAction
import com.yawa.server.notifications.MailService
import com.yawa.server.notifications.MailType
import com.yawa.server.security.tokens.ActionTokenService
import com.yawa.server.services.UserService
import io.swagger.v3.oas.annotations.Operation
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
Expand All @@ -22,6 +24,7 @@ class ResetPassword(
@Autowired val mailService: MailService,
) {

@Operation(tags = [USERS])
@PatchMapping("/users/{username}/password", produces = [MediaType.APPLICATION_JSON_VALUE])
fun resetPassword(
@PathVariable username: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.yawa.server.api.users.password

import com.yawa.server.constants.OpenApiTags.USERS
import com.yawa.server.models.tokens.TokenAction
import com.yawa.server.notifications.MailService
import com.yawa.server.notifications.MailType
import com.yawa.server.security.tokens.ActionTokenService
import com.yawa.server.services.UserService
import io.swagger.v3.oas.annotations.Operation
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
Expand All @@ -21,6 +23,7 @@ class SendPasswordResetToken(
@Autowired val mailService: MailService,
) {

@Operation(tags = [USERS])
@GetMapping("/users/{username}/tokens/password", produces = [MediaType.APPLICATION_JSON_VALUE])
fun sendPasswordResetToken(
@PathVariable username: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.yawa.server.api.users.profile

import com.yawa.server.constants.OpenApiTags.USERS
import com.yawa.server.datastore.repositories.UserRepository
import com.yawa.server.exceptions.ResourceNotFoundException
import com.yawa.server.models.users.UserProfile
import io.swagger.v3.oas.annotations.Operation
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
Expand All @@ -17,6 +19,7 @@ class GetUserProfile(
@Autowired val userRepository: UserRepository,
) {

@Operation(tags = [USERS])
@GetMapping("/users/{username}/profile", produces = [MediaType.APPLICATION_JSON_VALUE])
fun getUserProfile(
@PathVariable username: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.yawa.server.api.users.profile

import com.yawa.server.constants.OpenApiTags.USERS
import com.yawa.server.datastore.repositories.UserProfileRepository
import com.yawa.server.datastore.repositories.UserRepository
import com.yawa.server.exceptions.ResourceNotFoundException
import com.yawa.server.models.users.Gender
import com.yawa.server.models.users.UserProfile
import io.swagger.v3.oas.annotations.Operation
import jakarta.validation.Valid
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -24,6 +26,7 @@ class UpdateUserProfile(
@Autowired val userProfileRepository: UserProfileRepository,
) {

@Operation(tags = [USERS])
@PatchMapping("/users/{username}/profile", produces = [MediaType.APPLICATION_JSON_VALUE])
@PreAuthorize("authentication.principal.username == #username || hasRole('ROLE_ADMIN')")
fun updateUserProfile(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.yawa.server.api.users.profile.picture

import com.yawa.server.constants.OpenApiTags.USERS
import com.yawa.server.services.UserService
import io.swagger.v3.oas.annotations.Operation
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
Expand All @@ -16,6 +18,7 @@ class DeleteUserPicture(
@Autowired val userService: UserService,
) {

@Operation(tags = [USERS])
@DeleteMapping("/users/{username}/profile/picture", produces = [MediaType.APPLICATION_JSON_VALUE])
@PreAuthorize("authentication.principal.username == #username || hasRole('ROLE_ADMIN')")
fun deleteUserPicture(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.yawa.server.api.users.profile.picture

import com.yawa.server.constants.OpenApiTags.USERS
import com.yawa.server.services.UserService
import io.swagger.v3.oas.annotations.Operation
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
Expand All @@ -18,6 +20,7 @@ class UpdateUserPicture(
@Autowired val userService: UserService,
) {

@Operation(tags = [USERS])
@PatchMapping("/users/{username}/profile/picture", produces = [MediaType.APPLICATION_JSON_VALUE])
@PreAuthorize("authentication.principal.username == #username || hasRole('ROLE_ADMIN')")
fun updateUserPicture(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.yawa.server.api.users.settings

import com.yawa.server.constants.OpenApiTags.USERS
import com.yawa.server.datastore.repositories.UserRepository
import com.yawa.server.exceptions.ResourceNotFoundException
import com.yawa.server.models.users.UserSettings
import io.swagger.v3.oas.annotations.Operation
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
Expand All @@ -18,6 +20,7 @@ class GetUserSettings(
@Autowired val userRepository: UserRepository,
) {

@Operation(tags = [USERS])
@GetMapping("/users/{username}/settings", produces = [MediaType.APPLICATION_JSON_VALUE])
@PreAuthorize("authentication.principal.username == #username || hasRole('ROLE_ADMIN')")
fun getUserSettings(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.yawa.server.api.users.settings

import com.yawa.server.constants.OpenApiTags.USERS
import com.yawa.server.datastore.repositories.UserRepository
import com.yawa.server.datastore.repositories.UserSettingsRepository
import com.yawa.server.exceptions.ResourceNotFoundException
import com.yawa.server.models.users.UserSettings
import io.swagger.v3.oas.annotations.Operation
import jakarta.validation.Valid
import mu.KotlinLogging
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -22,6 +24,7 @@ class UpdateUserSettings(
@Autowired val userSettingsRepository: UserSettingsRepository,
) {

@Operation(tags = [USERS])
@PatchMapping("/users/{username}/settings", produces = [MediaType.APPLICATION_JSON_VALUE])
@PreAuthorize("authentication.principal.username == #username || hasRole('ROLE_ADMIN')")
fun updateUserSettings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class OpenApiConfig {
Operation()
.summary("Actuator web endpoint 'docs/openapi'")
.operationId("openapi")
.tags(listOf("Actuator"))
.tags(listOf("Documentation"))
.responses(
ApiResponses().addApiResponse(
"200",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.yawa.server.constants

object OpenApiTags {
const val ADMINISTRATION = "Administration"
const val AUTHENTICATION = "Authentication"
const val SIMPLE = "Simple"
const val USERS = "Users"
}
1 change: 1 addition & 0 deletions server/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ springdoc:
enabled: true
path: /docs/openapi-ui.html
layout: BaseLayout
display-operation-id: true
show-actuator: true
remove-broken-reference-definitions: true
writer-with-order-by-keys: true
Expand Down
Loading

0 comments on commit 0cbb336

Please sign in to comment.