Skip to content

Support @PathVariable, @RequestHeader, etc. as meta-annotations #27621

Closed
@Shryne

Description

@Shryne

@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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issuetype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions