Skip to content

Library does not support optional request body #324

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

Closed
stojan-jovic opened this issue May 13, 2021 · 6 comments · Fixed by #325
Closed

Library does not support optional request body #324

stojan-jovic opened this issue May 13, 2021 · 6 comments · Fixed by #325
Labels
area/deserializing Indicates an issue on deserializing area. kind/bug/confirmed

Comments

@stojan-jovic
Copy link

So, if we have definition for requestBody (e.g. for POST request) like this:

requestBody:
  content:
    application/json:
      schema:
        $ref: '#/components/schemas/some_json_schema'
  required: false

and if we try to make request without body, it will produce error like this:

Traceback (most recent call last):
  ...
  File "D:\venvs\.test_venv\lib\site-packages\openapi_core\validation\datatypes.py", line 11, in raise_for_errors
    raise error
  File "D:\venvs\.test_venv\lib\site-packages\openapi_core\validation\request\validators.py", line 164, in _get_body
    deserialised = self._deserialise_media_type(media_type, raw_body)
  File "D:\venvs\.test_venv\lib\site-packages\openapi_core\validation\validators.py", line 28, in _deserialise_media_type
    return deserializer(value)
  File "D:\venvs\.test_venv\lib\site-packages\openapi_core\deserializing\media_types\deserializers.py", line 14, in __call__
    raise DeserializeError(value, self.mimetype)
openapi_core.deserializing.exceptions.DeserializeError: Failed to deserialize value b'' with style application/json

even it should allow it because of required: false.

@p1c2u p1c2u added area/deserializing Indicates an issue on deserializing area. kind/bug/confirmed labels May 14, 2021
@p1c2u
Copy link
Collaborator

p1c2u commented May 14, 2021

Hi @stojan-jovic thanks for reporting the issue. I will try to fix it today.

@stojan-jovic
Copy link
Author

Thank you very much for the so quick fix!
Verified it with just released 0.14.2 and it working! Appreciate!

@stojan-jovic
Copy link
Author

@p1c2u Hm, now we have another issue, when required: true, validator will ignore requests without body.

@stojan-jovic
Copy link
Author

@p1c2u Actually, now validation of request body not working at all... Not sure is that because of this fix, or some of previous releases brought this issue (I updated from 0.13.4, which worked fine).

@p1c2u
Copy link
Collaborator

p1c2u commented May 14, 2021

@stojan-jovic interesting. 0.14.0 was a big change. How's your request body definition look like? Can you craft simple test for that? Feel free to open separate issue.

@stojan-jovic
Copy link
Author

@p1c2u False alarm, really sorry for that. Everything working fine now! I was looking at wrong swagger spec file while testing first time. Thank you one more time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/deserializing Indicates an issue on deserializing area. kind/bug/confirmed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants