rename version annotations

This commit is contained in:
Alexander Buntakov 2021-06-08 15:23:16 +03:00
parent b903289b21
commit 06e692ea9b
5 changed files with 13 additions and 15 deletions

View File

@ -0,0 +1,6 @@
package ru.touchin.version.annotations
@Target(allowedTargets = [AnnotationTarget.CLASS])
internal annotation class Versioned(
val value: String = ""
)

View File

@ -1,6 +1,5 @@
package ru.touchin.version.annotations
@Versioned("/api/v\${api.version}")
@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class VersionedApi(
val value: String = ""
)
annotation class VersionedApi

View File

@ -1,8 +0,0 @@
package ru.touchin.version.annotations
import org.springframework.web.bind.annotation.RestController
@RestController
@VersionedApi("/api/v\${api.version}")
@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class VersionedRestController

View File

@ -3,7 +3,7 @@ package ru.touchin.version.mapping
import org.springframework.core.annotation.AnnotatedElementUtils
import org.springframework.web.servlet.mvc.method.RequestMappingInfo
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
import ru.touchin.version.annotations.VersionedApi
import ru.touchin.version.annotations.Versioned
import java.lang.reflect.Method
class VersionedRequestMappingHandlerMapping : RequestMappingHandlerMapping() {
@ -12,7 +12,7 @@ class VersionedRequestMappingHandlerMapping : RequestMappingHandlerMapping() {
val mappingResult = super.getMappingForMethod(method, handlerType)
?: return null
val versionedAnnotation = AnnotatedElementUtils.findMergedAnnotation(handlerType, VersionedApi::class.java)
val versionedAnnotation = AnnotatedElementUtils.findMergedAnnotation(handlerType, Versioned::class.java)
?: return mappingResult
val versionPath = resolveEmbeddedValuesInPatterns(

View File

@ -17,9 +17,10 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import ru.touchin.version.annotations.VersionedRestController
import ru.touchin.version.annotations.VersionedApi
@VersionedRestController
@VersionedApi
@RestController
@RequestMapping("/app")
class VersionController {