Discover Spring REST Docs API Enum Designs
kotlin spring
Discover Spring REST Docs API Enum Designs
Spring REST Docs API 에서 사용된 Enum Design 이다.
internal interface SecurityRequirementsExtractor {
fun extractSecurityRequirements(operation: Operation): SecurityRequirements?
}
internal class BasicSecurityHandler : SecurityRequirementsExtractor {
override fun extractSecurityRequirements(operation: Operation): SecurityRequirements? {
return if (isBasicSecurity(operation)) {
Basic
} else null
}
private fun isBasicSecurity(operation: Operation): Boolean {
return operation.request.headers
.filterKeys { it == HttpHeaders.AUTHORIZATION }
.flatMap { it.value }
.filter { it.startsWith("Basic ") }
.isNotEmpty()
}
}
internal interface SecurityRequirements {
val type: SecurityType
}
internal data class Oauth2(val requiredScopes: List<String>) :
SecurityRequirements {
override val type = SecurityType.OAUTH2
}
internal object Basic : SecurityRequirements {
override val type = SecurityType.BASIC
}
internal object JWTBearer : SecurityRequirements {
override val type = SecurityType.JWT_BEARER
}
internal enum class SecurityType {
OAUTH2,
BASIC,
API_KEY,
JWT_BEARER
}
Basic 이나 JWTBearer 를 설계할때 sealed class 나 class 등 대신 object 를 사용한 이유는 무엇일까?
Answered by claude 3.5 sonnet: