Closed vijayseid closed 1 year ago
@vijayseid I tried with API, it works fine for me. Can you please refer the test cases for your method call?:
@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"}
}
@GavinChenYan
Test case : testRequestBodyEmpty()
if you pass request body as "" empty, it should throw as required fields right which we missed, but it says No request body is expected for %s on path %s.":"ERROR". But our case need an request body with required field.
Test Case : testRequestBodyNull()
I have tested by passing null, but it passed without any error
@vijayseid Sorry for the delay. I will take a look the status code for the error.
For second senario, can you take a look your code implementation? Do you set the request body ? requestEntity.setRequestBody(req);
Yeah @GavinChenYan I'm setting the request body
schemaValidateRequest.setRequestBody(requestBody);
That's weird, my case works fine
@vijayseid there is logic in the code: if ((requestEntity.getContentType()==null || requestEntity.getContentType().startsWith("application/json"))) {
what content type you are using? can you debug to find it? only in case it is null or application/json , it trigger body validation
@GavinChenYan Confirmed, content type is application/json & my request body is null. Still it is not throwing the error for me
requestEntity.setContentType(MediaType.APPLICATION_JSON_VALUE);
Request body is null - >
Status is null ->
if I pass the body, it will say expected key is required & it is missing
Also @GavinChenYan when new release will happen? any approx date?
version 2.0.8 released:
Uploaded to ossrh: https://oss.sonatype.org:443/service/local/staging/deployByRepositoryId/commservicetech-1013/com/mservicetech/openapi-schema-validation/2.0.8/openapi-schema-validation-2.0.8.jar.asc.asc (673 B at 7.9 kB/s)
@GavinChenYan @stevehu
Even though if pass the request body as empty or null, still it's not validating properly, I saw the change & made the same change on custom lib as well.
Passing as EMPTY :
Passing as NULL:
Can you please confirm you fix?
Originally posted by @vijayseid in https://github.com/mservicetech/openapi-schema-validation/issues/27#issuecomment-1587034064