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

Validate extra keys in data #96

Open
pintofcat opened this issue Jul 21, 2020 · 3 comments
Open

Validate extra keys in data #96

pintofcat opened this issue Jul 21, 2020 · 3 comments

Comments

@pintofcat
Copy link

pintofcat commented Jul 21, 2020

Hey!
Is it possible to validate extra keys in data?
For example:

class TaskSerializer(Schema):
    id = fields.Int()
   name = fields.Str()
    )


class TaskView(BaseView):
    serializer = TaskSerializer()

    @request_schema(TaskSerializer)
    async def patch(self) -> Response:
        data = self.request["data"]
        task_id = int(self.request.match_info["id"])
        return web.json_response({}, status=200)

If i try to patch with body {"id": 1, "name": "task", "extra_key": 1} then error will not be raised, how to raise ValidationError on this case too? Thanks.

@pintofcat pintofcat changed the title Validate keys in data Validate extra keys in data Jul 21, 2020
@maximdanilchenko
Copy link
Owner

Hi! There are no ready to use feature for this. But you can extend your schema validation (read here https://marshmallow.readthedocs.io/en/latest/extending.html) with post/preprocessing and checking for invalid keys.

@kiforchuk
Copy link
Contributor

@maximdanilchenko This won't help.. The problem with the webargs itself: it parses arguments and then calls schema.load(...) for already parsed arguments (there are no extra fields after arguments parsing), so basically webargs library ignores "unknown" schema parameter
However, it was changed in 6.0.0b1 -- since that version webargs parsers preserve marshmallow schemas behavior for the additional fields.

Does anything block webargs update in aiohttp_apispec?

@pzhang65
Copy link
Contributor

should be closed with #112
@maximdanilchenko

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

4 participants