Skip to content
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

Add fluent problem properties #132

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Conversation

jpraet
Copy link
Contributor

@jpraet jpraet commented Oct 29, 2024

No description provided.

@Test
void fluentProperties() {
InputValidationProblem problem = new MyInputValidationProblem()
.detail("detail message")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't override the fluent setters in InputValidationProblem, this chaining wouldn't work.

You would need to reverse the order to

        InputValidationProblem problem = new MyInputValidationProblem()
                .issues(InputValidationIssues.requiredInput(InEnum.QUERY, "test"))
                .detail("detail message");

The self-referencing generics trick we used in https://github.com/belgif/rest-problem-java/pull/101/files cannot be applied here, because an exception class cannot be generic.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've played around with the implementation but wasn't able to find an alternative approach. Even looked at the manifold compiler plugin which Pieter often mentions but even its crazy change features don't seem to often anything we can use here.

Simply a limitation of the language.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried out another approach with interfaces and default methods to reduce the boilerplate.
One drawback is that an explicit implements Fluent*Problem<SELF> is required on all concrete problem classes that wish to have these fluent properties. Whereas in the previous approach the fluent properties would automatically be inherited from the super class (but with the "wrong" return type, requiring to override to allow proper method chaining).

What do you think @belgif/rest-problem-java?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it does the trick, it's good for me. Adding more children with new properties to the hierarchy will make it more complex but I don't think we are going into that direction.

Copy link

sonarqubecloud bot commented Nov 6, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
20.0% Coverage on New Code (required ≥ 60%)

See analysis details on SonarCloud

Copy link

sonarqubecloud bot commented Dec 16, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants