From b63874167a269a16bc14fc698390b0cfaf206b73 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Wed, 22 May 2019 21:53:58 -0700 Subject: [PATCH] Add some more Swagger annotations --- .../budgetserver/{Error Response.kt => ErrorResponse.kt} | 0 .../com/wbrawner/budgetserver/account/AccountController.kt | 3 ++- .../wbrawner/budgetserver/category/CategoryController.kt | 4 ++-- .../com/wbrawner/budgetserver/config/SwaggerConfig.kt | 2 ++ .../budgetserver/transaction/TransactionController.kt | 6 ++---- .../kotlin/com/wbrawner/budgetserver/user/UserController.kt | 4 ++-- 6 files changed, 10 insertions(+), 9 deletions(-) rename src/main/kotlin/com/wbrawner/budgetserver/{Error Response.kt => ErrorResponse.kt} (100%) diff --git a/src/main/kotlin/com/wbrawner/budgetserver/Error Response.kt b/src/main/kotlin/com/wbrawner/budgetserver/ErrorResponse.kt similarity index 100% rename from src/main/kotlin/com/wbrawner/budgetserver/Error Response.kt rename to src/main/kotlin/com/wbrawner/budgetserver/ErrorResponse.kt diff --git a/src/main/kotlin/com/wbrawner/budgetserver/account/AccountController.kt b/src/main/kotlin/com/wbrawner/budgetserver/account/AccountController.kt index f6e835f..d480c45 100644 --- a/src/main/kotlin/com/wbrawner/budgetserver/account/AccountController.kt +++ b/src/main/kotlin/com/wbrawner/budgetserver/account/AccountController.kt @@ -4,6 +4,7 @@ import com.wbrawner.budgetserver.getCurrentUser import com.wbrawner.budgetserver.user.UserRepository import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation +import io.swagger.annotations.Authorization import org.hibernate.Hibernate import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.MediaType @@ -13,7 +14,7 @@ import javax.transaction.Transactional @RestController @RequestMapping("/accounts") -@Api(value = "Accounts", tags = ["Accounts"]) +@Api(value = "Accounts", tags = ["Accounts"], authorizations = [Authorization("basic")]) class AccountController @Autowired constructor(private val accountRepository: AccountRepository, private val userRepository: UserRepository) { @Transactional @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE]) diff --git a/src/main/kotlin/com/wbrawner/budgetserver/category/CategoryController.kt b/src/main/kotlin/com/wbrawner/budgetserver/category/CategoryController.kt index 65ce8c1..234db9e 100644 --- a/src/main/kotlin/com/wbrawner/budgetserver/category/CategoryController.kt +++ b/src/main/kotlin/com/wbrawner/budgetserver/category/CategoryController.kt @@ -6,19 +6,19 @@ import com.wbrawner.budgetserver.getCurrentUser import com.wbrawner.budgetserver.transaction.TransactionRepository import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation +import io.swagger.annotations.Authorization import org.hibernate.Hibernate import org.springframework.beans.factory.annotation.Autowired import org.springframework.data.domain.PageRequest import org.springframework.http.MediaType import org.springframework.http.ResponseEntity -import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.* import java.lang.Integer.min import javax.transaction.Transactional @RestController @RequestMapping("/categories") -@Api(value = "Categories", tags = ["Categories"]) +@Api(value = "Categories", tags = ["Categories"], authorizations = [Authorization("basic")]) class CategoryController @Autowired constructor( private val accountRepository: AccountRepository, private val categoryRepository: CategoryRepository, diff --git a/src/main/kotlin/com/wbrawner/budgetserver/config/SwaggerConfig.kt b/src/main/kotlin/com/wbrawner/budgetserver/config/SwaggerConfig.kt index dea36dc..459efe0 100644 --- a/src/main/kotlin/com/wbrawner/budgetserver/config/SwaggerConfig.kt +++ b/src/main/kotlin/com/wbrawner/budgetserver/config/SwaggerConfig.kt @@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport import springfox.documentation.builders.RequestHandlerSelectors +import springfox.documentation.service.BasicAuth import springfox.documentation.spi.DocumentationType import springfox.documentation.spring.web.plugins.Docket import springfox.documentation.swagger2.annotations.EnableSwagger2 @@ -14,6 +15,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2 class SwaggerConfig : WebMvcConfigurationSupport() { @Bean fun budgetApi(): Docket = Docket(DocumentationType.SWAGGER_2) + .securitySchemes(mutableListOf(BasicAuth("basic"))) .select() .apis(RequestHandlerSelectors.basePackage("com.wbrawner.budgetserver")) .build() diff --git a/src/main/kotlin/com/wbrawner/budgetserver/transaction/TransactionController.kt b/src/main/kotlin/com/wbrawner/budgetserver/transaction/TransactionController.kt index c73ca96..11cfcc0 100644 --- a/src/main/kotlin/com/wbrawner/budgetserver/transaction/TransactionController.kt +++ b/src/main/kotlin/com/wbrawner/budgetserver/transaction/TransactionController.kt @@ -7,22 +7,20 @@ import com.wbrawner.budgetserver.category.CategoryRepository import com.wbrawner.budgetserver.getCurrentUser import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation +import io.swagger.annotations.Authorization import org.hibernate.Hibernate import org.springframework.beans.factory.annotation.Autowired import org.springframework.data.domain.PageRequest import org.springframework.http.MediaType import org.springframework.http.ResponseEntity -import org.springframework.security.access.prepost.PreAuthorize import org.springframework.web.bind.annotation.* import java.lang.Integer.min -import java.lang.RuntimeException import java.time.Instant -import java.util.* import javax.transaction.Transactional @RestController @RequestMapping("/transactions") -@Api(value = "Transactions", tags = ["Transactions"]) +@Api(value = "Transactions", tags = ["Transactions"], authorizations = [Authorization("basic")]) class TransactionController @Autowired constructor( private val accountRepository: AccountRepository, private val categoryRepository: CategoryRepository, diff --git a/src/main/kotlin/com/wbrawner/budgetserver/user/UserController.kt b/src/main/kotlin/com/wbrawner/budgetserver/user/UserController.kt index 3f217b2..735d158 100644 --- a/src/main/kotlin/com/wbrawner/budgetserver/user/UserController.kt +++ b/src/main/kotlin/com/wbrawner/budgetserver/user/UserController.kt @@ -5,18 +5,18 @@ import com.wbrawner.budgetserver.account.AccountRepository import com.wbrawner.budgetserver.getCurrentUser import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation +import io.swagger.annotations.Authorization import org.hibernate.Hibernate import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.MediaType import org.springframework.http.ResponseEntity -import org.springframework.security.access.prepost.PreAuthorize import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.web.bind.annotation.* import javax.transaction.Transactional @RestController @RequestMapping("/users") -@Api(value = "Users", tags = ["Users"]) +@Api(value = "Users", tags = ["Users"], authorizations = [Authorization("basic")]) class UserController @Autowired constructor(private val accountRepository: AccountRepository, private val userRepository: UserRepository, private val passwordEncoder: PasswordEncoder) { @Transactional @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE])