sts4 icon indicating copy to clipboard operation
sts4 copied to clipboard

Add/Improve Warning message and Quick Fix for @RequestMapping for method/class level for inconsistent settings

Open manueljordan opened this issue 2 years ago • 5 comments

About Web, if is declared @RequestMapping at method level without the following elements

  • path/value
  • method

A warning message (the yellow icon) should be added - and consider to add a quick fix too.

Mostly for the second, when method is not declared the handler method reacts to any HTTP Method. It is not common

The inverse should be considered too. When @RequestMapping at class level has the method element. Should be removed.

Thank You

p.d: I created this issue because I did realize that many issues were created about @RequestMapping too.

manueljordan avatar Oct 10 '23 21:10 manueljordan

For the missing method parameter we have something already in 4.20.1 snapshot:

Screenshot 2023-10-10 at 18 40 19

Class level request mapping method parameter - I suppose we could add this validation with a quick fix to remove the parameter from the annotation. It just doesn't seem to happen often enough...

Method level @RequestMapping or @GetMapping or any other missing path parameter... We could add a validation for this (i.e. no path parameter and no @RequestMapping with path parameter over the class) but the validation would be without the quickfix... I don't think we can provide a snippet in a CodeAction... And this also doesn't seem like it happens often enough... Usually if one adds an endpoint it starts with a path... the request method might be missing. Yet the path most often is present.

BoykoAlex avatar Oct 10 '23 22:10 BoykoAlex

Thanks

Class level request mapping method parameter - I suppose we could add this validation with a quick fix to remove the parameter from the annotation. It just doesn't seem to happen often enough...

For beginners it would happens ... suppose he created a @Controller with pure/all @RequestMapping as GET, therefore he can assume that at class level can be declared once method as GET to be applied to the handler methods. Of course, it is an incorrect assumption.

Method level @RequestMapping or @GetMapping or any other missing path parameter... We could add a validation for this (i.e. no path parameter and no @RequestMapping with path parameter over the class) but the validation would be without the quickfix... I don't think we can provide a snippet in a CodeAction... And this also doesn't seem like it happens often enough... Usually if one adds an endpoint it starts with a path... the request method might be missing. Yet the path most often is present.

Agree, but it it is "easy" to be implemented ... would be nice to be added

manueljordan avatar Oct 11 '23 13:10 manueljordan

Hello @BoykoAlex and @martinlippert

For the missing method parameter we have something already in 4.20.1 snapshot:

About the "snapshot" bold part ... where is expected to get the IDE installers being not GA? I mean M1,M2, snapshot?

I couldn't find any at:

Observation

I thought in create an issue about this ... but it seems has no a specific section/category

Goal

The point is, I want to offer myself to test some issues/solutions by my part on:

  • Linux Ubuntu & Fedora
  • Windows 10

It according with your instructions. Practically be a Tester.

Let me know your thoughts.

manueljordan avatar Oct 11 '23 14:10 manueljordan

Here is the nightly/snapshot builds download page: https://dist.springsource.com/snapshot/STS4/nightly-distributions.html

BoykoAlex avatar Oct 11 '23 14:10 BoykoAlex

@manueljordan The javadoc over org.springframework.web.bind.annotation.RequestMapping annotation declaration states that all annotation parameters are applicable to type and methods (each parameter javadoc). Therefore I don't think there is anything we should be doing for @RequestMapping over a type. Perhaps it is worth flagging absence of the path parameter in method request mapping annotation as it would map an empty path which is likely undesired... but otherwise I'd just let it be.

BoykoAlex avatar Oct 11 '23 19:10 BoykoAlex