Skip to content

@PathVariable, @RequestBody, @ApiParam, similar annotations, may be removed if they're present on superclass or interface #9

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

Open
sambsnyd opened this issue Oct 20, 2020 · 4 comments · May be fixed by #698
Labels
enhancement New feature or request

Comments

@sambsnyd
Copy link
Member

sambsnyd commented Oct 20, 2020

There are various spring annotations, including but not limited to @PathVariable, @RequestBody, @Valid, @Size, @ApiParam, @Pattern, which allow developers to tell spring about the contract their API has.

If these annotations are present on a superclass or interface being implemented then they can be removed from the subclass.
Leaving them isn't necessarily harmful so long as the arguments of the duplicated annotations match. If the arguments do not match it's a spring runtime error. So this is a "best practices & hygiene" rather than an "essential for migration" sort visitor.

@sambsnyd sambsnyd added the enhancement New feature or request label Oct 20, 2020
@gadams00 gadams00 self-assigned this Jan 4, 2021
@sambsnyd
Copy link
Member Author

Turns out this is really hard/ almost impossible with our current API. We just don't have enough information on JavaType.Class about what methods and what annotations are on those methods to be able to do this correctly.

@sambsnyd
Copy link
Member Author

sambsnyd commented Jan 14, 2021

@rpau rpau added this to the Support Spring Framework migrations milestone May 24, 2023
@timtebeek timtebeek moved this to Recipes Wanted in OpenRewrite Nov 29, 2023
@timtebeek timtebeek removed this from the Support Spring Framework migrations milestone Nov 30, 2023
ryan-hudson pushed a commit to ryan-hudson/rewrite-spring that referenced this issue Nov 18, 2024
…pringdoc

rearranging springdoc/openapi recipes. individual springdoc upgrades …
@arodionov arodionov self-assigned this Apr 17, 2025
@arodionov arodionov linked a pull request Apr 24, 2025 that will close this issue
3 tasks
@arodionov
Copy link

It seems, there is still no way to get all the required annotations for a superclass/interface.

For example, having an interface:

public interface UserApi {
    @PostMapping("/users/{id}")
    String updateUser(
        @PathVariable("id") Long id,
        @RequestBody UserData request
    );
}

and the UserController implementation:

@RestController
public class UserController implements UserApi {

    @Override @PostMapping("/users/{id}")
    public String updateUser(
        @PathVariable("id") Long id,
        @RequestBody UserData request
    ) {
        return "User " + id + " updated: " + request.getFirstName() + " " + request.getLastName();
    }
}

The JavaType.Method for UserApi#updateUser has method annotations but doesn't have method parameters annotations:

Image

@timtebeek
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Recipes Wanted
Development

Successfully merging a pull request may close this issue.

5 participants