mservicetech / openapi-schema-validation

Apache License 2.0
15 stars 9 forks source link

Fix Request Body Validation Bug #27

Closed vijayseid closed 1 year ago

vijayseid commented 1 year ago

Hi @GavinChenYan @stevehu Find a Bug on validating the Request body, could you please fix it.

OpenApiSpec has Mandatory field on request body, here is the piece of line added

RequestBody: required: - feature type: object properties: billerDivisionId: type: string description: Division Id for account, same as spc division id billerAccountNumber: type: string description: Account number in a billing system soloAccountId: type: string description: Account Id in SOLO feature: type: string description: 'Use case for which this token needs to be generated (example: enable-paperless-billing)' description: Billing details

Scenario 0 : Positive - Works as expected

image

Scenario 1 : Negative - Works as expected

If I Skip the field feature, I got the perfect validation says this field is required & it's missed.

image

Scenario 2 : Negative - Failed to pass

If I Skip the entire Request body(not passing any body), I Didn't get any validation error, & validation was successful. It should throw the same as scenario 1.

image

GavinChenYan commented 1 year ago

@vijayseid Thanks, will take a look this issue

GavinChenYan commented 1 year ago

@vijayseid For your case, you put body type as null, which normally will not happen on API call. If we specify the json format on postman, it will have error as expected: image

But for your case, I add a fix as well. And added two test cases for reference. Please take a look PR: https://github.com/mservicetech/openapi-schema-validation/pull/28

vijayseid commented 1 year ago

@GavinChenYan Thanks for the quick fix, great advantage of using this lib is lightening response & fix from developer .

vijayseid commented 1 year ago

@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 :

image

Passing as NULL:

image

Can you please confirm you fix?

vijayseid commented 1 year ago

@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 - >

image

Status is null ->

image

if I pass the body, it will say expected key is required & it is missing