@PathVariable (and others) should be useable on annotations (like @RequestMapping). With that it would be possible to create custom annotations based on that.

Personally, I would like to combine it with annotations from swagger-core. Normally, a REST method on a controller looks like that:

@GetMapping(...)
fun get(
    @Parameter(description = "My special id")
    @PathVariable 
    id: Long
): ResponseEntity<Something> { ... }

The problem is that every method will need at least two kinds of annotations: The spring annotations for the functionality and the documentation for this functionality. In my opinion, I should be able to combine it:

@Parameter
@PathVariable
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION)
annotation class DocPathVariable(
    @get:AliasFor(annotation = PathVariable::class, attribute = "name")
    val name: String = "",

    @get:AliasFor(annotation = Parameter::class, attribute = "description")
    val description: String = "",
)

// used:
@GetMapping(...)
fun get(
    @DocPathVariable(description = "My special id") 
    id: Long
): ResponseEntity<Something> { ... }

Same goes for: @RequestHeader, @RequestBody, @RequestParam and probably more.

Comment From: sbrannen

Closing as a duplicate of #21829

Comment From: sbrannen

Note that this support is planned in Spring Framework 6.0: https://github.com/spring-projects/spring-framework/issues/21829#issuecomment-956252567