Skip to content

fixes #27 #28

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

Merged
merged 1 commit into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -137,9 +137,10 @@ public Status validateRequestPath (String requestURI , String httpMethod, Reques
if ((requestEntity.getContentType()==null || requestEntity.getContentType().startsWith("application/json"))) {
try {
Object body = attachJsonBody(requestEntity.getRequestBody());
if (body!=null) {
status = validateRequestBody(body, openApiOperation);
}
status = validateRequestBody(body, openApiOperation);
// if (body!=null) {
// status = validateRequestBody(body, openApiOperation);
// }
} catch (Exception e) {
status = new Status( VALIDATOR_REQUEST_BODY_UNEXPECTED, requestPath.normalised());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,32 @@ public void testRequestBody4() throws JsonProcessingException {
//{"statusCode":400,"code":"ERR11004","message":"VALIDATOR_SCHEMA","description":"Schema Validation Error - requestBody.id: string found, integer expected","severity":"ERROR"}
}

@Test
public void testRequestBodyEmpty() {
String req = "";
RequestEntity requestEntity = new RequestEntity();
requestEntity.setRequestBody(req);
requestEntity.setContentType("application/json");
Status status = openApiValidator.validateRequestPath("/pets", "post", requestEntity);
Assert.assertNotNull(status);
Assert.assertEquals( status.getCode(), "ERR11013");
System.out.println(status.getDescription());
//{"statusCode":400,"code":"ERR11013","message":"VALIDATOR_REQUEST_BODY_UNEXPECTED","No request body is expected for %s on path %s.":"ERROR"}
}

@Test
public void testRequestBodyNull() {
String req = null;
RequestEntity requestEntity = new RequestEntity();
requestEntity.setRequestBody(req);
requestEntity.setContentType("application/json");
Status status = openApiValidator.validateRequestPath("/pets", "post", requestEntity);
Assert.assertNotNull(status);
Assert.assertEquals( status.getCode(), "ERR11014");
//{"statusCode":400,"code":"ERR11004","message":"VALIDATOR_REQUEST_BODY_MISSING","description":"Method post on path /pets requires a request body. None found.","severity":"ERROR"}
}


@Test
public void testRequestPath() {

Expand Down