Skip to content

Commit

Permalink
fix swagger specification test
Browse files Browse the repository at this point in the history
  • Loading branch information
mherman22 committed Oct 29, 2024
1 parent 2bfc0b2 commit 70dbaf0
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,30 +179,31 @@ public void checkOperationIdsSet() {
@Test
public void checkRepresentationParamExists() {
SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator();
String json = ssc.getJSON();
ssc.getJSON();
OpenAPI spec = ssc.getOpenAPI();

Assert.assertNotNull("SwaggerSpecificationCreator should not be null", ssc);
Assert.assertNotNull("JSON should not be null", json);
Assert.assertNotNull("OpenAPI spec should not be null", spec);
Assert.assertNotNull("Paths in OpenAPI spec should not be null", spec.getPaths());

// If we get past the assertion, continue with the original test logic
for (PathItem p : spec.getPaths().values()) {
Assert.assertNotNull("PathItem should not be null", p);
for (Operation o : p.readOperations()) {
if (o != null) {
Assert.assertTrue("Ensure each GET operation has the 'v' query parameter",
operationHasRepresentationParam(o));
}
spec.getPaths().forEach((path, pathItem) -> {
Operation getOperation = pathItem.getGet();
if (getOperation != null) {
Assert.assertTrue(
String.format("GET operation at path %s must have 'v' query parameter", path),
operationHasRepresentationParam(getOperation)
);
}
}
});
}

private boolean operationHasRepresentationParam(Operation operation) {
return operation.getParameters() != null &&
operation.getParameters().stream()
.anyMatch(param -> "v".equals(param.getName()) && "query".equals(param.getIn()));
if (operation.getParameters() == null) {
return false;
}

return operation.getParameters().stream()
.anyMatch(param -> "v".equals(param.getName()));
}

// make sure each operation that supports paging has the limit and startIndex parameters
Expand Down

0 comments on commit 70dbaf0

Please sign in to comment.