-
Notifications
You must be signed in to change notification settings - Fork 297
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
Development:
Enforce Usage of Optional<T> Over @RequestParam(required = false) in Method Parameters
#9146
Conversation
…ith required set to false
…e-with-request-param
WalkthroughThe recent updates across various classes enhance the handling of optional parameters by transitioning from nullable types to Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant API
participant Service
Client->>API: Call endpoint with optional parameters
API->>Service: Process request with Optional parameters
Service-->>API: Return results or handle absence
API-->>Client: Send response back
Possibly related issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
This was very briefly discussed with @Strohgelaender. As of now, this PR does not actually fix any violation of this rule. Keeping the single responsibility principle in mind, the PR actually fixing the violations should be separate, as the refactoring might introduce many code changes to incorporate the change. |
Development:
Enforce Usage of Optional<T> Over @RequestParam(required = false) in Method Parameters
src/test/java/de/tum/in/www1/artemis/architecture/ArchitectureTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
src/test/java/de/tum/in/www1/artemis/architecture/ArchitectureTest.java
Outdated
Show resolved
Hide resolved
src/test/java/de/tum/in/www1/artemis/architecture/ArchitectureTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
src/test/java/de/tum/in/www1/artemis/architecture/ArchitectureTest.java
Outdated
Show resolved
Hide resolved
Thank you for the contribution and welcome to Artemis 👋 Please also fix the violations of the new test in this PR. We don't want to merge PRs that contain test failures into Also |
src/test/java/de/tum/in/www1/artemis/architecture/ArchitectureTest.java
Outdated
Show resolved
Hide resolved
I'd suggest that this PR also introduces an architecture test that ensures the correct use of optional as parameters |
There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions. |
…d-check-for-required-false-with-request-param
While I still disagree with this stance, especially since you lose the ability to assert when a given parameter has been checked for Regarding the documentation request, I assume you want me to change the documentation in confluence? Is there a certain procedure to follow when updating documentation I should be aware of? I was and still am in Japan until the end of the week and will probably address the change requests in the upcoming week. |
Should the PR really get any bigger at this point? I think this could and should be handled as a separate PR. It would also be a |
@krusche @dfuchss Could you please go over the new addition to the server guidelines in this PR and check whether you agree with the wording? Furthermore I have an additional question: How should we handle the case where using
|
For me, the stated guidelines look good. |
I mean the question might be "how many are there". If it's kind of e.g., 10 I'd suggest to do that. otherwise, I'd suggest to add a PR later. In any case I'd add an architecture test to check for wrong occurrences. |
There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions. |
Checklist
General
Motivation and Context
There are some instances where a Controller/Endpoint uses the
@RequestParam
annotation withrequired
set to false. This however leads to the issue of potentialNullPointerExceptions
. Spring supports the use ofOptional<T>
for this use case, leading to aOptional.empty()
if the value is not set. This would allow for cleaner functional-style code.Description
This PR introduces a new ArchUnit test to enforce a coding standard regarding the usage of
@RequestParam
annotations in method parameters. The test ensures that no method within the specified packages uses@RequestParam
withrequired = false
. Instead, it encourages the use of Optional to handle optional parameters.Steps for Testing
Run the ArchTests, probably using
./gradlew test
.Testserver States
Note
These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.
Review Progress
Performance Review
Code Review
Manual Tests
Exam Mode Test
Test Coverage
Screenshots
Summary by CodeRabbit
New Features
Optional<T>
for method parameters, improving clarity and safety.Bug Fixes
Enhancements
Optional<T>
, promoting better null safety and code readability.