Skip to content
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

Consider empty requestBody as valid if not required #197

Open
cvernerie opened this issue May 15, 2023 · 2 comments
Open

Consider empty requestBody as valid if not required #197

cvernerie opened this issue May 15, 2023 · 2 comments

Comments

@cvernerie
Copy link

In the OpenApi specification, request bodies are optional by default, unless required: true is declared explicitly.

So I think the BodyValidator should not throw an exception in case an optional request body is not provided in the request.

As well, if a requestBody is required in the spec but not provided in the request, we can directly throw an InvalidBody exception and not try to validate against the schema.

One consequence is that projects using the library might need to add required: true on their endpoints in order to keep the same validation behaviour.

@Sarke
Copy link

Sarke commented Sep 24, 2023

Same with required fields. As long as the required fields are present, it shouldn't fail because the optional ones are not present.

@marius-xentral
Copy link

what's the status here? validating a request with an empty body (RequestValidator->validate($request)) results in a JSON syntax error if requestBody - required: true is not set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants