Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Shryne opened this issue Oct 28, 2021 · 2 comments
Closed

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

Shryne opened this issue Oct 28, 2021 · 2 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@Shryne
Copy link

Shryne commented Oct 28, 2021

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 28, 2021
@sbrannen sbrannen changed the title Add ANNOTATION_TYPE as a target to PathVariable, RequestHeader and others Support @PathVariable, @RequestHeader, etc. as meta annotations Oct 28, 2021
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Oct 28, 2021
@sbrannen
Copy link
Member

Closing as a duplicate of #21829

@sbrannen sbrannen added status: duplicate A duplicate of another issue type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 28, 2021
@sbrannen
Copy link
Member

sbrannen commented Nov 1, 2021

Note that this support is planned in Spring Framework 6.0: #21829 (comment)

@sbrannen sbrannen changed the title Support @PathVariable, @RequestHeader, etc. as meta annotations Support @PathVariable, @RequestHeader, etc. as meta-annotations Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants