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

Merged
merged 8 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,42 @@ public void addInvalidParam(InvalidParam invalidParam) {
invalidParams.add(invalidParam);
}

// fluent properties

@Override
public InputValidationProblem href(URI href) {
setHref(href);
return this;
}

@Override
public InputValidationProblem detail(String detail) {
setDetail(detail);
return this;
}

@Override
public InputValidationProblem instance(URI instance) {
setInstance(instance);
return this;
}

@Override
public InputValidationProblem additionalProperty(String name, Object value) {
setAdditionalProperty(name, value);
return this;
}

public InputValidationProblem issues(InputValidationIssue... issues) {
setIssues(issues);
return this;
}

public InputValidationProblem issues(List<InputValidationIssue> issues) {
setIssues(issues);
return this;
}

@Override
public String getMessage() {
StringBuilder message = new StringBuilder(super.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,28 @@ public void setAdditionalProperty(String name, Object value) {
additionalProperties.put(name, value);
}

// fluent properties

public Problem href(URI href) {
setHref(href);
return this;
}

public Problem detail(String detail) {
setDetail(detail);
return this;
}

public Problem instance(URI instance) {
setInstance(instance);
return this;
}

public Problem additionalProperty(String name, Object value) {
setAdditionalProperty(name, value);
return this;
}

/**
* Returns the problem message, consisting of the problem title, followed by the detail message (if present).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ void addInvalidParam() {
assertThat(problem.getInvalidParams()).isUnmodifiable().containsExactly(invalidParam);
}

@Test
void fluentProperties() {
InputValidationProblem problem = new MyInputValidationProblem()
.detail("detail message")
jpraet marked this conversation as resolved.
Show resolved Hide resolved
.issues(InputValidationIssues.requiredInput(InEnum.QUERY, "test"));
}

@Test
void equalsHashCodeToString() {
InputValidationIssue issue = new InputValidationIssue(InEnum.QUERY, "test");
Expand Down
Loading