Skip to content

Commit b029b28

Browse files
authored
Merge branch 'main' into feature/configurable-ambiguous-oneof-violations
2 parents 29ddf86 + 873b594 commit b029b28

13 files changed

Lines changed: 109 additions & 54 deletions

File tree

‎CODEOWNERS‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @getyourguide/uspr
1+
* @getyourguide/payx

‎gradle/libs.versions.toml‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[versions]
22
java = "21"
3-
spring-boot = "4.0.7"
3+
spring-boot = "4.1.2"
44
spring-dependency-management = "1.1.7"
5-
openapi-generator = "7.21.0"
6-
openapi-tools = "0.2.9"
7-
swagger = "2.2.46"
8-
swagger-request-validator = "2.46.1"
5+
openapi-generator = "7.26.0"
6+
openapi-tools = "0.2.13"
7+
swagger = "3.0.0"
8+
swagger-request-validator = "3.0.0"
99
jakarta-validation = "3.1.1"
10-
lombok = "1.18.44"
11-
commons-codec = "1.21.0"
10+
lombok = "1.18.48"
11+
commons-codec = "1.23.0"
1212
find-bugs = "3.0.2"
1313
gradle-nexus-publish-plugin = "2.0.0"
1414
datadog-statsd = "4.4.5"
@@ -17,9 +17,9 @@ checkstyle = "8.44"
1717
pmd = "7.14.0"
1818
jacoco = "0.8.13"
1919
# Testing
20-
mockito = "5.23.0"
21-
junit-jupiter = "6.0.3"
22-
junit-platform = "6.0.3"
20+
mockito = "5.24.0"
21+
junit-jupiter = "6.1.3"
22+
junit-platform = "6.1.3"
2323

2424
[libraries]
2525
openapi-tools-jacksonDatabindNullable = { group = "org.openapitools", name = "jackson-databind-nullable", version.ref = "openapi-tools" }

‎gradle/wrapper/gradle-wrapper.jar‎

-217 Bytes
Binary file not shown.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.2-bin.zip
44
networkTimeout=10000
5+
retries=0
6+
retryBackOffMs=500
57
zipStoreBase=GRADLE_USER_HOME
68
zipStorePath=wrapper/dists

‎gradlew‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎gradlew.bat‎

Lines changed: 52 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎openapi-validation-api/src/main/java/com/getyourguide/openapi/validation/api/Rules.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public static class Request {
55
public static final String PATH_MISSING = "validation.request.path.missing";
66
public static final String OPERATION_NOT_ALLOWED = "validation.request.operation.notAllowed";
77
public static final String BODY_SCHEMA_ONE_OF = "validation.request.body.schema.oneOf";
8+
public static final String ACCEPT_NOT_ALLOWED = "validation.request.accept.notAllowed";
89
}
910

1011
public static class Response {

‎openapi-validation-core/src/main/java/com/getyourguide/openapi/validation/core/exclusions/InternalViolationExclusions.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public InternalViolationExclusions(
2323
}
2424

2525
public boolean isExcluded(OpenApiViolation violation) {
26-
return falsePositive404(violation)
26+
return falsePositive204(violation)
27+
|| falsePositive404(violation)
2728
|| falsePositive405(violation)
2829
|| falsePositive406(violation)
2930
|| falsePositiveRequestWith4xxResponse(violation)
@@ -42,6 +43,11 @@ private static boolean oneOfMatchesMoreThanOneSchema(OpenApiViolation violation)
4243
.matches(".*Instance failed to match exactly one schema \\(matched [1-9][0-9]* out of \\d+\\).*");
4344
}
4445

46+
private boolean falsePositive204(OpenApiViolation violation) {
47+
return violation.getResponseStatus().orElse(0) == 204
48+
&& Rules.Request.ACCEPT_NOT_ALLOWED.equals(violation.getRule());
49+
}
50+
4551
private boolean falsePositive404(OpenApiViolation violation) {
4652
return
4753
(

‎openapi-validation-core/src/main/java/com/getyourguide/openapi/validation/core/log/ThrottlingOpenApiViolationHandler.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
import com.getyourguide.openapi.validation.api.log.OpenApiViolationHandler;
44
import com.getyourguide.openapi.validation.api.model.OpenApiViolation;
5+
import java.time.Instant;
56
import java.util.Map;
67
import java.util.concurrent.ConcurrentHashMap;
78
import lombok.AllArgsConstructor;
89
import lombok.NonNull;
9-
import org.joda.time.DateTime;
1010

1111
@AllArgsConstructor
1212
public class ThrottlingOpenApiViolationHandler implements OpenApiViolationHandler {
1313
private final OpenApiViolationHandler delegate;
1414
private final int waitSeconds;
15-
private final Map<String, DateTime> loggedMessages = new ConcurrentHashMap<>();
15+
private final Map<String, Instant> loggedMessages = new ConcurrentHashMap<>();
1616

1717
@Override
1818
public void onOpenApiViolation(OpenApiViolation violation) {
@@ -25,13 +25,13 @@ public void onOpenApiViolation(OpenApiViolation violation) {
2525
}
2626

2727
private void registerLoggedMessage(OpenApiViolation openApiViolation) {
28-
loggedMessages.put(buildKey(openApiViolation), DateTime.now());
28+
loggedMessages.put(buildKey(openApiViolation), Instant.now());
2929
}
3030

3131
private boolean isThrottled(OpenApiViolation openApiViolation) {
3232
var key = buildKey(openApiViolation);
3333
var lastLoggedTime = loggedMessages.get(key);
34-
return lastLoggedTime != null && lastLoggedTime.plusSeconds(waitSeconds).isAfterNow();
34+
return lastLoggedTime != null && lastLoggedTime.plusSeconds(waitSeconds).isAfter(Instant.now());
3535
}
3636

3737
@NonNull

‎openapi-validation-core/src/test/java/com/getyourguide/openapi/validation/core/exclusions/InternalViolationExclusionsTest.java‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public void whenViolationThenViolationNotExcluded() {
2929
checkViolationNotExcluded(buildSimpleViolation(Direction.RESPONSE, 404));
3030
checkViolationNotExcluded(buildSimpleViolation(Direction.RESPONSE, 400));
3131
checkViolationNotExcluded(buildSimpleViolation(Direction.REQUEST, 200));
32+
checkViolationNotExcluded(buildSimpleViolation(Direction.REQUEST, 204));
3233
checkViolationNotExcluded(buildSimpleViolation(Direction.REQUEST, null));
3334
checkViolationNotExcluded(buildSimpleViolation(Direction.RESPONSE, 200));
3435
}
@@ -180,6 +181,30 @@ public void when406ResponseCodeWithStatusUnknownViolationThenViolationExcluded()
180181
.build());
181182
}
182183

184+
@Test
185+
public void when204ResponseCodeWithAcceptNotAllowedViolationThenViolationExcluded() {
186+
when(customViolationExclusions.isExcluded(any())).thenReturn(false);
187+
188+
checkViolationExcluded(buildAcceptNotAllowedViolation(204));
189+
}
190+
191+
@Test
192+
public void whenNon204ResponseCodeWithAcceptNotAllowedViolationThenViolationNotExcluded() {
193+
when(customViolationExclusions.isExcluded(any())).thenReturn(false);
194+
195+
checkViolationNotExcluded(buildAcceptNotAllowedViolation(200));
196+
}
197+
198+
private static OpenApiViolation buildAcceptNotAllowedViolation(int responseStatus) {
199+
return OpenApiViolation.builder()
200+
.direction(Direction.REQUEST)
201+
.rule("validation.request.accept.notAllowed")
202+
.responseStatus(responseStatus)
203+
.message("Request Accept header '[application/json]' does not match any defined response types. "
204+
+ "Must be one of: [application/problem+json].")
205+
.build();
206+
}
207+
183208
@Test
184209
public void whenUnknownErrorWithConcurrentModificationExceptionThenViolationExcluded() {
185210
when(customViolationExclusions.isExcluded(any())).thenReturn(false);

0 commit comments

Comments
 (0)