Skip to content

BUG: Unmarshalling nullable objects #232

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
berislavlopac opened this issue Apr 3, 2020 · 2 comments · Fixed by #239
Closed

BUG: Unmarshalling nullable objects #232

berislavlopac opened this issue Apr 3, 2020 · 2 comments · Fixed by #239
Labels
area/unmarshalling Indicates an issue on unmarshalling area. kind/bug/confirmed

Comments

@berislavlopac
Copy link

berislavlopac commented Apr 3, 2020

According to my tests, the latest openapi-core release (0.13.3 at the time of this writing) is ignoring the nullable keyword when unmarshalling an object, so it fails here:

  File "/home/berislav/.virtualenvs/tm/lib/python3.7/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py", line 201, in _unmarshal_properties
    value_props_names = value.keys()
AttributeError: 'NoneType' object has no attribute 'keys'

I will write a quick minimum test case when I have a minute, opening this now if someone can take a look.

@berislavlopac berislavlopac changed the title Unmarshalling nullable objects BUG: Unmarshalling nullable objects Apr 3, 2020
@playpauseandstop
Copy link

Can confirm given issue.

I've managed to fix it by entirely remove nullable: true specifications from my OpenAPI schemas.

@p1c2u p1c2u added area/unmarshalling Indicates an issue on unmarshalling area. kind/bug/confirmed labels Apr 11, 2020
@berislavlopac
Copy link
Author

berislavlopac commented Apr 12, 2020

Here's a minimal example I could whip up:

from openapi_core import create_spec
from openapi_core.validation.request.datatypes import RequestParameters, OpenAPIRequest
from openapi_core.validation.request.validators import RequestValidator

spec_dict = {
    "openapi": "3.0.1",
    "info": {"title": "Test Spec", "version": "0.0.0"},
    "servers": [{"url": "http://localhost"}],
    "paths": {
        "/test": {
            "post": {
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "foo": {
                                        "type": "object",
                                        "nullable": True
                                    },
                                }
                            }
                        }
                    }
                },
                "responses": {"204": {"description": "Empty response."}}
            }
        }
    }
}

spec = create_spec(spec_dict)

request_body = '{"foo": null}'

request = OpenAPIRequest(
    full_url_pattern="http://localhost/test",
    method="post",
    parameters=RequestParameters(),
    body=request_body,
    mimetype="application/json",
)

result = RequestValidator(spec).validate(request)

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

Successfully merging a pull request may close this issue.

3 participants