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

Deserialization crash in client when schema excludes fields #175

Open
brockhaywood opened this issue Feb 14, 2020 · 0 comments
Open

Deserialization crash in client when schema excludes fields #175

brockhaywood opened this issue Feb 14, 2020 · 0 comments
Labels
bug Something isn't working swagger-generation Concerns automatic swagger generation

Comments

@brockhaywood
Copy link
Contributor

In a response schema, if a nested field excludes fields from the schema that it nests, the swagger file generated by flask-rebar does not indicate that the excluded field will not be in the response.

Steps to reproduce

Define a schema similar to this

from marshmallow import fields
from flask_rebar.validation import ResponseSchema

class MyObjectSchema(ResponseSchema):
    my_uid = fields.UUID(required=True)
    my_field = fields.String(required=True)

class MyObjectListSchema(ResponseSchema):
    results = fields.Nested(
        MyObjectSchema,
        exclude=("my_field",),
        required=True,
        many=True,
    )

This will generate a swagger file with some of the following in it:

....
        "MyObjectSchema": {
            "properties": {
                "my_uid": {
                    "format": "uuid",
                    "type": "string"
                },
                "my_field": {
                    "type": "string"
                }
            },
            "required": [
                "my_uid",
                "my_field"
            ],
            "title": "MyObjectSchema",
            "type": "object"
        },
....
        "MyObjectListSchema": {
            "properties": {
                "results": {
                    "items": {
                        "$ref": "#/definitions/MyObjectSchema"
                    },
                    "type": "array"
                }
            },
            "required": [
                "results"
            ],
            "title": "MyObjectListSchema",
            "type": "object"
        },

So, what this results in, when deserializing objects in a swagger-codegen generated client is the following ValueError gets raised

@my_field.setter
    def my_field(self, my_field):
        if my_field is None:
>           raise ValueError("Invalid value for `my_field`, must not be `None`")
E           ValueError: Invalid value for `my_field`, must not be `None`
@airstandley airstandley added the bug Something isn't working label Mar 6, 2020
@airstandley airstandley added the swagger-generation Concerns automatic swagger generation label Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working swagger-generation Concerns automatic swagger generation
Projects
None yet
Development

No branches or pull requests

2 participants